Commit f947bcc4 authored by JC Brand's avatar JC Brand

Also notify if the chat is not visible in the page.

parent 33c2d461
// Converse.js (A browser based XMPP chat client) // Converse.js (A browser based XMPP chat client)
// http://conversejs.org // http://conversejs.org
// //
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2013-2018, JC Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
// //
/*global define */ /*global define */
...@@ -10,10 +10,13 @@ ...@@ -10,10 +10,13 @@
define(["converse-core"], factory); define(["converse-core"], factory);
}(this, function (converse) { }(this, function (converse) {
"use strict"; "use strict";
const { utils, Strophe, _ } = converse.env; const { Strophe, _ } = converse.env,
u = converse.env.utils;
converse.plugins.add('converse-notification', { converse.plugins.add('converse-notification', {
dependencies: ["converse-chatboxes"],
initialize () { initialize () {
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
...@@ -72,10 +75,11 @@ ...@@ -72,10 +75,11 @@
_converse.isMessageToHiddenChat = function (message) { _converse.isMessageToHiddenChat = function (message) {
if (_.includes(['mobile', 'fullscreen', 'embedded'], _converse.view_mode)) { if (_.includes(['mobile', 'fullscreen', 'embedded'], _converse.view_mode)) {
const jid = Strophe.getBareJidFromJid(message.getAttribute('from')); const jid = Strophe.getBareJidFromJid(message.getAttribute('from')),
const model = _converse.chatboxes.get(jid); view = _converse.chatboxviews.get(jid);
if (!_.isNil(model)) {
return model.get('hidden') || _converse.windowState === 'hidden'; if (!_.isNil(view)) {
return view.model.get('hidden') || _converse.windowState === 'hidden' || !u.isVisible(view.el);
} }
return true; return true;
} }
...@@ -83,14 +87,12 @@ ...@@ -83,14 +87,12 @@
} }
_converse.shouldNotifyOfMessage = function (message) { _converse.shouldNotifyOfMessage = function (message) {
/* Is this a message worthy of notification?
*/
const forwarded = message.querySelector('forwarded'); const forwarded = message.querySelector('forwarded');
if (!_.isNull(forwarded)) { if (!_.isNull(forwarded)) {
return false; return false;
} else if (message.getAttribute('type') === 'groupchat') { } else if (message.getAttribute('type') === 'groupchat') {
return _converse.shouldNotifyOfGroupMessage(message); return _converse.shouldNotifyOfGroupMessage(message);
} else if (utils.isHeadlineMessage(_converse, message)) { } else if (u.isHeadlineMessage(_converse, message)) {
// We want to show notifications for headline messages. // We want to show notifications for headline messages.
return _converse.isMessageToHiddenChat(message); return _converse.isMessageToHiddenChat(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