From aa730b597641a3fe4c368d0f6c52feff5d343412 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Thu, 6 Dec 2018 13:55:28 +0100 Subject: [PATCH] New event `messageNotification` --- dist/converse.js | 2 ++ docs/source/events.rst | 16 ++++++++++++++++ src/converse-notification.js | 1 + 3 files changed, 19 insertions(+) diff --git a/dist/converse.js b/dist/converse.js index c28c6fa1d..5c6b81ba2 100644 --- a/dist/converse.js +++ b/dist/converse.js @@ -55920,6 +55920,8 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins return false; } + _converse.api.emit('messageNotification', message); + _converse.playSoundNotification(); _converse.showMessageNotification(message); diff --git a/docs/source/events.rst b/docs/source/events.rst index 9f80886e6..b6876e733 100644 --- a/docs/source/events.rst +++ b/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`. }); + +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 ~~~~~~~~~~~ diff --git a/src/converse-notification.js b/src/converse-notification.js index eb3300e20..43cbb87db 100644 --- a/src/converse-notification.js +++ b/src/converse-notification.js @@ -261,6 +261,7 @@ converse.plugins.add('converse-notification', { if (!_converse.shouldNotifyOfMessage(message)) { return false; } + _converse.api.emit('messageNotification', message); _converse.playSoundNotification(); _converse.showMessageNotification(message); };