Call save only once when updating a cached message

This commit is contained in:
JC Brand 2019-03-07 17:29:20 +01:00
parent b51d98d6d1
commit ebd1797991
4 changed files with 43 additions and 24 deletions

38
dist/converse.js vendored
View File

@ -61911,7 +61911,20 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return this.vcard.get('fullname') || this.get('jid'); return this.vcard.get('fullname') || this.get('jid');
}, },
updateMessage(message, stanza) {// Overridden in converse-muc and converse-mam getUpdatedMessageAttributes(message, stanza) {
// Overridden in converse-muc and converse-mam
return {};
},
updateMessage(message, stanza) {
// Overridden in converse-muc and converse-mam
const attrs = this.getUpdatedMessageAttributes(message, stanza);
if (attrs) {
message.save(attrs, {
'patch': true
});
}
}, },
handleMessageCorrection(stanza) { handleMessageCorrection(stanza) {
@ -65754,14 +65767,16 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-mam
return message; return message;
}, },
updateMessage(message, stanza) { getUpdatedMessageAttributes(message, stanza) {
this.__super__.updateMessage.apply(this, arguments); const attrs = this.__super__.getUpdatedMessageAttributes.apply(this, arguments);
if (message && !message.get('is_archived')) { if (message && !message.get('is_archived')) {
message.save(_.extend({ return _.extend(attrs, {
'is_archived': this.isArchived(stanza) 'is_archived': this.isArchived(stanza)
}, this.getStanzaIDs(stanza))); }, this.getStanzaIDs(stanza));
} }
return attrs;
} }
}, },
@ -67388,17 +67403,14 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc
return is_csn && (attrs.is_delayed || own_message); return is_csn && (attrs.is_delayed || own_message);
}, },
updateMessage(message, stanza) { getUpdatedMessageAttributes(message, stanza) {
/* Make sure that the already cached message is updated with // Overridden in converse-muc and converse-mam
* the stanza ID. const attrs = _converse.ChatBox.prototype.getUpdatedMessageAttributes.call(this, message, stanza);
*/
_converse.ChatBox.prototype.updateMessage.call(this, message, stanza);
const from = stanza.getAttribute('from'); const from = stanza.getAttribute('from');
const own_message = Strophe.getResourceFromJid(from) == this.get('nick'); const own_message = Strophe.getResourceFromJid(from) == this.get('nick');
if (own_message) { if (own_message) {
const attrs = {};
const stanza_id = sizzle(`stanza-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop(); const stanza_id = sizzle(`stanza-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop();
const by_jid = stanza_id ? stanza_id.getAttribute('by') : undefined; const by_jid = stanza_id ? stanza_id.getAttribute('by') : undefined;
@ -67410,9 +67422,9 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc
if (!message.get('received')) { if (!message.get('received')) {
attrs.received = moment().format(); attrs.received = moment().format();
} }
message.save(attrs);
} }
return attrs;
}, },
async onMessage(stanza) { async onMessage(stanza) {

View File

@ -290,8 +290,17 @@ converse.plugins.add('converse-chatboxes', {
return this.vcard.get('fullname') || this.get('jid'); return this.vcard.get('fullname') || this.get('jid');
}, },
getUpdatedMessageAttributes (message, stanza) {
// Overridden in converse-muc and converse-mam
return {};
},
updateMessage (message, stanza) { updateMessage (message, stanza) {
// Overridden in converse-muc and converse-mam // Overridden in converse-muc and converse-mam
const attrs = this.getUpdatedMessageAttributes(message, stanza);
if (attrs) {
message.save(attrs, {'patch': true});
}
}, },
handleMessageCorrection (stanza) { handleMessageCorrection (stanza) {

View File

@ -142,13 +142,14 @@ converse.plugins.add('converse-mam', {
}, },
updateMessage (message, stanza) { getUpdatedMessageAttributes (message, stanza) {
this.__super__.updateMessage.apply(this, arguments); const attrs = this.__super__.getUpdatedMessageAttributes.apply(this, arguments);
if (message && !message.get('is_archived')) { if (message && !message.get('is_archived')) {
message.save(_.extend({ return _.extend(attrs, {
'is_archived': this.isArchived(stanza) 'is_archived': this.isArchived(stanza)
}, this.getStanzaIDs(stanza))); }, this.getStanzaIDs(stanza))
} }
return attrs;
} }
}, },

View File

@ -1000,15 +1000,12 @@ converse.plugins.add('converse-muc', {
return is_csn && (attrs.is_delayed || own_message); return is_csn && (attrs.is_delayed || own_message);
}, },
updateMessage (message, stanza) { getUpdatedMessageAttributes (message, stanza) {
/* Make sure that the already cached message is updated with // Overridden in converse-muc and converse-mam
* the stanza ID. const attrs = _converse.ChatBox.prototype.getUpdatedMessageAttributes.call(this, message, stanza);
*/
_converse.ChatBox.prototype.updateMessage.call(this, message, stanza);
const from = stanza.getAttribute('from'); const from = stanza.getAttribute('from');
const own_message = Strophe.getResourceFromJid(from) == this.get('nick'); const own_message = Strophe.getResourceFromJid(from) == this.get('nick');
if (own_message) { if (own_message) {
const attrs = {};
const stanza_id = sizzle(`stanza-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop(); const stanza_id = sizzle(`stanza-id[xmlns="${Strophe.NS.SID}"]`, stanza).pop();
const by_jid = stanza_id ? stanza_id.getAttribute('by') : undefined; const by_jid = stanza_id ? stanza_id.getAttribute('by') : undefined;
if (by_jid) { if (by_jid) {
@ -1018,8 +1015,8 @@ converse.plugins.add('converse-muc', {
if (!message.get('received')) { if (!message.get('received')) {
attrs.received = moment().format(); attrs.received = moment().format();
} }
message.save(attrs);
} }
return attrs;
}, },
async onMessage (stanza) { async onMessage (stanza) {