Commit e38daf34 authored by JC Brand's avatar JC Brand

Remove coupling between converse-chatboxes and converse-roster

In embedded mode (singleton) we don't need or want the roster, so we
should be able to disable it.

updates #1374
parent a8ed46f6
...@@ -49303,21 +49303,6 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins ...@@ -49303,21 +49303,6 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins
}); });
/************************ BEGIN Event Handlers ************************/ /************************ BEGIN Event Handlers ************************/
_converse.api.waitUntil('rosterContactsFetched').then(() => {
_converse.roster.on('add', contact => {
/* When a new contact is added, check if we already have a
* chatbox open for it, and if so attach it to the chatbox.
*/
const chatbox = _converse.chatboxes.findWhere({
'jid': contact.get('jid')
});
if (chatbox) {
chatbox.addRelatedContact(contact);
}
});
});
_converse.api.listen.on('chatBoxesInitialized', () => { _converse.api.listen.on('chatBoxesInitialized', () => {
_converse.chatboxviews = new _converse.ChatBoxViews({ _converse.chatboxviews = new _converse.ChatBoxViews({
'model': _converse.chatboxes 'model': _converse.chatboxes
...@@ -61571,7 +61556,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -61571,7 +61556,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
model: _converse.Message, model: _converse.Message,
comparator: 'time' comparator: 'time'
}); });
_converse.ChatBox = _converse.ModelWithVCardAndPresence.extend({ _converse.ChatBox = Backbone.Model.extend({
defaults() { defaults() {
return { return {
'bookmarked': false, 'bookmarked': false,
...@@ -61585,19 +61570,25 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -61585,19 +61570,25 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
}, },
initialize() { initialize() {
_converse.ModelWithVCardAndPresence.prototype.initialize.apply(this, arguments); const jid = this.get('jid');
this.vcard = _converse.vcards.findWhere({
'jid': jid
}) || _converse.vcards.create({
'jid': jid
}); // XXX: this creates a dependency on converse-roster, which we
// probably shouldn't have here, so we should probably move
// ChatBox out of converse-chatboxes
_converse.api.waitUntil('rosterContactsFetched').then(() => { this.presence = _converse.presences.findWhere({
this.addRelatedContact(_converse.roster.findWhere({ 'jid': jid
'jid': this.get('jid') }) || _converse.presences.create({
})); 'jid': jid
}); });
this.messages = new _converse.Messages(); this.messages = new _converse.Messages();
const storage = _converse.config.get('storage'); const storage = _converse.config.get('storage');
this.messages.browserStorage = new Backbone.BrowserStorage[storage](b64_sha1(`converse.messages${this.get('jid')}${_converse.bare_jid}`)); this.messages.browserStorage = new Backbone.BrowserStorage[storage](b64_sha1(`converse.messages${jid}${_converse.bare_jid}`));
this.messages.chatbox = this; this.messages.chatbox = this;
this.messages.on('change:upload', message => { this.messages.on('change:upload', message => {
if (message.get('upload') === _converse.SUCCESS) { if (message.get('upload') === _converse.SUCCESS) {
...@@ -61614,13 +61605,6 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -61614,13 +61605,6 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
}); });
}, },
addRelatedContact(contact) {
if (!_.isUndefined(contact)) {
this.contact = contact;
this.trigger('contactAdded', contact);
}
},
getDisplayName() { getDisplayName() {
return this.vcard.get('fullname') || this.get('jid'); return this.vcard.get('fullname') || this.get('jid');
}, },
...@@ -62269,21 +62253,6 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -62269,21 +62253,6 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
_converse.on('chatBoxesFetched', autoJoinChats); _converse.on('chatBoxesFetched', autoJoinChats);
_converse.api.waitUntil('rosterContactsFetched').then(() => {
_converse.roster.on('add', contact => {
/* When a new contact is added, check if we already have a
* chatbox open for it, and if so attach it to the chatbox.
*/
const chatbox = _converse.chatboxes.findWhere({
'jid': contact.get('jid')
});
if (chatbox) {
chatbox.addRelatedContact(contact);
}
});
});
_converse.on('addClientFeatures', () => { _converse.on('addClientFeatures', () => {
_converse.api.disco.own.features.add(Strophe.NS.MESSAGE_CORRECT); _converse.api.disco.own.features.add(Strophe.NS.MESSAGE_CORRECT);
...@@ -63791,7 +63760,7 @@ _converse.initialize = function (settings, callback) { ...@@ -63791,7 +63760,7 @@ _converse.initialize = function (settings, callback) {
} else { } else {
_i18n__WEBPACK_IMPORTED_MODULE_6__["default"].fetchTranslations(_converse.locale, _converse.locales, _converse_headless_utils_core__WEBPACK_IMPORTED_MODULE_11__["default"].interpolate(_converse.locales_url, { _i18n__WEBPACK_IMPORTED_MODULE_6__["default"].fetchTranslations(_converse.locale, _converse.locales, _converse_headless_utils_core__WEBPACK_IMPORTED_MODULE_11__["default"].interpolate(_converse.locales_url, {
'locale': _converse.locale 'locale': _converse.locale
})).catch(e => _converse.log(e.message, strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.FATAL)).finally(finishInitialization); })).catch(e => _converse.log(e.message, strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.FATAL)).finally(finishInitialization).catch(e => _converse.log(e.message, strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.FATAL));
} }
return init_promise; return init_promise;
...@@ -68597,6 +68566,13 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins ...@@ -68597,6 +68566,13 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
/********** Event Handlers *************/ /********** Event Handlers *************/
function addRelatedContactToChatbox(chatbox, contact) {
if (!_.isUndefined(contact)) {
chatbox.contact = contact;
chatbox.trigger('contactAdded', contact);
}
}
function updateUnreadCounter(chatbox) { function updateUnreadCounter(chatbox) {
const contact = _converse.roster.findWhere({ const contact = _converse.roster.findWhere({
'jid': chatbox.get('jid') 'jid': chatbox.get('jid')
...@@ -68611,10 +68587,32 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins ...@@ -68611,10 +68587,32 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
_converse.api.listen.on('chatBoxesInitialized', () => { _converse.api.listen.on('chatBoxesInitialized', () => {
_converse.chatboxes.on('change:num_unread', updateUnreadCounter); _converse.chatboxes.on('change:num_unread', updateUnreadCounter);
_converse.chatboxes.on('add', async chatbox => {
await _converse.api.waitUntil('rosterContactsFetched');
addRelatedContactToChatbox(chatbox, _converse.roster.findWhere({
'jid': chatbox.get('jid')
}));
});
}); });
_converse.api.listen.on('beforeTearDown', _converse.unregisterPresenceHandler()); _converse.api.listen.on('beforeTearDown', _converse.unregisterPresenceHandler());
_converse.api.waitUntil('rosterContactsFetched').then(() => {
_converse.roster.on('add', contact => {
/* When a new contact is added, check if we already have a
* chatbox open for it, and if so attach it to the chatbox.
*/
const chatbox = _converse.chatboxes.findWhere({
'jid': contact.get('jid')
});
if (chatbox) {
addRelatedContactToChatbox(chatbox, contact);
}
});
});
_converse.api.listen.on('afterTearDown', () => { _converse.api.listen.on('afterTearDown', () => {
if (_converse.presences) { if (_converse.presences) {
_converse.presences.off().reset(); // Remove presences _converse.presences.off().reset(); // Remove presences
...@@ -145,19 +145,6 @@ converse.plugins.add('converse-chatboxviews', { ...@@ -145,19 +145,6 @@ converse.plugins.add('converse-chatboxviews', {
/************************ BEGIN Event Handlers ************************/ /************************ BEGIN Event Handlers ************************/
_converse.api.waitUntil('rosterContactsFetched').then(() => {
_converse.roster.on('add', (contact) => {
/* When a new contact is added, check if we already have a
* chatbox open for it, and if so attach it to the chatbox.
*/
const chatbox = _converse.chatboxes.findWhere({'jid': contact.get('jid')});
if (chatbox) {
chatbox.addRelatedContact(contact);
}
});
});
_converse.api.listen.on('chatBoxesInitialized', () => { _converse.api.listen.on('chatBoxesInitialized', () => {
_converse.chatboxviews = new _converse.ChatBoxViews({ _converse.chatboxviews = new _converse.ChatBoxViews({
'model': _converse.chatboxes 'model': _converse.chatboxes
......
...@@ -219,7 +219,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -219,7 +219,7 @@ converse.plugins.add('converse-chatboxes', {
}); });
_converse.ChatBox = _converse.ModelWithVCardAndPresence.extend({ _converse.ChatBox = Backbone.Model.extend({
defaults () { defaults () {
return { return {
'bookmarked': false, 'bookmarked': false,
...@@ -233,15 +233,17 @@ converse.plugins.add('converse-chatboxes', { ...@@ -233,15 +233,17 @@ converse.plugins.add('converse-chatboxes', {
}, },
initialize () { initialize () {
_converse.ModelWithVCardAndPresence.prototype.initialize.apply(this, arguments); const jid = this.get('jid');
this.vcard = _converse.vcards.findWhere({'jid': jid}) || _converse.vcards.create({'jid': jid});
// XXX: this creates a dependency on converse-roster, which we
// probably shouldn't have here, so we should probably move
// ChatBox out of converse-chatboxes
this.presence = _converse.presences.findWhere({'jid': jid}) || _converse.presences.create({'jid': jid});
_converse.api.waitUntil('rosterContactsFetched').then(() => {
this.addRelatedContact(_converse.roster.findWhere({'jid': this.get('jid')}));
});
this.messages = new _converse.Messages(); this.messages = new _converse.Messages();
const storage = _converse.config.get('storage'); const storage = _converse.config.get('storage');
this.messages.browserStorage = new Backbone.BrowserStorage[storage]( this.messages.browserStorage = new Backbone.BrowserStorage[storage](
b64_sha1(`converse.messages${this.get('jid')}${_converse.bare_jid}`)); b64_sha1(`converse.messages${jid}${_converse.bare_jid}`));
this.messages.chatbox = this; this.messages.chatbox = this;
this.messages.on('change:upload', (message) => { this.messages.on('change:upload', (message) => {
...@@ -261,13 +263,6 @@ converse.plugins.add('converse-chatboxes', { ...@@ -261,13 +263,6 @@ converse.plugins.add('converse-chatboxes', {
}); });
}, },
addRelatedContact (contact) {
if (!_.isUndefined(contact)) {
this.contact = contact;
this.trigger('contactAdded', contact);
}
},
getDisplayName () { getDisplayName () {
return this.vcard.get('fullname') || this.get('jid'); return this.vcard.get('fullname') || this.get('jid');
}, },
...@@ -632,7 +627,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -632,7 +627,7 @@ converse.plugins.add('converse-chatboxes', {
onChatBoxesFetched (collection) { onChatBoxesFetched (collection) {
/* Show chat boxes upon receiving them from sessionStorage */ /* Show chat boxes upon receiving them from sessionStorage */
collection.each((chatbox) => { collection.each(chatbox => {
if (this.chatBoxMayBeShown(chatbox)) { if (this.chatBoxMayBeShown(chatbox)) {
chatbox.trigger('show'); chatbox.trigger('show');
} }
...@@ -846,19 +841,6 @@ converse.plugins.add('converse-chatboxes', { ...@@ -846,19 +841,6 @@ converse.plugins.add('converse-chatboxes', {
_converse.on('chatBoxesFetched', autoJoinChats); _converse.on('chatBoxesFetched', autoJoinChats);
_converse.api.waitUntil('rosterContactsFetched').then(() => {
_converse.roster.on('add', (contact) => {
/* When a new contact is added, check if we already have a
* chatbox open for it, and if so attach it to the chatbox.
*/
const chatbox = _converse.chatboxes.findWhere({'jid': contact.get('jid')});
if (chatbox) {
chatbox.addRelatedContact(contact);
}
});
});
_converse.on('addClientFeatures', () => { _converse.on('addClientFeatures', () => {
_converse.api.disco.own.features.add(Strophe.NS.MESSAGE_CORRECT); _converse.api.disco.own.features.add(Strophe.NS.MESSAGE_CORRECT);
_converse.api.disco.own.features.add(Strophe.NS.HTTPUPLOAD); _converse.api.disco.own.features.add(Strophe.NS.HTTPUPLOAD);
......
...@@ -1237,7 +1237,8 @@ _converse.initialize = function (settings, callback) { ...@@ -1237,7 +1237,8 @@ _converse.initialize = function (settings, callback) {
_converse.locales, _converse.locales,
u.interpolate(_converse.locales_url, {'locale': _converse.locale})) u.interpolate(_converse.locales_url, {'locale': _converse.locale}))
.catch(e => _converse.log(e.message, Strophe.LogLevel.FATAL)) .catch(e => _converse.log(e.message, Strophe.LogLevel.FATAL))
.finally(finishInitialization); .finally(finishInitialization)
.catch(e => _converse.log(e.message, Strophe.LogLevel.FATAL));
} }
return init_promise; return init_promise;
}; };
......
...@@ -9,6 +9,7 @@ import converse from "@converse/headless/converse-core"; ...@@ -9,6 +9,7 @@ import converse from "@converse/headless/converse-core";
const { Backbone, Promise, Strophe, $iq, $pres, b64_sha1, moment, sizzle, _ } = converse.env; const { Backbone, Promise, Strophe, $iq, $pres, b64_sha1, moment, sizzle, _ } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
converse.plugins.add('converse-roster', { converse.plugins.add('converse-roster', {
dependencies: ["converse-vcard"], dependencies: ["converse-vcard"],
...@@ -806,6 +807,12 @@ converse.plugins.add('converse-roster', { ...@@ -806,6 +807,12 @@ converse.plugins.add('converse-roster', {
/********** Event Handlers *************/ /********** Event Handlers *************/
function addRelatedContactToChatbox (chatbox, contact) {
if (!_.isUndefined(contact)) {
chatbox.contact = contact;
chatbox.trigger('contactAdded', contact);
}
}
function updateUnreadCounter (chatbox) { function updateUnreadCounter (chatbox) {
const contact = _converse.roster.findWhere({'jid': chatbox.get('jid')}); const contact = _converse.roster.findWhere({'jid': chatbox.get('jid')});
...@@ -815,10 +822,28 @@ converse.plugins.add('converse-roster', { ...@@ -815,10 +822,28 @@ converse.plugins.add('converse-roster', {
} }
_converse.api.listen.on('chatBoxesInitialized', () => { _converse.api.listen.on('chatBoxesInitialized', () => {
_converse.chatboxes.on('change:num_unread', updateUnreadCounter) _converse.chatboxes.on('change:num_unread', updateUnreadCounter)
_converse.chatboxes.on('add', async chatbox => {
await _converse.api.waitUntil('rosterContactsFetched');
addRelatedContactToChatbox(chatbox, _converse.roster.findWhere({'jid': chatbox.get('jid')}));
});
}); });
_converse.api.listen.on('beforeTearDown', _converse.unregisterPresenceHandler()); _converse.api.listen.on('beforeTearDown', _converse.unregisterPresenceHandler());
_converse.api.waitUntil('rosterContactsFetched').then(() => {
_converse.roster.on('add', (contact) => {
/* When a new contact is added, check if we already have a
* chatbox open for it, and if so attach it to the chatbox.
*/
const chatbox = _converse.chatboxes.findWhere({'jid': contact.get('jid')});
if (chatbox) {
addRelatedContactToChatbox(chatbox, contact);
}
});
});
_converse.api.listen.on('afterTearDown', () => { _converse.api.listen.on('afterTearDown', () => {
if (_converse.presences) { if (_converse.presences) {
_converse.presences.off().reset(); // Remove presences _converse.presences.off().reset(); // Remove presences
......
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