Commit d90bcd52 authored by JC Brand's avatar JC Brand

Combine two versions of isOnlyChatStateNotification into one

Also fix a bug in the code dermining whether an XMLElement stanza is only a chat state notification
parent 7a590f7c
...@@ -38,17 +38,6 @@ converse.plugins.add('converse-notification', { ...@@ -38,17 +38,6 @@ converse.plugins.add('converse-notification', {
notification_delay: 5000 notification_delay: 5000
}); });
_converse.isOnlyChatStateNotification = (msg) =>
// See XEP-0085 Chat State Notification
_.isNull(msg.querySelector('body')) && (
_.isNull(msg.querySelector(_converse.ACTIVE)) ||
_.isNull(msg.querySelector(_converse.COMPOSING)) ||
_.isNull(msg.querySelector(_converse.INACTIVE)) ||
_.isNull(msg.querySelector(_converse.PAUSED)) ||
_.isNull(msg.querySelector(_converse.GONE))
)
;
_converse.shouldNotifyOfGroupMessage = function (message) { _converse.shouldNotifyOfGroupMessage = function (message) {
/* Is this a group message worthy of notification? /* Is this a group message worthy of notification?
*/ */
...@@ -96,9 +85,8 @@ converse.plugins.add('converse-notification', { ...@@ -96,9 +85,8 @@ converse.plugins.add('converse-notification', {
// We want to show notifications for headline messages. // We want to show notifications for headline messages.
return _converse.isMessageToHiddenChat(message); return _converse.isMessageToHiddenChat(message);
} }
const is_me = Strophe.getBareJidFromJid( const is_me = Strophe.getBareJidFromJid(message.getAttribute('from')) === _converse.bare_jid;
message.getAttribute('from')) === _converse.bare_jid; return !u.isOnlyChatStateNotification(message) &&
return !_converse.isOnlyChatStateNotification(message) &&
!is_me && !is_me &&
(_converse.show_desktop_notifications === 'all' || _converse.isMessageToHiddenChat(message)); (_converse.show_desktop_notifications === 'all' || _converse.isMessageToHiddenChat(message));
}; };
......
...@@ -128,11 +128,20 @@ u.isEmptyMessage = function (attrs) { ...@@ -128,11 +128,20 @@ u.isEmptyMessage = function (attrs) {
!attrs['message']; !attrs['message'];
}; };
u.isOnlyChatStateNotification = function (attrs) { u.isOnlyChatStateNotification = function (msg) {
if (attrs instanceof Backbone.Model) { if (msg instanceof Element) {
attrs = attrs.attributes; // See XEP-0085 Chat State Notification
return (msg.querySelector('body') === null) && (
(msg.querySelector('active') !== null) ||
(msg.querySelector('composing') !== null) ||
(msg.querySelector('inactive') !== null) ||
(msg.querySelector('paused') !== null) ||
(msg.querySelector('gone') !== null));
}
if (msg instanceof Backbone.Model) {
msg = msg.attributes;
} }
return attrs['chat_state'] && u.isEmptyMessage(attrs); return msg['chat_state'] && u.isEmptyMessage(msg);
}; };
u.isHeadlineMessage = function (_converse, message) { u.isHeadlineMessage = function (_converse, message) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment