From e94904e4a16fffa2265a55dece6edf55aebbc12a Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sun, 14 Feb 2016 12:10:54 +0000 Subject: [PATCH] Don't play sound notifications for... OTR messages which are setting up an encrypted session. --- docs/CHANGES.md | 11 ++++++++--- src/converse-core.js | 37 +++++++++++++++++++++++-------------- src/converse-otr.js | 23 ++++++++++++++++++++--- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/docs/CHANGES.md b/docs/CHANGES.md index fc1e4b377..a233834f2 100755 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -1,11 +1,16 @@ # Changelog -## 0.10.2 (Unreleased) +## 0.11.0 (Unreleased) -- #261 show_controlbox_by_default config not working [diditopher] -- #573 xgettext build error: `'javascript' unknown` +- Split converse.js into different modules. The code for the OTR and MUC + features are now in separate modules and these can be removed completely from + the build. [jcbrand] +- Don't play sound notifications for OTR messages which are setting up an + encrypted session. [jcbrand] - Save scroll position on minimize and restore it on maximize [rlanvin] +- #261 show_controlbox_by_default config not working [diditopher] - #566 Do not steal the focus when the chatbox opens automatically [rlanvin] +- #573 xgettext build error: `'javascript' unknown` [jcbrand] ## 0.10.1 (2016-02-06) diff --git a/src/converse-core.js b/src/converse-core.js index 3da2c8633..70a8dcaaf 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -955,6 +955,28 @@ }); }, + isOnlyChatStateNotification: function ($msg) { + // See XEP-0085 Chat State Notification + return ( + $msg.find('body').length === 0 && ( + $msg.find(ACTIVE).length !== 0 || + $msg.find(COMPOSING).length !== 0 || + $msg.find(INACTIVE).length !== 0 || + $msg.find(PAUSED).length !== 0 || + $msg.find(GONE).length !== 0 + ) + ); + }, + + shouldPlayNotification: function ($message) { + var $forwarded = $message.find('forwarded'); + if ($forwarded.length) { + return false; + } + var is_me = Strophe.getBareJidFromJid($message.attr('from')) === converse.bare_jid; + return !this.isOnlyChatStateNotification($message) && !is_me; + }, + createMessage: function ($message, $delay, archive_id) { $delay = $delay || $message.find('delay'); var body = $message.children('body').text(), @@ -2313,19 +2335,6 @@ }); }, - isOnlyChatStateNotification: function ($msg) { - // See XEP-0085 Chat State Notification - return ( - $msg.find('body').length === 0 && ( - $msg.find(ACTIVE).length !== 0 || - $msg.find(COMPOSING).length !== 0 || - $msg.find(INACTIVE).length !== 0 || - $msg.find(PAUSED).length !== 0 || - $msg.find(GONE).length !== 0 - ) - ); - }, - onMessage: function (message) { /* Handler method for all incoming single-user chat "message" stanzas. */ @@ -2374,7 +2383,7 @@ if (msgid && chatbox.messages.findWhere({msgid: msgid})) { return true; // We already have this message stored. } - if (!this.isOnlyChatStateNotification($message) && !is_me && !$forwarded.length) { + if (chatbox.shouldPlayNotification($message)) { converse.playNotification(); } chatbox.createMessage($message, $delay, archive_id); diff --git a/src/converse-otr.js b/src/converse-otr.js index 7f778917f..e8f2128a4 100644 --- a/src/converse-otr.js +++ b/src/converse-otr.js @@ -109,10 +109,27 @@ } }, + isOTRMessage: function ($message) { + var $body = $message.children('body'), + text = ($body.length > 0 ? $body.text() : undefined); + return !!text.match(/^\?OTR/); + }, + + shouldPlayNotification: function ($message) { + /* Don't play a notification if this is an OTR message but + * encryption is not yet set up. That would mean that the + * OTR session is still being established, so there are no + * "visible" OTR messages being exchanged. + */ + return this._super.shouldPlayNotification.apply(this, arguments) && + !(this.isOTRMessage($message) && !_.contains([UNVERIFIED, VERIFIED], this.get('otr_status'))); + }, + createMessage: function ($message, $delay, archive_id) { - var converse = this._super.converse; - var $body = $message.children('body'); - var text = ($body.length > 0 ? $body.text() : undefined); + var converse = this._super.converse, + $body = $message.children('body'), + text = ($body.length > 0 ? $body.text() : undefined); + if ((!text) || (!converse.allow_otr)) { return this._super.createMessage.apply(this, arguments); }