From 9b0e23dcc666167c2e0deb29962f4a8a56707c55 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 22 Feb 2019 23:04:20 +0100 Subject: [PATCH] Ensure new contact is attached to existing chatbox When a new contact is added, check if we already have a chatbox open for it, and if so attach it to the chatbox. --- dist/converse.js | 15 +++++++++++++++ src/converse-chatboxviews.js | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/dist/converse.js b/dist/converse.js index 69b6f35c3..40dea21a9 100644 --- a/dist/converse.js +++ b/dist/converse.js @@ -49082,6 +49082,21 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins }); /************************ 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.chatboxviews = new _converse.ChatBoxViews({ 'model': _converse.chatboxes diff --git a/src/converse-chatboxviews.js b/src/converse-chatboxviews.js index 72438b9a5..371d8c9c1 100644 --- a/src/converse-chatboxviews.js +++ b/src/converse-chatboxviews.js @@ -152,6 +152,18 @@ converse.plugins.add('converse-chatboxviews', { /************************ 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.chatboxviews = new _converse.ChatBoxViews({ 'model': _converse.chatboxes