Handle multiple out of order reactions

This commit is contained in:
Ken Powers 2020-03-20 15:07:44 -04:00 committed by Scott Nonnenberg
parent 37ad95af27
commit 42152be4af
2 changed files with 20 additions and 16 deletions

View file

@ -2401,11 +2401,11 @@
await conversation.notify(message);
}
// Does this message have a pending, previously-received associated reaction?
const reaction = Whisper.Reactions.forMessage(message);
if (reaction) {
// Does this message have any pending, previously-received associated reactions?
const reactions = Whisper.Reactions.forMessage(message);
reactions.forEach(reaction => {
message.handleReaction(reaction);
}
});
Whisper.events.trigger('incrementProgress');
confirm();

View file

@ -1,7 +1,8 @@
/* global
Backbone,
Whisper,
MessageController
MessageController,
ConversationController
*/
/* eslint-disable more/no-then */
@ -14,29 +15,32 @@
Whisper.Reactions = new (Backbone.Collection.extend({
forMessage(message) {
if (message.isOutgoing()) {
const outgoingReaction = this.findWhere({
const outgoingReactions = this.filter({
targetTimestamp: message.get('sent_at'),
});
if (outgoingReaction) {
if (outgoingReactions.length > 0) {
window.log.info('Found early reaction for outgoing message');
this.remove(outgoingReaction);
return outgoingReaction;
this.remove(outgoingReactions);
return outgoingReactions;
}
}
const reactionBySource = this.findWhere({
targetAuthorE164: message.get('source'),
targetTimestamp: message.get('sent_at'),
const reactionsBySource = this.filter(re => {
const mcid = message.get('conversationId');
const recid = ConversationController.getConversationId(
re.get('targetAuthorE164') || re.get('targetAuthorUuid')
);
return mcid === recid;
});
if (reactionBySource) {
if (reactionsBySource.length > 0) {
window.log.info('Found early reaction for message');
this.remove(reactionBySource);
return reactionBySource;
this.remove(reactionsBySource);
return reactionsBySource;
}
return null;
return [];
},
async onReaction(reaction) {
try {