Browse Source

Fixes #1714

don't notify if only message delivery receipt
Christoph Scholz 5 years ago
parent
commit
bce8dc9113
3 changed files with 14 additions and 0 deletions
  1. 1 0
      CHANGES.md
  2. 1 0
      src/converse-notification.js
  3. 12 0
      src/headless/utils/core.js

+ 1 - 0
CHANGES.md

@@ -7,6 +7,7 @@
 - #1712: `TypeError: plugin._features is not a function`
 - Bugfix: process stanzas from mam one-by-one in order to correctly process message
   receipts
+- #1714 Bugfix: Don't notify the user in case we're receiving a message delivery receipt only
 
 ## 5.0.3 (2019-09-13)
 

+ 1 - 0
src/converse-notification.js

@@ -87,6 +87,7 @@ converse.plugins.add('converse-notification', {
             }
             const is_me = Strophe.getBareJidFromJid(message.getAttribute('from')) === _converse.bare_jid;
             return !u.isOnlyChatStateNotification(message) &&
+                !u.isOnlyMessageDeliveryReceipt(message) &&
                 !is_me &&
                 (_converse.show_desktop_notifications === 'all' || _converse.isMessageToHiddenChat(message));
         };

+ 12 - 0
src/headless/utils/core.js

@@ -148,6 +148,18 @@ u.isOnlyChatStateNotification = function (msg) {
     return msg['chat_state'] && u.isEmptyMessage(msg);
 };
 
+u.isOnlyMessageDeliveryReceipt = function (msg) {
+    if (msg instanceof Element) {
+        // See XEP-0184 Message Delivery Receipts
+        return (msg.querySelector('body') === null) &&
+                    (msg.querySelector('received') !== null);
+    }
+    if (msg instanceof Backbone.Model) {
+        msg = msg.attributes;
+    }
+    return msg['received'] && u.isEmptyMessage(msg);
+};
+
 u.isHeadlineMessage = function (_converse, message) {
     const from_jid = message.getAttribute('from');
     if (message.getAttribute('type') === 'headline') {