Message deduplication bugfixes and improvements.

- Add a new method to check for dupes based on the message text.
- When checking for dupes based on origin_id, no need to restrict to
  only our own.
This commit is contained in:
JC Brand 2019-04-27 14:58:50 +02:00
parent 7feab35a1d
commit b9e5658112
6 changed files with 66 additions and 12 deletions

View File

@ -8,6 +8,7 @@
- Hide the textarea when a user is muted in a groupchat.
- Don't restore a BOSH session without knowing the JID
- In the `/help` menu, only show allowed commands
- Message deduplication bugfixes and improvements
- #1296: `embedded` view mode shows `chatbox-navback` arrow in header
- #1532: Converse reloads on enter pressed in the filter box

26
dist/converse.js vendored
View File

@ -62423,8 +62423,8 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return false;
},
getDuplicateMessage(stanza) {
return this.findDuplicateFromOriginID(stanza) || this.findDuplicateFromStanzaID(stanza);
async getDuplicateMessage(stanza) {
return this.findDuplicateFromOriginID(stanza) || (await this.findDuplicateFromStanzaID(stanza)) || this.findDuplicateFromMessage(stanza);
},
findDuplicateFromOriginID(stanza) {
@ -62436,7 +62436,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return this.messages.findWhere({
'origin_id': origin_id.getAttribute('id'),
'sender': 'me'
'from': stanza.getAttribute('from')
});
},
@ -62459,6 +62459,26 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return this.messages.findWhere(query);
},
findDuplicateFromMessage(stanza) {
const text = this.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
});
},
sendMarker(to_jid, id, type) {
const stanza = $msg({
'from': _converse.connection.jid,

View File

@ -2249,7 +2249,6 @@
<stanza-id xmlns="urn:xmpp:sid:0"
id="5f3dbc5e-e1d3-4077-a492-693f3769c7ad"
by="room@muc.example.com"/>
<origin-id xmlns="urn:xmpp:sid:0" id="de305d54-75b4-431b-adb2-eb6b9e546013"/>
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.api.chats.get().length);
@ -2267,7 +2266,6 @@
<stanza-id xmlns="urn:xmpp:sid:0"
id="5f3dbc5e-e1d3-4077-a492-693f3769c7ad"
by="room@muc.example.com"/>
<origin-id xmlns="urn:xmpp:sid:0" id="de305d54-75b4-431b-adb2-eb6b9e546013"/>
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => view.model.findDuplicateFromStanzaID.calls.count() === 2);

View File

@ -360,8 +360,10 @@ converse.plugins.add('converse-chatboxes', {
return false;
},
getDuplicateMessage (stanza) {
return this.findDuplicateFromOriginID(stanza) || this.findDuplicateFromStanzaID(stanza);
async getDuplicateMessage (stanza) {
return this.findDuplicateFromOriginID(stanza) ||
await this.findDuplicateFromStanzaID(stanza) ||
this.findDuplicateFromMessage(stanza);
},
findDuplicateFromOriginID (stanza) {
@ -371,11 +373,11 @@ converse.plugins.add('converse-chatboxes', {
}
return this.messages.findWhere({
'origin_id': origin_id.getAttribute('id'),
'sender': 'me'
'from': stanza.getAttribute('from')
});
},
async findDuplicateFromStanzaID(stanza) {
async findDuplicateFromStanzaID (stanza) {
const stanza_id = sizzle(`stanza-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop();
if (!stanza_id) {
return false;
@ -390,6 +392,17 @@ converse.plugins.add('converse-chatboxes', {
return this.messages.findWhere(query);
},
findDuplicateFromMessage (stanza) {
const text = this.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
});
},
sendMarker(to_jid, id, type) {
const stanza = $msg({

View File

@ -323,6 +323,7 @@ converse.plugins.add('converse-muc', {
'to': this.getRoomJIDAndNick(nick)
}).c("x", {'xmlns': Strophe.NS.MUC})
.c("history", {'maxstanzas': this.features.get('mam_enabled') ? 0 : _converse.muc_history_max_stanzas}).up();
if (password) {
stanza.cnode(Strophe.xmlElement("password", [], password));
}
@ -1082,6 +1083,7 @@ converse.plugins.add('converse-muc', {
return _converse.api.trigger('message', {'stanza': original_stanza});
}
const attrs = await this.getMessageAttributesFromStanza(stanza, original_stanza);
if (attrs.nick &&
!this.subjectChangeHandled(attrs) &&
!this.ignorableCSN(attrs) &&

View File

@ -40647,8 +40647,8 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return false;
},
getDuplicateMessage(stanza) {
return this.findDuplicateFromOriginID(stanza) || this.findDuplicateFromStanzaID(stanza);
async getDuplicateMessage(stanza) {
return this.findDuplicateFromOriginID(stanza) || (await this.findDuplicateFromStanzaID(stanza)) || this.findDuplicateFromMessage(stanza);
},
findDuplicateFromOriginID(stanza) {
@ -40660,7 +40660,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return this.messages.findWhere({
'origin_id': origin_id.getAttribute('id'),
'sender': 'me'
'from': stanza.getAttribute('from')
});
},
@ -40683,6 +40683,26 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return this.messages.findWhere(query);
},
findDuplicateFromMessage(stanza) {
const text = this.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
});
},
sendMarker(to_jid, id, type) {
const stanza = $msg({
'from': _converse.connection.jid,