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)
// 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)
//
/*global define */
......@@ -10,10 +10,13 @@
define(["converse-core"], factory);
}(this, function (converse) {
"use strict";
const { utils, Strophe, _ } = converse.env;
const { Strophe, _ } = converse.env,
u = converse.env.utils;
converse.plugins.add('converse-notification', {
dependencies: ["converse-chatboxes"],
initialize () {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
......@@ -72,10 +75,11 @@
_converse.isMessageToHiddenChat = function (message) {
if (_.includes(['mobile', 'fullscreen', 'embedded'], _converse.view_mode)) {
const jid = Strophe.getBareJidFromJid(message.getAttribute('from'));
const model = _converse.chatboxes.get(jid);
if (!_.isNil(model)) {
return model.get('hidden') || _converse.windowState === 'hidden';
const jid = Strophe.getBareJidFromJid(message.getAttribute('from')),
view = _converse.chatboxviews.get(jid);
if (!_.isNil(view)) {
return view.model.get('hidden') || _converse.windowState === 'hidden' || !u.isVisible(view.el);
}
return true;
}
......@@ -83,14 +87,12 @@
}
_converse.shouldNotifyOfMessage = function (message) {
/* Is this a message worthy of notification?
*/
const forwarded = message.querySelector('forwarded');
if (!_.isNull(forwarded)) {
return false;
} else if (message.getAttribute('type') === 'groupchat') {
return _converse.shouldNotifyOfGroupMessage(message);
} else if (utils.isHeadlineMessage(_converse, message)) {
} else if (u.isHeadlineMessage(_converse, message)) {
// We want to show notifications for headline messages.
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