Skip to content

Commit

Permalink
Ignore emoji when removing reactions
Browse files Browse the repository at this point in the history
Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>
  • Loading branch information
automated-signal and EvanHahn-Signal committed Oct 27, 2021
1 parent ac17aab commit 6a07bc0
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions ts/models/messages.ts
Expand Up @@ -3148,24 +3148,20 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
this.get('conversationId')
);

let reactionToRemove: Partial<ReactionType> | undefined;
const oldReaction = reactions.find(
re => re.fromId === reaction.get('fromId')
);
if (oldReaction) {
this.clearNotifications(oldReaction);
}

let oldReaction: ReactionAttributesType | undefined;
if (reaction.get('remove')) {
log.info('Removing reaction for message', messageId);
const newReactions = reactions.filter(
re =>
re.emoji !== reaction.get('emoji') ||
re.fromId !== reaction.get('fromId')
re => re.fromId !== reaction.get('fromId')
);
this.set({ reactions: newReactions });

reactionToRemove = {
emoji: reaction.get('emoji'),
targetAuthorUuid: reaction.get('targetAuthorUuid'),
targetTimestamp: reaction.get('targetTimestamp'),
};

await window.Signal.Data.removeReactionFromConversation({
emoji: reaction.get('emoji'),
fromId: reaction.get('fromId'),
Expand All @@ -3180,15 +3176,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
newReactions.push(reaction.toJSON());
this.set({ reactions: newReactions });

oldReaction = reactions.find(re => re.fromId === reaction.get('fromId'));
if (oldReaction) {
reactionToRemove = {
emoji: oldReaction.emoji,
targetAuthorUuid: oldReaction.targetAuthorUuid,
targetTimestamp: oldReaction.targetTimestamp,
};
}

await window.Signal.Data.addReaction({
conversationId: this.get('conversationId'),
emoji: reaction.get('emoji'),
Expand All @@ -3209,10 +3196,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
}
}

if (reactionToRemove) {
this.clearNotifications(reactionToRemove);
}

const newCount = (this.get('reactions') || []).length;
log.info(
`Done processing reaction for message ${messageId}. Went from ${count} to ${newCount} reactions.`
Expand Down

0 comments on commit 6a07bc0

Please sign in to comment.