Skip to content

Commit c6a79d2

Browse files
Ensure reactions are handled in order
1 parent ab2b74e commit c6a79d2

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

ts/background.preload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,7 @@ export async function startApp(): Promise<void> {
24702470
timestamp,
24712471
};
24722472

2473-
drop(Reactions.onReaction(attributes));
2473+
await Reactions.onReaction(attributes);
24742474
return;
24752475
}
24762476

@@ -2971,7 +2971,7 @@ export async function startApp(): Promise<void> {
29712971
receivedAtDate: data.receivedAtDate,
29722972
timestamp,
29732973
};
2974-
drop(Reactions.onReaction(attributes));
2974+
await Reactions.onReaction(attributes);
29752975
return;
29762976
}
29772977

ts/messageModifiers/Reactions.preload.ts

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -228,43 +228,40 @@ export async function onReaction(
228228

229229
const logId = `Reactions.onReaction(timestamp=${reaction.timestamp};target=${reaction.targetTimestamp})`;
230230

231-
try {
232-
const matchingMessage = await findMessageForReaction({
233-
targetTimestamp: reaction.targetTimestamp,
234-
targetAuthorAci: reaction.targetAuthorAci,
235-
reactionSenderConversationId: reaction.fromId,
236-
logId,
237-
});
238-
239-
if (!matchingMessage) {
240-
log.info(
241-
`${logId}: No message for reaction`,
242-
'targeting',
243-
reaction.targetAuthorAci
244-
);
245-
return;
246-
}
231+
const matchingMessage = await findMessageForReaction({
232+
targetTimestamp: reaction.targetTimestamp,
233+
targetAuthorAci: reaction.targetAuthorAci,
234+
reactionSenderConversationId: reaction.fromId,
235+
logId,
236+
});
247237

248-
const matchingMessageConversation = window.ConversationController.get(
249-
matchingMessage.conversationId
238+
if (!matchingMessage) {
239+
log.info(
240+
`${logId}: No message for reaction`,
241+
'targeting',
242+
reaction.targetAuthorAci
250243
);
244+
return;
245+
}
251246

252-
if (!matchingMessageConversation) {
253-
log.info(
254-
`${logId}: No target conversation for reaction`,
255-
reaction.targetAuthorAci,
256-
reaction.targetTimestamp
257-
);
258-
remove(reaction);
259-
return undefined;
260-
}
247+
const matchingMessageConversation = window.ConversationController.get(
248+
matchingMessage.conversationId
249+
);
261250

262-
// awaiting is safe since `onReaction` is never called from inside the queue
263-
await matchingMessageConversation.queueJob(
264-
'Reactions.onReaction',
265-
async () => {
266-
log.info(`${logId}: handling`);
251+
if (!matchingMessageConversation) {
252+
log.info(
253+
`${logId}: No target conversation for reaction`,
254+
reaction.targetAuthorAci,
255+
reaction.targetTimestamp
256+
);
257+
remove(reaction);
258+
return undefined;
259+
}
267260

261+
drop(
262+
matchingMessageConversation.queueJob('Reactions.onReaction', async () => {
263+
log.info(`${logId}: handling`);
264+
try {
268265
// Message is fetched inside the conversation queue so we have the
269266
// most recent data
270267
const targetMessage = await findMessageForReaction({
@@ -302,12 +299,12 @@ export async function onReaction(
302299
}
303300

304301
remove(reaction);
302+
} catch (error) {
303+
remove(reaction);
304+
log.error(`${logId} error:`, Errors.toLogFormat(error));
305305
}
306-
);
307-
} catch (error) {
308-
remove(reaction);
309-
log.error(`${logId} error:`, Errors.toLogFormat(error));
310-
}
306+
})
307+
);
311308
}
312309

313310
export async function handleReaction(

0 commit comments

Comments
 (0)