From e8eea6324ea2da2060bd85963c6ca2b16f0ae0ed Mon Sep 17 00:00:00 2001 From: JC Brand Date: Mon, 14 Dec 2020 14:38:39 +0100 Subject: [PATCH] MUC: Send XEP-0333 markers with the MUC stanza id See: https://xmpp.org/extensions/xep-0333.html#rules-muc --- CHANGES.md | 1 + src/headless/plugins/muc/muc.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 0e94a739b..99ebeb05f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ - File structure reordering: All plugins are now in `./plugins` folders. - New configuration setting: [show_tab_notifications](https://conversejs.org/docs/html/configuration.html#show-tab-notifications) - New configuration setting: [muc_clear_messages_on_leave](https://conversejs.org/docs/html/configuration.html#muc-clear-messages-on-leave) +- Use the MUC stanza id when sending XEP-0333 markers ### Breaking Changes diff --git a/src/headless/plugins/muc/muc.js b/src/headless/plugins/muc/muc.js index 308719c6f..f24e3cdb9 100644 --- a/src/headless/plugins/muc/muc.js +++ b/src/headless/plugins/muc/muc.js @@ -178,6 +178,26 @@ const ChatRoomMixin = { } }, + /** + * Given the passed in MUC message, send a XEP-0333 chat marker. + * @param { _converse.MUCMessage } msg + * @param { ('received'|'displayed'|'acknowledged') } [type='displayed'] + * @param { Boolean } force - Whether a marker should be sent for the + * message, even if it didn't include a `markable` element. + */ + sendMarkerForMessage (msg, type='displayed', force=false) { + if (!msg) return; + if (msg?.get('is_markable') || force) { + const id = msg.get(`stanza_id ${this.get('jid')}`); + if (!id) { + log.error(`Can't send marker for message without stanza ID: ${msg}`); + return; + } + const from_jid = Strophe.getBareJidFromJid(msg.get('from')); + this.sendMarker(from_jid, id, type, msg.get('type')); + } + }, + /** * Handler that gets called when the 'hidden' flag is toggled. * @private