Commit 15f962ad authored by JC Brand's avatar JC Brand

Add `converse-singleton` to the mobile build.

This will make the unread messages feature work.
Update so that new chats are opened in the background.
parent c8159993
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
## 3.1.0 (Unreleased) ## 3.1.0 (Unreleased)
- New non-core plugin `converse-singleton` which ensures that no more than
one chat is visible at any given time. Used in the mobile build:
`converse-mobile.js` and makes the unread messages counter possible there.
[jcbrand]
- Show unread messages next to roster contacts. [jcbrand] - Show unread messages next to roster contacts. [jcbrand]
- API change: the `message` event now returns a data object with `stanza` and - API change: the `message` event now returns a data object with `stanza` and
`chatbox` attributes, instead of just the stanza. [jcbrand] `chatbox` attributes, instead of just the stanza. [jcbrand]
......
...@@ -46,10 +46,10 @@ require.config({ ...@@ -46,10 +46,10 @@ require.config({
// Converse // Converse
"converse": "src/converse", "converse": "src/converse",
"converse-core": "src/converse-core",
"converse-bookmarks": "src/converse-bookmarks", "converse-bookmarks": "src/converse-bookmarks",
"converse-chatview": "src/converse-chatview", "converse-chatview": "src/converse-chatview",
"converse-controlbox": "src/converse-controlbox", "converse-controlbox": "src/converse-controlbox",
"converse-core": "src/converse-core",
"converse-dragresize": "src/converse-dragresize", "converse-dragresize": "src/converse-dragresize",
"converse-headline": "src/converse-headline", "converse-headline": "src/converse-headline",
"converse-mam": "src/converse-mam", "converse-mam": "src/converse-mam",
...@@ -61,6 +61,7 @@ require.config({ ...@@ -61,6 +61,7 @@ require.config({
"converse-ping": "src/converse-ping", "converse-ping": "src/converse-ping",
"converse-register": "src/converse-register", "converse-register": "src/converse-register",
"converse-rosterview": "src/converse-rosterview", "converse-rosterview": "src/converse-rosterview",
"converse-singleton": "src/converse-singleton",
"converse-vcard": "src/converse-vcard", "converse-vcard": "src/converse-vcard",
// Off-the-record-encryption // Off-the-record-encryption
......
...@@ -1543,34 +1543,30 @@ ...@@ -1543,34 +1543,30 @@
return true; return true;
}, },
getChatBox: function (jid, create, attrs) { createChatBox: function (jid, attrs) {
/* Returns a chat box or optionally return a newly /* Creates a chat box
* created one if one doesn't exist.
* *
* Parameters: * Parameters:
* (String) jid - The JID of the user whose chat box we want * (String) jid - The JID of the user for whom a chat box
* (Boolean) create - Should a new chat box be created if none exists? * gets created.
* (Object) attrs - Optional chat box atributes. * (Object) attrs - Optional chat box atributes.
*/ */
jid = jid.toLowerCase();
var bare_jid = Strophe.getBareJidFromJid(jid); var bare_jid = Strophe.getBareJidFromJid(jid);
var chatbox = this.get(bare_jid); var roster_info = {};
if (!chatbox && create) { var roster_item = _converse.roster.get(bare_jid);
var roster_info = {}; if (! _.isUndefined(roster_item)) {
var roster_item = _converse.roster.get(bare_jid); roster_info = {
if (! _.isUndefined(roster_item)) { 'fullname': _.isEmpty(roster_item.get('fullname'))? jid: roster_item.get('fullname'),
roster_info = { 'image_type': roster_item.get('image_type'),
'fullname': _.isEmpty(roster_item.get('fullname'))? jid: roster_item.get('fullname'), 'image': roster_item.get('image'),
'image_type': roster_item.get('image_type'), 'url': roster_item.get('url'),
'image': roster_item.get('image'), };
'url': roster_item.get('url'), } else if (!_converse.allow_non_roster_messaging) {
}; _converse.log('Could not get roster item for JID '+bare_jid+
} else if (!_converse.allow_non_roster_messaging) { ' and allow_non_roster_messaging is set to false', 'error');
_converse.log('Could not get roster item for JID '+bare_jid+ return;
' and allow_non_roster_messaging is set to false', 'error'); }
return; return this.create(_.assignIn({
}
chatbox = this.create(_.assignIn({
'id': bare_jid, 'id': bare_jid,
'jid': bare_jid, 'jid': bare_jid,
'fullname': jid, 'fullname': jid,
...@@ -1578,6 +1574,21 @@ ...@@ -1578,6 +1574,21 @@
'image': DEFAULT_IMAGE, 'image': DEFAULT_IMAGE,
'url': '', 'url': '',
}, roster_info, attrs || {})); }, roster_info, attrs || {}));
},
getChatBox: function (jid, create, attrs) {
/* Returns a chat box or optionally return a newly
* created one if one doesn't exist.
*
* Parameters:
* (String) jid - The JID of the user whose chat box we want
* (Boolean) create - Should a new chat box be created if none exists?
* (Object) attrs - Optional chat box atributes.
*/
jid = jid.toLowerCase();
var chatbox = this.get(Strophe.getBareJidFromJid(jid));
if (!chatbox && create) {
chatbox = this.createChatBox(jid, attrs);
} }
return chatbox; return chatbox;
} }
......
...@@ -11,17 +11,18 @@ if (typeof define !== 'undefined') { ...@@ -11,17 +11,18 @@ if (typeof define !== 'undefined') {
* -------------------- * --------------------
* Any of the following components may be removed if they're not needed. * Any of the following components may be removed if they're not needed.
*/ */
"converse-bookmarks", // XEP-0048 Bookmarks
"converse-chatview", // Renders standalone chat boxes for single user chat "converse-chatview", // Renders standalone chat boxes for single user chat
"converse-controlbox", // The control box "converse-controlbox", // The control box
"converse-bookmarks", // XEP-0048 Bookmarks "converse-headline", // Support for headline messages
"converse-mam", // XEP-0313 Message Archive Management "converse-mam", // XEP-0313 Message Archive Management
"converse-muc", // XEP-0045 Multi-user chat "converse-muc", // XEP-0045 Multi-user chat
"converse-vcard", // XEP-0054 VCard-temp "converse-notification",// HTML5 Notifications
"converse-otr", // Off-the-record encryption for one-on-one messages "converse-otr", // Off-the-record encryption for one-on-one messages
"converse-register", // XEP-0077 In-band registration
"converse-ping", // XEP-0199 XMPP Ping "converse-ping", // XEP-0199 XMPP Ping
"converse-notification",// HTML5 Notifications "converse-register", // XEP-0077 In-band registration
"converse-headline", // Support for headline messages "converse-singleton", // Allow at most a single chat to be visible at any one time
"converse-vcard", // XEP-0054 VCard-temp
/* END: Removable components */ /* END: Removable components */
], function (converse) { ], function (converse) {
return converse; return converse;
......
...@@ -38,6 +38,17 @@ ...@@ -38,6 +38,17 @@
// relevant objects or classes. // relevant objects or classes.
// //
// new functions which don't exist yet can also be added. // new functions which don't exist yet can also be added.
ChatBoxes: {
createChatBox: function (jid, attrs) {
/* Make sure new chat boxes are hidden by default.
*/
attrs = attrs || {};
attrs.hidden = true;
return this.__super__.createChatBox.call(this, jid, attrs);
}
},
ChatBoxViews: { ChatBoxViews: {
showChat: function (attrs) { showChat: function (attrs) {
...@@ -46,8 +57,13 @@ ...@@ -46,8 +57,13 @@
* chats are hidden. * chats are hidden.
*/ */
var _converse = this.__super__._converse; var _converse = this.__super__._converse;
var chatbox = this.getChatBox(attrs, true); var chatbox = this.getChatBox(attrs);
if (!attrs.hidden && _converse.connection.authenticated) { if (_.isUndefined(chatbox)) {
// We don't show new chat boxes, but instead open them
// in the background.
attrs.hidden = true;
chatbox = this.getChatBox(attrs, true);
} else if (!attrs.hidden && _converse.connection.authenticated) {
_.each(_converse.chatboxviews.xget(chatbox.get('id')), _.each(_converse.chatboxviews.xget(chatbox.get('id')),
function (view) { function (view) {
if (view.model.get('id') === 'controlbox') { if (view.model.get('id') === 'controlbox') {
...@@ -70,6 +86,9 @@ ...@@ -70,6 +86,9 @@
*/ */
if (!this.model.get('hidden')) { if (!this.model.get('hidden')) {
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), function (view) { _.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), function (view) {
if (view.model.get('id') === 'controlbox') {
return;
}
view.hide(); view.hide();
view.model.set({'hidden': true}); view.model.set({'hidden': true});
}); });
......
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