|
@@ -370,14 +370,14 @@ converse.plugins.add('converse-chat', {
|
|
|
},
|
|
|
|
|
|
async onMessage (stanza, original_stanza, from_jid) {
|
|
|
- const message = await this.getDuplicateMessage(stanza);
|
|
|
+ const attrs = await this.getMessageAttributesFromStanza(stanza, original_stanza);
|
|
|
+ const message = await this.getDuplicateMessage(attrs);
|
|
|
if (message) {
|
|
|
this.updateMessage(message, original_stanza);
|
|
|
} else if (
|
|
|
!this.handleReceipt (stanza, from_jid) &&
|
|
|
!this.handleChatMarker(stanza, from_jid)
|
|
|
) {
|
|
|
- const attrs = await this.getMessageAttributesFromStanza(stanza, original_stanza);
|
|
|
if (this.handleRetraction(attrs)) {
|
|
|
return;
|
|
|
}
|
|
@@ -661,46 +661,28 @@ converse.plugins.add('converse-chat', {
|
|
|
return message;
|
|
|
},
|
|
|
|
|
|
- async getDuplicateMessage (stanza) {
|
|
|
- return this.findDuplicateFromOriginID(stanza) ||
|
|
|
- await this.findDuplicateFromStanzaID(stanza) ||
|
|
|
- this.findDuplicateFromMessage(stanza);
|
|
|
+ getDuplicateMessage (attrs) {
|
|
|
+ return this.findDuplicateFromOriginID(attrs) || this.findDuplicateFromMessage(attrs);
|
|
|
},
|
|
|
|
|
|
- findDuplicateFromOriginID (stanza) {
|
|
|
- const origin_id = sizzle(`origin-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop();
|
|
|
- if (!origin_id) {
|
|
|
+ findDuplicateFromOriginID (attrs) {
|
|
|
+ if (!attrs.origin_id) {
|
|
|
return null;
|
|
|
}
|
|
|
return this.messages.findWhere({
|
|
|
- 'origin_id': origin_id.getAttribute('id'),
|
|
|
- 'from': stanza.getAttribute('from')
|
|
|
+ 'origin_id': attrs.origin_id,
|
|
|
+ 'from': attrs.from
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- async findDuplicateFromStanzaID (stanza) {
|
|
|
- const stanza_id = sizzle(`stanza-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop();
|
|
|
- if (!stanza_id) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- const by_jid = stanza_id.getAttribute('by');
|
|
|
- if (!(await _converse.api.disco.supports(Strophe.NS.SID, by_jid))) {
|
|
|
- return false;
|
|
|
+ findDuplicateFromMessage (attrs) {
|
|
|
+ if (!attrs.message || !attrs.msgid) {
|
|
|
+ return null;
|
|
|
}
|
|
|
- const query = {};
|
|
|
- query[`stanza_id ${by_jid}`] = stanza_id.getAttribute('id');
|
|
|
- return this.messages.findWhere(query);
|
|
|
- },
|
|
|
-
|
|
|
- findDuplicateFromMessage (stanza) {
|
|
|
- const text = stanza_utils.getMessageBody(stanza) || undefined;
|
|
|
- if (!text) { return false; }
|
|
|
- const id = stanza.getAttribute('id');
|
|
|
- if (!id) { return false; }
|
|
|
return this.messages.findWhere({
|
|
|
- 'message': text,
|
|
|
- 'from': stanza.getAttribute('from'),
|
|
|
- 'msgid': id
|
|
|
+ 'message': attrs.message,
|
|
|
+ 'from': attrs.from,
|
|
|
+ 'msgid': attrs.msgid
|
|
|
});
|
|
|
},
|
|
|
|