mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 02:08:57 +00:00
Ensure reactions are handled in order
This commit is contained in:
@@ -2470,7 +2470,7 @@ export async function startApp(): Promise<void> {
|
||||
timestamp,
|
||||
};
|
||||
|
||||
drop(Reactions.onReaction(attributes));
|
||||
await Reactions.onReaction(attributes);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2971,7 +2971,7 @@ export async function startApp(): Promise<void> {
|
||||
receivedAtDate: data.receivedAtDate,
|
||||
timestamp,
|
||||
};
|
||||
drop(Reactions.onReaction(attributes));
|
||||
await Reactions.onReaction(attributes);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -228,43 +228,40 @@ export async function onReaction(
|
||||
|
||||
const logId = `Reactions.onReaction(timestamp=${reaction.timestamp};target=${reaction.targetTimestamp})`;
|
||||
|
||||
try {
|
||||
const matchingMessage = await findMessageForReaction({
|
||||
targetTimestamp: reaction.targetTimestamp,
|
||||
targetAuthorAci: reaction.targetAuthorAci,
|
||||
reactionSenderConversationId: reaction.fromId,
|
||||
logId,
|
||||
});
|
||||
const matchingMessage = await findMessageForReaction({
|
||||
targetTimestamp: reaction.targetTimestamp,
|
||||
targetAuthorAci: reaction.targetAuthorAci,
|
||||
reactionSenderConversationId: reaction.fromId,
|
||||
logId,
|
||||
});
|
||||
|
||||
if (!matchingMessage) {
|
||||
log.info(
|
||||
`${logId}: No message for reaction`,
|
||||
'targeting',
|
||||
reaction.targetAuthorAci
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const matchingMessageConversation = window.ConversationController.get(
|
||||
matchingMessage.conversationId
|
||||
if (!matchingMessage) {
|
||||
log.info(
|
||||
`${logId}: No message for reaction`,
|
||||
'targeting',
|
||||
reaction.targetAuthorAci
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!matchingMessageConversation) {
|
||||
log.info(
|
||||
`${logId}: No target conversation for reaction`,
|
||||
reaction.targetAuthorAci,
|
||||
reaction.targetTimestamp
|
||||
);
|
||||
remove(reaction);
|
||||
return undefined;
|
||||
}
|
||||
const matchingMessageConversation = window.ConversationController.get(
|
||||
matchingMessage.conversationId
|
||||
);
|
||||
|
||||
// awaiting is safe since `onReaction` is never called from inside the queue
|
||||
await matchingMessageConversation.queueJob(
|
||||
'Reactions.onReaction',
|
||||
async () => {
|
||||
log.info(`${logId}: handling`);
|
||||
if (!matchingMessageConversation) {
|
||||
log.info(
|
||||
`${logId}: No target conversation for reaction`,
|
||||
reaction.targetAuthorAci,
|
||||
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
|
||||
// most recent data
|
||||
const targetMessage = await findMessageForReaction({
|
||||
@@ -302,12 +299,12 @@ export async function onReaction(
|
||||
}
|
||||
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user