Improve reliability of out-of-order reactions and DOE
This commit is contained in:
parent
f1182fa609
commit
4289c28a38
5 changed files with 170 additions and 115 deletions
|
@ -186,6 +186,40 @@
|
||||||
const uuid = textsecure.storage.user.getUuid();
|
const uuid = textsecure.storage.user.getUuid();
|
||||||
return this.getConversationId(e164 || uuid);
|
return this.getConversationId(e164 || uuid);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Given certain metadata about a message (an identifier of who wrote the
|
||||||
|
* message and the sent_at timestamp of the message) returns the
|
||||||
|
* conversation the message belongs to OR null if a conversation isn't
|
||||||
|
* found.
|
||||||
|
* @param {string} targetFrom The E164, UUID, or Conversation ID of the message author
|
||||||
|
* @param {number} targetTimestamp The sent_at timestamp of the target message
|
||||||
|
*/
|
||||||
|
async getConversationForTargetMessage(targetFrom, targetTimestamp) {
|
||||||
|
const targetFromId = this.getConversationId(targetFrom);
|
||||||
|
|
||||||
|
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||||
|
targetTimestamp,
|
||||||
|
{
|
||||||
|
MessageCollection: Whisper.MessageCollection,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const targetMessage = messages.find(m => {
|
||||||
|
const contact = m.getContact();
|
||||||
|
|
||||||
|
if (!contact) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mcid = contact.get('id');
|
||||||
|
return mcid === targetFromId;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (targetMessage) {
|
||||||
|
return targetMessage.getConversation();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
prepareForSend(id, options) {
|
prepareForSend(id, options) {
|
||||||
// id is any valid conversation identifier
|
// id is any valid conversation identifier
|
||||||
const conversation = this.get(id);
|
const conversation = this.get(id);
|
||||||
|
|
|
@ -31,13 +31,6 @@
|
||||||
},
|
},
|
||||||
async onDelete(del) {
|
async onDelete(del) {
|
||||||
try {
|
try {
|
||||||
const messages = await window.Signal.Data.getMessagesBySentAt(
|
|
||||||
del.get('targetSentTimestamp'),
|
|
||||||
{
|
|
||||||
MessageCollection: Whisper.MessageCollection,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// The contact the delete message came from
|
// The contact the delete message came from
|
||||||
const fromContact = ConversationController.get(del.get('fromId'));
|
const fromContact = ConversationController.get(del.get('fromId'));
|
||||||
|
|
||||||
|
@ -51,6 +44,15 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do not await, since this can deadlock the queue
|
||||||
|
fromContact.queueJob(async () => {
|
||||||
|
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||||
|
del.get('targetSentTimestamp'),
|
||||||
|
{
|
||||||
|
MessageCollection: Whisper.MessageCollection,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const targetMessage = messages.find(m => {
|
const targetMessage = messages.find(m => {
|
||||||
const messageContact = m.getContact();
|
const messageContact = m.getContact();
|
||||||
|
|
||||||
|
@ -97,6 +99,7 @@
|
||||||
await message.handleDeleteForEveryone(del);
|
await message.handleDeleteForEveryone(del);
|
||||||
|
|
||||||
this.remove(del);
|
this.remove(del);
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
window.log.error(
|
window.log.error(
|
||||||
'Deletes.onDelete error:',
|
'Deletes.onDelete error:',
|
||||||
|
|
|
@ -2520,6 +2520,18 @@
|
||||||
window.Signal.Data.updateConversation(conversation.attributes);
|
window.Signal.Data.updateConversation(conversation.attributes);
|
||||||
|
|
||||||
await message.queueAttachmentDownloads();
|
await message.queueAttachmentDownloads();
|
||||||
|
|
||||||
|
// Does this message have any pending, previously-received associated reactions?
|
||||||
|
const reactions = Whisper.Reactions.forMessage(message);
|
||||||
|
reactions.forEach(reaction => {
|
||||||
|
message.handleReaction(reaction, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Does this message have any pending, previously-received associated
|
||||||
|
// delete for everyone messages?
|
||||||
|
const deletes = Whisper.Deletes.forMessage(message);
|
||||||
|
deletes.forEach(del => Whisper.Deletes.onDelete(del, false));
|
||||||
|
|
||||||
await window.Signal.Data.saveMessage(message.attributes, {
|
await window.Signal.Data.saveMessage(message.attributes, {
|
||||||
Message: Whisper.Message,
|
Message: Whisper.Message,
|
||||||
forceSave: true,
|
forceSave: true,
|
||||||
|
@ -2531,17 +2543,6 @@
|
||||||
await conversation.notify(message);
|
await conversation.notify(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Does this message have any pending, previously-received associated reactions?
|
|
||||||
const reactions = Whisper.Reactions.forMessage(message);
|
|
||||||
reactions.forEach(reaction => {
|
|
||||||
message.handleReaction(reaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Does this message have any pending, previously-received associated
|
|
||||||
// delete for everyone messages?
|
|
||||||
const deletes = Whisper.Deletes.forMessage(message);
|
|
||||||
deletes.forEach(del => Whisper.Deletes.onDelete(del));
|
|
||||||
|
|
||||||
Whisper.events.trigger('incrementProgress');
|
Whisper.events.trigger('incrementProgress');
|
||||||
confirm();
|
confirm();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -2557,7 +2558,7 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async handleReaction(reaction) {
|
async handleReaction(reaction, shouldPersist = true) {
|
||||||
if (this.get('deletedForEveryone')) {
|
if (this.get('deletedForEveryone')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2597,9 +2598,11 @@
|
||||||
`Done processing reaction for message ${messageId}. Went from ${count} to ${newCount} reactions.`
|
`Done processing reaction for message ${messageId}. Went from ${count} to ${newCount} reactions.`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (shouldPersist) {
|
||||||
await window.Signal.Data.saveMessage(this.attributes, {
|
await window.Signal.Data.saveMessage(this.attributes, {
|
||||||
Message: Whisper.Message,
|
Message: Whisper.Message,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async handleDeleteForEveryone(del) {
|
async handleDeleteForEveryone(del) {
|
||||||
|
|
|
@ -46,13 +46,26 @@
|
||||||
},
|
},
|
||||||
async onReaction(reaction) {
|
async onReaction(reaction) {
|
||||||
try {
|
try {
|
||||||
|
const targetConversation = await ConversationController.getConversationForTargetMessage(
|
||||||
|
// Do not use ensureContactIds here since maliciously malformed
|
||||||
|
// reactions from clients could cause issues
|
||||||
|
reaction.get('targetAuthorE164') || reaction.get('targetAuthorUuid'),
|
||||||
|
reaction.get('targetTimestamp')
|
||||||
|
);
|
||||||
|
if (!targetConversation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// awaiting is safe since `onReaction` is never called from inside the queue
|
||||||
|
await targetConversation.queueJob(async () => {
|
||||||
const messages = await window.Signal.Data.getMessagesBySentAt(
|
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||||
reaction.get('targetTimestamp'),
|
reaction.get('targetTimestamp'),
|
||||||
{
|
{
|
||||||
MessageCollection: Whisper.MessageCollection,
|
MessageCollection: Whisper.MessageCollection,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
// Message is fetched inside the conversation queue so we have the
|
||||||
|
// most recent data
|
||||||
const targetMessage = messages.find(m => {
|
const targetMessage = messages.find(m => {
|
||||||
const contact = m.getContact();
|
const contact = m.getContact();
|
||||||
|
|
||||||
|
@ -62,7 +75,8 @@
|
||||||
|
|
||||||
const mcid = contact.get('id');
|
const mcid = contact.get('id');
|
||||||
const recid = ConversationController.getConversationId(
|
const recid = ConversationController.getConversationId(
|
||||||
reaction.get('targetAuthorE164') || reaction.get('targetAuthorUuid')
|
reaction.get('targetAuthorE164') ||
|
||||||
|
reaction.get('targetAuthorUuid')
|
||||||
);
|
);
|
||||||
return mcid === recid;
|
return mcid === recid;
|
||||||
});
|
});
|
||||||
|
@ -76,7 +90,7 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
// Since we haven't received the message for which we are removing a
|
// Since we haven't received the message for which we are removing a
|
||||||
// reaction, we can just remove those pending reaction
|
// reaction, we can just remove those pending reactions
|
||||||
if (reaction.get('remove')) {
|
if (reaction.get('remove')) {
|
||||||
this.remove(reaction);
|
this.remove(reaction);
|
||||||
const oldReaction = this.where({
|
const oldReaction = this.where({
|
||||||
|
@ -99,6 +113,7 @@
|
||||||
await message.handleReaction(reaction);
|
await message.handleReaction(reaction);
|
||||||
|
|
||||||
this.remove(reaction);
|
this.remove(reaction);
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
window.log.error(
|
window.log.error(
|
||||||
'Reactions.onReaction error:',
|
'Reactions.onReaction error:',
|
||||||
|
|
|
@ -164,17 +164,17 @@
|
||||||
"rule": "jQuery-load(",
|
"rule": "jQuery-load(",
|
||||||
"path": "js/conversation_controller.js",
|
"path": "js/conversation_controller.js",
|
||||||
"line": " async load() {",
|
"line": " async load() {",
|
||||||
"lineNumber": 218,
|
"lineNumber": 252,
|
||||||
"reasonCategory": "falseMatch",
|
"reasonCategory": "falseMatch",
|
||||||
"updated": "2020-03-24T20:06:31.391Z"
|
"updated": "2020-06-19T18:29:40.067Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"rule": "jQuery-load(",
|
"rule": "jQuery-load(",
|
||||||
"path": "js/conversation_controller.js",
|
"path": "js/conversation_controller.js",
|
||||||
"line": " this._initialPromise = load();",
|
"line": " this._initialPromise = load();",
|
||||||
"lineNumber": 260,
|
"lineNumber": 294,
|
||||||
"reasonCategory": "falseMatch",
|
"reasonCategory": "falseMatch",
|
||||||
"updated": "2020-03-24T20:06:31.391Z"
|
"updated": "2020-06-19T18:29:40.067Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"rule": "jQuery-$(",
|
"rule": "jQuery-$(",
|
||||||
|
|
Loading…
Reference in a new issue