handleReaction: don't fetch/save across an await boundary
Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
parent
e4b8bef962
commit
4430485c18
|
@ -3145,9 +3145,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldReactions = this.get('reactions') || [];
|
const previousLength = (this.get('reactions') || []).length;
|
||||||
|
|
||||||
let newReactions: typeof oldReactions;
|
|
||||||
if (reaction.get('source') === ReactionSource.FromThisDevice) {
|
if (reaction.get('source') === ReactionSource.FromThisDevice) {
|
||||||
log.info(
|
log.info(
|
||||||
`handleReaction: sending reaction to ${this.idForLogging()} from this device`
|
`handleReaction: sending reaction to ${this.idForLogging()} from this device`
|
||||||
|
@ -3165,11 +3163,14 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
newReactions = reactionUtil.addOutgoingReaction(
|
const reactions = reactionUtil.addOutgoingReaction(
|
||||||
oldReactions,
|
this.get('reactions') || [],
|
||||||
newReaction
|
newReaction
|
||||||
);
|
);
|
||||||
|
this.set({ reactions });
|
||||||
} else {
|
} else {
|
||||||
|
const oldReactions = this.get('reactions') || [];
|
||||||
|
let reactions: Array<MessageReactionType>;
|
||||||
const oldReaction = oldReactions.find(
|
const oldReaction = oldReactions.find(
|
||||||
re => re.fromId === reaction.get('fromId')
|
re => re.fromId === reaction.get('fromId')
|
||||||
);
|
);
|
||||||
|
@ -3184,16 +3185,17 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (reaction.get('source') === ReactionSource.FromSync) {
|
if (reaction.get('source') === ReactionSource.FromSync) {
|
||||||
newReactions = oldReactions.filter(
|
reactions = oldReactions.filter(
|
||||||
re =>
|
re =>
|
||||||
re.fromId !== reaction.get('fromId') ||
|
re.fromId !== reaction.get('fromId') ||
|
||||||
re.timestamp > reaction.get('timestamp')
|
re.timestamp > reaction.get('timestamp')
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
newReactions = oldReactions.filter(
|
reactions = oldReactions.filter(
|
||||||
re => re.fromId !== reaction.get('fromId')
|
re => re.fromId !== reaction.get('fromId')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
this.set({ reactions });
|
||||||
|
|
||||||
await window.Signal.Data.removeReactionFromConversation({
|
await window.Signal.Data.removeReactionFromConversation({
|
||||||
emoji: reaction.get('emoji'),
|
emoji: reaction.get('emoji'),
|
||||||
|
@ -3218,10 +3220,11 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
reactionToAdd = reaction.toJSON();
|
reactionToAdd = reaction.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
newReactions = oldReactions.filter(
|
reactions = oldReactions.filter(
|
||||||
re => re.fromId !== reaction.get('fromId')
|
re => re.fromId !== reaction.get('fromId')
|
||||||
);
|
);
|
||||||
newReactions.push(reactionToAdd);
|
reactions.push(reactionToAdd);
|
||||||
|
this.set({ reactions });
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isOutgoing(this.attributes) &&
|
isOutgoing(this.attributes) &&
|
||||||
|
@ -3242,12 +3245,11 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set({ reactions: newReactions });
|
const currentLength = (this.get('reactions') || []).length;
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
'handleReaction:',
|
'handleReaction:',
|
||||||
`Done processing reaction for message ${this.idForLogging()}.`,
|
`Done processing reaction for message ${this.idForLogging()}.`,
|
||||||
`Went from ${oldReactions.length} to ${newReactions.length} reactions.`
|
`Went from ${previousLength} to ${currentLength} reactions.`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (reaction.get('source') === ReactionSource.FromThisDevice) {
|
if (reaction.get('source') === ReactionSource.FromThisDevice) {
|
||||||
|
|
Loading…
Reference in New Issue