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 @@
## 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]
- API change: the `message` event now returns a data object with `stanza` and
`chatbox` attributes, instead of just the stanza. [jcbrand]
......
......@@ -46,10 +46,10 @@ require.config({
// Converse
"converse": "src/converse",
"converse-core": "src/converse-core",
"converse-bookmarks": "src/converse-bookmarks",
"converse-chatview": "src/converse-chatview",
"converse-controlbox": "src/converse-controlbox",
"converse-core": "src/converse-core",
"converse-dragresize": "src/converse-dragresize",
"converse-headline": "src/converse-headline",
"converse-mam": "src/converse-mam",
......@@ -61,6 +61,7 @@ require.config({
"converse-ping": "src/converse-ping",
"converse-register": "src/converse-register",
"converse-rosterview": "src/converse-rosterview",
"converse-singleton": "src/converse-singleton",
"converse-vcard": "src/converse-vcard",
// Off-the-record-encryption
......
......@@ -1543,34 +1543,30 @@
return true;
},
getChatBox: function (jid, create, attrs) {
/* Returns a chat box or optionally return a newly
* created one if one doesn't exist.
createChatBox: function (jid, attrs) {
/* Creates a chat box
*
* 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?
* (String) jid - The JID of the user for whom a chat box
* gets created.
* (Object) attrs - Optional chat box atributes.
*/
jid = jid.toLowerCase();
var bare_jid = Strophe.getBareJidFromJid(jid);
var chatbox = this.get(bare_jid);
if (!chatbox && create) {
var roster_info = {};
var roster_item = _converse.roster.get(bare_jid);
if (! _.isUndefined(roster_item)) {
roster_info = {
'fullname': _.isEmpty(roster_item.get('fullname'))? jid: roster_item.get('fullname'),
'image_type': roster_item.get('image_type'),
'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+
' and allow_non_roster_messaging is set to false', 'error');
return;
}
chatbox = this.create(_.assignIn({
var roster_info = {};
var roster_item = _converse.roster.get(bare_jid);
if (! _.isUndefined(roster_item)) {
roster_info = {
'fullname': _.isEmpty(roster_item.get('fullname'))? jid: roster_item.get('fullname'),
'image_type': roster_item.get('image_type'),
'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+
' and allow_non_roster_messaging is set to false', 'error');
return;
}
return this.create(_.assignIn({
'id': bare_jid,
'jid': bare_jid,
'fullname': jid,
......@@ -1578,6 +1574,21 @@
'image': DEFAULT_IMAGE,
'url': '',
}, 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;
}
......
......@@ -11,17 +11,18 @@ if (typeof define !== 'undefined') {
* --------------------
* 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-controlbox", // The control box
"converse-bookmarks", // XEP-0048 Bookmarks
"converse-headline", // Support for headline messages
"converse-mam", // XEP-0313 Message Archive Management
"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-register", // XEP-0077 In-band registration
"converse-ping", // XEP-0199 XMPP Ping
"converse-notification",// HTML5 Notifications
"converse-headline", // Support for headline messages
"converse-register", // XEP-0077 In-band registration
"converse-singleton", // Allow at most a single chat to be visible at any one time
"converse-vcard", // XEP-0054 VCard-temp
/* END: Removable components */
], function (converse) {
return converse;
......
......@@ -38,6 +38,17 @@
// relevant objects or classes.
//
// 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: {
showChat: function (attrs) {
......@@ -46,8 +57,13 @@
* chats are hidden.
*/
var _converse = this.__super__._converse;
var chatbox = this.getChatBox(attrs, true);
if (!attrs.hidden && _converse.connection.authenticated) {
var chatbox = this.getChatBox(attrs);
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')),
function (view) {
if (view.model.get('id') === 'controlbox') {
......@@ -70,6 +86,9 @@
*/
if (!this.model.get('hidden')) {
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), function (view) {
if (view.model.get('id') === 'controlbox') {
return;
}
view.hide();
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