Explorar el Código

New event `messageNotification`

JC Brand hace 6 años
padre
commit
aa730b5976
Se han modificado 3 ficheros con 19 adiciones y 0 borrados
  1. 2 0
      dist/converse.js
  2. 16 0
      docs/source/events.rst
  3. 1 0
      src/converse-notification.js

+ 2 - 0
dist/converse.js

@@ -55920,6 +55920,8 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
         return false;
         return false;
       }
       }
 
 
+      _converse.api.emit('messageNotification', message);
+
       _converse.playSoundNotification();
       _converse.playSoundNotification();
 
 
       _converse.showMessageNotification(message);
       _converse.showMessageNotification(message);

+ 16 - 0
docs/source/events.rst

@@ -259,6 +259,22 @@ as a `message` attribute which refers to the Message model.
         // The original chatbox is at `data.chatbox`.
         // The original chatbox is at `data.chatbox`.
     });
     });
 
 
+
+messageNotification
+~~~~~~~~~~~~~~~~~~~
+
+Emitted just before an HTML5 message notification will be sent out.
+
+.. code-block:: javascript
+
+    _converse.api.listen.on('messageNotification', stanza => {
+
+        const body = sizzle(`encrypted[xmlns="${Strophe.NS.OMEMO}"]`, message).length ?
+                        __('OMEMO Message received') :
+                        _.get(message.querySelector('body'), 'textContent');
+        alert(body);
+    });
+
 messageSend
 messageSend
 ~~~~~~~~~~~
 ~~~~~~~~~~~
 
 

+ 1 - 0
src/converse-notification.js

@@ -261,6 +261,7 @@ converse.plugins.add('converse-notification', {
             if (!_converse.shouldNotifyOfMessage(message)) {
             if (!_converse.shouldNotifyOfMessage(message)) {
                 return false;
                 return false;
             }
             }
+            _converse.api.emit('messageNotification', message);
             _converse.playSoundNotification();
             _converse.playSoundNotification();
             _converse.showMessageNotification(message);
             _converse.showMessageNotification(message);
         };
         };