Reactions/DFE: Ensure post-save updates are persisted
This commit is contained in:
parent
d98345f20f
commit
84aed82357
1 changed files with 31 additions and 9 deletions
|
@ -4135,20 +4135,22 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||||
const message = this;
|
const message = this;
|
||||||
const type = message.get('type');
|
const type = message.get('type');
|
||||||
|
let changed = false;
|
||||||
|
|
||||||
if (type === 'outgoing') {
|
if (type === 'outgoing') {
|
||||||
const receipts = window.Whisper.DeliveryReceipts.forMessage(
|
const receipts = window.Whisper.DeliveryReceipts.forMessage(
|
||||||
conversation,
|
conversation,
|
||||||
message
|
message
|
||||||
);
|
);
|
||||||
receipts.forEach(receipt =>
|
receipts.forEach(receipt => {
|
||||||
message.set({
|
message.set({
|
||||||
delivered: (message.get('delivered') || 0) + 1,
|
delivered: (message.get('delivered') || 0) + 1,
|
||||||
delivered_to: _.union(message.get('delivered_to') || [], [
|
delivered_to: _.union(message.get('delivered_to') || [], [
|
||||||
receipt.get('deliveredTo'),
|
receipt.get('deliveredTo'),
|
||||||
]),
|
]),
|
||||||
})
|
});
|
||||||
);
|
changed = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'incoming') {
|
if (type === 'incoming') {
|
||||||
|
@ -4172,6 +4174,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
if (c) {
|
if (c) {
|
||||||
c.onReadMessage(message);
|
c.onReadMessage(message);
|
||||||
}
|
}
|
||||||
|
changed = true;
|
||||||
} else if (isFirstRun) {
|
} else if (isFirstRun) {
|
||||||
conversation.set({
|
conversation.set({
|
||||||
unreadCount: (conversation.get('unreadCount') || 0) + 1,
|
unreadCount: (conversation.get('unreadCount') || 0) + 1,
|
||||||
|
@ -4190,17 +4193,22 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
message.set({
|
message.set({
|
||||||
read_by: _.union(message.get('read_by'), readBy),
|
read_by: _.union(message.get('read_by'), readBy),
|
||||||
});
|
});
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A sync'd message to ourself is automatically considered read/delivered
|
// A sync'd message to ourself is automatically considered read/delivered
|
||||||
if (conversation.isMe()) {
|
if (isFirstRun && conversation.isMe()) {
|
||||||
message.set({
|
message.set({
|
||||||
read_by: conversation.getRecipients(),
|
read_by: conversation.getRecipients(),
|
||||||
delivered_to: conversation.getRecipients(),
|
delivered_to: conversation.getRecipients(),
|
||||||
});
|
});
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
message.set({ recipients: conversation.getRecipients() });
|
if (isFirstRun) {
|
||||||
|
message.set({ recipients: conversation.getRecipients() });
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for out-of-order view syncs
|
// Check for out-of-order view syncs
|
||||||
|
@ -4208,23 +4216,37 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
const viewSync = window.Whisper.ViewSyncs.forMessage(message);
|
const viewSync = window.Whisper.ViewSyncs.forMessage(message);
|
||||||
if (viewSync) {
|
if (viewSync) {
|
||||||
await message.markViewed({ fromSync: true });
|
await message.markViewed({ fromSync: true });
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Does this message have any pending, previously-received associated reactions?
|
// Does this message have any pending, previously-received associated reactions?
|
||||||
const reactions = window.Whisper.Reactions.forMessage(message);
|
const reactions = window.Whisper.Reactions.forMessage(message);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
reactions.map(reaction => message.handleReaction(reaction, false))
|
reactions.map(async reaction => {
|
||||||
|
await message.handleReaction(reaction, false);
|
||||||
|
changed = true;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Does this message have any pending, previously-received associated
|
// Does this message have any pending, previously-received associated
|
||||||
// delete for everyone messages?
|
// delete for everyone messages?
|
||||||
const deletes = window.Whisper.Deletes.forMessage(message);
|
const deletes = window.Whisper.Deletes.forMessage(message);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
deletes.map(del =>
|
deletes.map(async del => {
|
||||||
window.Signal.Util.deleteForEveryone(message, del, false)
|
await window.Signal.Util.deleteForEveryone(message, del, false);
|
||||||
)
|
changed = true;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (changed && !isFirstRun) {
|
||||||
|
window.log.info(
|
||||||
|
`modifyTargetMessage/${this.idForLogging()}: Changes in second run; saving.`
|
||||||
|
);
|
||||||
|
await window.Signal.Data.saveMessage(this.attributes, {
|
||||||
|
Message: window.Whisper.Message,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleReaction(
|
async handleReaction(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue