瀏覽代碼

Don't send message markers to users not subscribed to our presence

JC Brand 7 月之前
父節點
當前提交
2872180146
共有 2 個文件被更改,包括 18 次插入8 次删除
  1. 11 2
      src/headless/shared/model-with-messages.js
  2. 7 6
      src/plugins/chatview/tests/markers.js

+ 11 - 2
src/headless/shared/model-with-messages.js

@@ -704,10 +704,19 @@ export default function ModelWithMessages(BaseModel) {
          * @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 || !api.settings.get('send_chat_markers').includes(type)) {
+        async sendMarkerForMessage(msg, type = 'displayed', force = false) {
+            if (!msg || msg?.get('type') === 'groupchat' || !api.settings.get('send_chat_markers').includes(type)) {
                 return;
             }
+
+            // Don't send chat markers to contacts that are not subscribed
+            // to our presence.
+            const contact = await api.contacts.get(this.get('jid'));
+            const subscription = contact?.get('subscription');
+            if (!contact || subscription === 'none' || subscription === 'to') {
+                return;
+            }
+
             if (msg?.get('is_markable') || force) {
                 const from_jid = Strophe.getBareJidFromJid(msg.get('from'));
                 sendMarker(from_jid, msg.get('msgid'), type, msg.get('type'));

+ 7 - 6
src/plugins/chatview/tests/markers.js

@@ -1,9 +1,8 @@
 /*global mock, converse */
-
-const Strophe = converse.env.Strophe;
-const u = converse.env.utils;
 // See: https://xmpp.org/rfcs/rfc3921.html
 
+const { Strophe, u, stx } = converse.env;
+
 
 describe("A XEP-0333 Chat Marker", function () {
 
@@ -41,14 +40,16 @@ describe("A XEP-0333 Chat Marker", function () {
         await mock.waitForRoster(_converse, 'current', 0);
         const contact_jid = 'someone@montague.lit';
         const msgid = u.getUniqueId();
-        const stanza = u.toStanza(`
-            <message from='${contact_jid}'
+        const stanza = stx`
+            <message
+                xmlns="jabber:client"
+                from='${contact_jid}'
                 id='${msgid}'
                 type="chat"
                 to='${_converse.jid}'>
               <body>My lord, dispatch; read o'er these articles.</body>
               <markable xmlns='urn:xmpp:chat-markers:0'/>
-            </message>`);
+            </message>`;
 
         const sent_stanzas = [];
         spyOn(_converse.api.connection.get(), 'send').and.callFake(s => sent_stanzas.push(s));