Ensure reactions are handled in order

This commit is contained in:
trevor-signal
2025-10-31 12:25:42 -04:00
committed by GitHub
parent ab2b74e774
commit c6a79d2207
2 changed files with 36 additions and 39 deletions

View File

@@ -2470,7 +2470,7 @@ export async function startApp(): Promise<void> {
timestamp, timestamp,
}; };
drop(Reactions.onReaction(attributes)); await Reactions.onReaction(attributes);
return; return;
} }
@@ -2971,7 +2971,7 @@ export async function startApp(): Promise<void> {
receivedAtDate: data.receivedAtDate, receivedAtDate: data.receivedAtDate,
timestamp, timestamp,
}; };
drop(Reactions.onReaction(attributes)); await Reactions.onReaction(attributes);
return; return;
} }

View File

@@ -228,43 +228,40 @@ export async function onReaction(
const logId = `Reactions.onReaction(timestamp=${reaction.timestamp};target=${reaction.targetTimestamp})`; const logId = `Reactions.onReaction(timestamp=${reaction.timestamp};target=${reaction.targetTimestamp})`;
try { const matchingMessage = await findMessageForReaction({
const matchingMessage = await findMessageForReaction({ targetTimestamp: reaction.targetTimestamp,
targetTimestamp: reaction.targetTimestamp, targetAuthorAci: reaction.targetAuthorAci,
targetAuthorAci: reaction.targetAuthorAci, reactionSenderConversationId: reaction.fromId,
reactionSenderConversationId: reaction.fromId, logId,
logId, });
});
if (!matchingMessage) { if (!matchingMessage) {
log.info( log.info(
`${logId}: No message for reaction`, `${logId}: No message for reaction`,
'targeting', 'targeting',
reaction.targetAuthorAci reaction.targetAuthorAci
);
return;
}
const matchingMessageConversation = window.ConversationController.get(
matchingMessage.conversationId
); );
return;
}
if (!matchingMessageConversation) { const matchingMessageConversation = window.ConversationController.get(
log.info( matchingMessage.conversationId
`${logId}: No target conversation for reaction`, );
reaction.targetAuthorAci,
reaction.targetTimestamp
);
remove(reaction);
return undefined;
}
// awaiting is safe since `onReaction` is never called from inside the queue if (!matchingMessageConversation) {
await matchingMessageConversation.queueJob( log.info(
'Reactions.onReaction', `${logId}: No target conversation for reaction`,
async () => { reaction.targetAuthorAci,
log.info(`${logId}: handling`); reaction.targetTimestamp
);
remove(reaction);
return undefined;
}
drop(
matchingMessageConversation.queueJob('Reactions.onReaction', async () => {
log.info(`${logId}: handling`);
try {
// Message is fetched inside the conversation queue so we have the // Message is fetched inside the conversation queue so we have the
// most recent data // most recent data
const targetMessage = await findMessageForReaction({ const targetMessage = await findMessageForReaction({
@@ -302,12 +299,12 @@ export async function onReaction(
} }
remove(reaction); remove(reaction);
} catch (error) {
remove(reaction);
log.error(`${logId} error:`, Errors.toLogFormat(error));
} }
); })
} catch (error) { );
remove(reaction);
log.error(`${logId} error:`, Errors.toLogFormat(error));
}
} }
export async function handleReaction( export async function handleReaction(