Fix out of order edit message read syncs
This commit is contained in:
@@ -326,8 +326,9 @@ export async function handleEditMessage(
|
||||
drop(mainMessageConversation.updateLastMessage());
|
||||
// Apply any other operations, excluding edits that target this message
|
||||
await modifyTargetMessage(mainMessageModel, mainMessageConversation, {
|
||||
isFirstRun: true,
|
||||
isFirstRun: false,
|
||||
skipEdits: true,
|
||||
skipSave: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -34,9 +34,13 @@ import { strictAssert } from './assert';
|
||||
export async function modifyTargetMessage(
|
||||
message: MessageModel,
|
||||
conversation: ConversationModel,
|
||||
options?: { isFirstRun: boolean; skipEdits: boolean }
|
||||
options?: { isFirstRun: boolean; skipEdits: boolean; skipSave: boolean }
|
||||
): Promise<void> {
|
||||
const { isFirstRun = false, skipEdits = false } = options ?? {};
|
||||
const {
|
||||
isFirstRun = false,
|
||||
skipEdits = false,
|
||||
skipSave = false,
|
||||
} = options ?? {};
|
||||
|
||||
const logId = `modifyTargetMessage/${message.idForLogging()}`;
|
||||
const type = message.get('type');
|
||||
@@ -111,13 +115,10 @@ export async function modifyTargetMessage(
|
||||
|
||||
const viewSyncs = ViewSyncs.forMessage(message);
|
||||
|
||||
log.info(`${logId}: ReadSync-1`, { length: readSyncs.length });
|
||||
|
||||
const isGroupStoryReply =
|
||||
isGroup(conversation.attributes) && message.get('storyId');
|
||||
|
||||
if (readSyncs.length !== 0 || viewSyncs.length !== 0) {
|
||||
log.info(`${logId}: ReadSync-2`);
|
||||
const markReadAt = Math.min(
|
||||
Date.now(),
|
||||
...readSyncs.map(sync => sync.readAt),
|
||||
@@ -152,7 +153,6 @@ export async function modifyTargetMessage(
|
||||
});
|
||||
changed = true;
|
||||
|
||||
log.info(`${logId}: ReadSync-3`);
|
||||
message.setPendingMarkRead(
|
||||
Math.min(message.getPendingMarkRead() ?? Date.now(), markReadAt)
|
||||
);
|
||||
@@ -161,12 +161,10 @@ export async function modifyTargetMessage(
|
||||
!isGroupStoryReply &&
|
||||
canConversationBeUnarchived(conversation.attributes)
|
||||
) {
|
||||
log.info(`${logId}: ReadSync-4`);
|
||||
conversation.setArchived(false);
|
||||
}
|
||||
|
||||
if (!isFirstRun && message.getPendingMarkRead()) {
|
||||
log.info(`${logId}: ReadSync-5`);
|
||||
const markReadAt = message.getPendingMarkRead();
|
||||
message.setPendingMarkRead(undefined);
|
||||
|
||||
@@ -263,7 +261,7 @@ export async function modifyTargetMessage(
|
||||
);
|
||||
}
|
||||
|
||||
if (changed && !isFirstRun) {
|
||||
if (!skipSave && changed && !isFirstRun) {
|
||||
log.info(`${logId}: Changes in second run; saving.`);
|
||||
await window.Signal.Data.saveMessage(message.attributes, {
|
||||
ourAci,
|
||||
|
Reference in New Issue
Block a user