Сохранить текущий снимок DM-синхронизации

This commit is contained in:
AidarKC
2026-08-24 17:50:36 +04:00
parent 015fade4c0
commit d8e0c77951
48 changed files with 2498 additions and 383 deletions
+37 -1
View File
@@ -414,6 +414,7 @@ function persistMessageRecord(chatId, row) {
readAtMs: Number(row.readAtMs || 0),
readReceiptSent: Boolean(row.readReceiptSent),
refBaseKey: String(row.refBaseKey || ''),
deliveryState: String(row.deliveryState || ''),
ts: resolvedTs > 0 ? resolvedTs : Date.now(),
}).catch(() => {});
}
@@ -450,6 +451,7 @@ export async function hydrateMessagesFromStore() {
readAtMs: Number(row.readAtMs || 0),
readReceiptSent: Boolean(row.readReceiptSent),
refBaseKey: String(row.refBaseKey || ''),
deliveryState: String(row.deliveryState || ''),
createdAtMs: Number(row.ts || 0),
});
});
@@ -531,7 +533,11 @@ export function addOutgoingPendingMessage(chatId, text) {
return tempId;
}
export function markOutgoingSent(tempId, { messageKey = '', baseKey = '' } = {}) {
export function markOutgoingSent(tempId, {
messageKey = '',
baseKey = '',
deliveryState = 'accepted',
} = {}) {
if (!tempId) return;
const keys = Object.keys(state.chats || {});
keys.forEach((chatId) => {
@@ -541,6 +547,7 @@ export function markOutgoingSent(tempId, { messageKey = '', baseKey = '' } = {})
row.firstTick = true;
row.messageKey = messageKey || row.messageKey || '';
row.baseKey = baseKey || row.baseKey || '';
row.deliveryState = String(deliveryState || row.deliveryState || 'accepted');
if (messageKey) {
state.knownMessageKeys[messageKey] = true;
persistMessageRecord(chatId, row);
@@ -549,6 +556,33 @@ export function markOutgoingSent(tempId, { messageKey = '', baseKey = '' } = {})
});
}
export function markOutgoingDeliveryState({
outgoingKey = '',
baseKey = '',
deliveryState = '',
} = {}) {
const normalizedOutgoingKey = String(outgoingKey || '').trim();
const normalizedBaseKey = String(baseKey || '').trim();
let changed = false;
Object.keys(state.chats || {}).forEach((chatId) => {
getChatMessages(chatId).forEach((row) => {
if (row?.from !== 'out') return;
const matches = (
(normalizedOutgoingKey && String(row.messageKey || '') === normalizedOutgoingKey)
|| (normalizedBaseKey && String(row.baseKey || '') === normalizedBaseKey)
);
if (!matches) return;
row.deliveryState = String(deliveryState || row.deliveryState || 'accepted');
if (row.deliveryState === 'delivered') {
row.firstTick = true;
}
persistMessageRecord(chatId, row);
changed = true;
});
});
return changed;
}
export function markOutgoingReadByBaseKey(baseKey, readAtMs = 0) {
if (!baseKey) return;
const normalizedReadAtMs = Number(readAtMs || 0);
@@ -629,6 +663,7 @@ export function addSignedMessageToChat({
rawBlobB64 = '',
refBaseKey = '',
revisionTimeMs = 0,
deliveryState = '',
deleted = false,
} = {}) {
const normalizedChatId = normalizeDmChatId(chatId);
@@ -663,6 +698,7 @@ export function addSignedMessageToChat({
row.messageType = Number(messageType || 0);
row.rawBlobB64 = String(rawBlobB64 || '');
row.revisionTimeMs = nextRevision;
row.deliveryState = String(deliveryState || existing?.deliveryState || (row.from === 'out' ? 'accepted' : ''));
row.unread = row.from === 'in' ? Boolean(unread) : false;
row.refBaseKey = String(refBaseKey || '');
row.firstTick = row.from === 'out';