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