Commit 754ad7a0 authored by JC Brand's avatar JC Brand

Initial work on combining the converse and inverse modes

- Adds new config setting: `view_mode`
- `converse-singleton` is now a core plugin and its behavior depends on `view_mode`.
parent 221798e6
......@@ -21,10 +21,11 @@
authentication: 'login',
auto_away: 300,
blacklisted_plugins: ['converse-minimize', 'converse-dragresize'],
whitelisted_plugins: ['converse-inverse', 'converse-singleton'],
whitelisted_plugins: ['converse-inverse'],
auto_reconnect: true,
bosh_service_url: 'https://conversejs.org/http-bind/', // Please use this connection manager only for testing purposes
message_archiving: 'always',
view_mode: 'fullscreen'
});
</script>
</body>
......
......@@ -126,12 +126,11 @@
converse.initialize({
bosh_service_url: 'https://conversejs.org/http-bind/', // Please use this connection manager only for testing purposes
message_carbons: true,
// Whitelist non-core plugins that we need
whitelisted_plugins: ['converse-singleton'],
// Blacklist plugins which aren't being used for mobile, so that
// other code cannot register their own plugins under those names.
blacklisted_plugins: ['converse-minimize', 'converse-dragresize'],
show_controlbox_by_default: false,
view_mode: 'mobile'
});
</script>
</html>
......@@ -21,6 +21,7 @@
test_utils.createContacts(_converse, 'current');
spyOn(_converse, 'showMessageNotification');
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
spyOn(_converse, 'isMessageToHiddenChat').and.returnValue(true);
var message = 'This message will show a desktop notification';
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
......@@ -82,6 +83,7 @@
function (done, _converse) {
spyOn(_converse, 'showMessageNotification').and.callThrough();
spyOn(_converse, 'isMessageToHiddenChat').and.returnValue(true);
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
var stanza = $msg({
'type': 'headline',
......
......@@ -80,6 +80,7 @@
'converse-register',
'converse-roomslist',
'converse-rosterview',
'converse-singleton',
'converse-vcard'
];
......@@ -325,6 +326,7 @@
storage: 'session',
strict_plugin_dependencies: false,
synchronize_availability: true,
view_mode: 'overlayed', // Choices are 'overlayed', 'fullscreen', 'mobile'
websocket_url: undefined,
whitelisted_plugins: [],
xhr_custom_status: false,
......
......@@ -18,17 +18,6 @@
"use strict";
const { Strophe, _ } = converse.env;
function isMessageToHiddenChat (_converse, message) {
const jid = Strophe.getBareJidFromJid(message.getAttribute('from'));
const model = _converse.chatboxes.get(jid);
if (!_.isNil(model)) {
return model.get('hidden');
}
// Not having a chat box is assume to be practically the same
// as it being hidden.
return true;
}
converse.plugins.add('converse-inverse', {
overrides: {
......@@ -38,18 +27,6 @@
//
// new functions which don't exist yet can also be added.
areDesktopNotificationsEnabled () {
// Call with "ignore_hidden" as true, so that it doesn't check
// if the windowState is hidden.
return this.__super__.areDesktopNotificationsEnabled.call(this, true);
},
shouldNotifyOfMessage (message) {
const { _converse } = this.__super__;
const result = this.__super__.shouldNotifyOfMessage.apply(this, arguments);
return result && isMessageToHiddenChat(_converse, message);
},
ControlBoxView: {
createBrandHeadingHTML() {
return tpl_brand_heading();
......@@ -84,6 +61,7 @@
hide_open_bookmarks: true,
show_controlbox_by_default: true,
sticky_controlbox: true,
view_mode: 'fullscreen'
});
}
});
......
......@@ -70,6 +70,18 @@
return true;
};
_converse.isMessageToHiddenChat = function (message) {
if (_.includes(['mobile', 'fullscreen'], _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';
}
return true;
}
return _converse.windowState === 'hidden';
}
_converse.shouldNotifyOfMessage = function (message) {
/* Is this a message worthy of notification?
*/
......@@ -83,11 +95,13 @@
return _converse.shouldNotifyOfGroupMessage(message);
} else if (utils.isHeadlineMessage(message)) {
// We want to show notifications for headline messages.
return true;
return _converse.isMessageToHiddenChat(message);
}
const is_me = Strophe.getBareJidFromJid(
message.getAttribute('from')) === _converse.bare_jid;
return !_converse.isOnlyChatStateNotification(message) && !is_me;
return !_converse.isOnlyChatStateNotification(message) &&
!is_me &&
_converse.isMessageToHiddenChat(message);
};
_converse.playSoundNotification = function () {
......@@ -108,15 +122,10 @@
}
};
_converse.areDesktopNotificationsEnabled = function (ignore_hidden) {
const enabled = _converse.supports_html5_notification &&
_converse.areDesktopNotificationsEnabled = function () {
return _converse.supports_html5_notification &&
_converse.show_desktop_notifications &&
Notification.permission === "granted";
if (ignore_hidden) {
return enabled;
} else {
return enabled && _converse.windowState === 'hidden';
}
};
_converse.showMessageNotification = function (message) {
......
......@@ -7,13 +7,15 @@
/*global Backbone, define, window, document, JSON */
/* converse-singleton
/* ******************
* ******************
*
* A non-core plugin which ensures that only one chat, private or group, is
* A plugin which ensures that only one chat (private or groupchat) is
* visible at any one time. All other ongoing chats are hidden and kept in the
* background.
*
* This plugin makes sense in mobile or fullscreen chat environments.
* This plugin makes sense in mobile or fullscreen chat environments (as
* configured by the `view_mode` setting).
*
*/
(function (root, factory) {
define(
......@@ -48,8 +50,11 @@
createChatBox (jid, attrs) {
/* Make sure new chat boxes are hidden by default.
*/
if (_.includes(['mobile', 'fullscreen'],
this.__super__._converse.view_mode)) {
attrs = attrs || {};
attrs.hidden = true;
}
return this.__super__.createChatBox.call(this, jid, attrs);
}
},
......@@ -63,7 +68,10 @@
if (_.isUndefined(result)) {
return
}
if (_.includes(['mobile', 'fullscreen'],
this.__super__._converse.view_mode)) {
result.hidden = false;
}
return result;
}
},
......@@ -75,12 +83,14 @@
* chats are hidden.
*/
const { _converse } = this.__super__;
if (_.includes(['mobile', 'fullscreen'], _converse.view_mode)) {
const chatbox = this.getChatBox(attrs, true);
const hidden = _.isUndefined(attrs.hidden) ? chatbox.get('hidden') : attrs.hidden;
if ((force || !hidden) && _converse.connection.authenticated) {
_.each(_converse.chatboxviews.xget(chatbox.get('id')), hideChat);
chatbox.save({'hidden': false});
}
}
return this.__super__.showChat.apply(this, arguments);
}
},
......@@ -91,8 +101,13 @@
* time. So before opening a chat, we make sure all other
* chats are hidden.
*/
const { _converse } = this.__super__;
if (_.includes(['mobile', 'fullscreen'], _converse.view_mode)) {
if (!this.model.get('hidden')) {
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat);
_.each(_converse.chatboxviews.xget(this.model.get('id')), hideChat);
return this.__super__._show.apply(this, arguments);
}
} else {
return this.__super__._show.apply(this, arguments);
}
}
......@@ -104,8 +119,11 @@
* time. So before opening a chat, we make sure all other
* chats are hidden.
*/
const { _converse } = this.__super__;
if (_.includes(['mobile', 'fullscreen'], _converse.view_mode)) {
_.each(this.__super__._converse.chatboxviews.xget('controlbox'), hideChat);
this.model.save({'hidden': false});
}
return this.__super__.openChat.apply(this, arguments);
},
}
......
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