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', {
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) {
/* Is this a group message worthy of notification?
*/
......@@ -96,9 +85,8 @@ converse.plugins.add('converse-notification', {
// We want to show notifications for headline messages.
return _converse.isMessageToHiddenChat(message);
}
const is_me = Strophe.getBareJidFromJid(
message.getAttribute('from')) === _converse.bare_jid;
return !_converse.isOnlyChatStateNotification(message) &&
const is_me = Strophe.getBareJidFromJid(message.getAttribute('from')) === _converse.bare_jid;
return !u.isOnlyChatStateNotification(message) &&
!is_me &&
(_converse.show_desktop_notifications === 'all' || _converse.isMessageToHiddenChat(message));
};
......
......@@ -128,11 +128,20 @@ u.isEmptyMessage = function (attrs) {
!attrs['message'];
};
u.isOnlyChatStateNotification = function (attrs) {
if (attrs instanceof Backbone.Model) {
attrs = attrs.attributes;
}
return attrs['chat_state'] && u.isEmptyMessage(attrs);
u.isOnlyChatStateNotification = function (msg) {
if (msg instanceof Element) {
// 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 msg['chat_state'] && u.isEmptyMessage(msg);
};
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