From 4f7ff1f3cfd61b634f0f56a6bae23bf47c5fdbad Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 28 Oct 2020 13:05:39 +0100 Subject: [PATCH] headlines-view: Update to match changes to the normal chat view --- spec/notification.js | 1 + src/converse-headlines-view.js | 15 +++++++++++---- src/headless/converse-headlines.js | 5 +++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/spec/notification.js b/spec/notification.js index 5c4c2a0ee..b2cddbf1d 100644 --- a/spec/notification.js +++ b/spec/notification.js @@ -111,6 +111,7 @@ describe("Notifications", function () { .c('x', {'xmlns': 'jabber:x:oob'}) .c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18'); _converse.connection._dataRecv(mock.createRequest(stanza)); + await u.waitUntil(() => _converse.chatboxviews.keys().length); const view = _converse.chatboxviews.get('notify.example.com'); await new Promise(resolve => view.model.messages.once('rendered', resolve)); diff --git a/src/converse-headlines-view.js b/src/converse-headlines-view.js index e13dc2b30..61e89d68f 100644 --- a/src/converse-headlines-view.js +++ b/src/converse-headlines-view.js @@ -28,13 +28,18 @@ const HeadlinesBoxView = ChatBoxView.extend({ this.initDebounced(); this.model.disable_mam = true; // Don't do MAM queries for this box - this.listenTo(this.model.messages, 'add', this.renderChatHistory); + this.listenTo(this.model, 'change:hidden', m => m.get('hidden') ? this.hide() : this.show()); + this.listenTo(this.model, 'destroy', this.remove); this.listenTo(this.model, 'show', this.show); - this.listenTo(this.model, 'destroy', this.hide); - this.listenTo(this.model, 'change:minimized', this.onMinimizedChanged); this.render(); - this.renderHeading(); + + // Need to be registered after render has been called. + this.listenTo(this.model.messages, 'add', this.onMessageAdded); + this.listenTo(this.model.messages, 'remove', this.renderChatHistory); + this.listenTo(this.model.messages, 'rendered', this.maybeScrollDown); + this.listenTo(this.model.messages, 'reset', this.renderChatHistory); + await this.model.messages.fetched; this.insertIntoDOM(); this.model.maybeShow(); @@ -62,6 +67,8 @@ const HeadlinesBoxView = ChatBoxView.extend({ render(result, this.el); this.content = this.el.querySelector('.chat-content'); this.msgs_container = this.el.querySelector('.chat-content__messages'); + this.renderChatContent(); + this.renderHeading(); return this; }, diff --git a/src/headless/converse-headlines.js b/src/headless/converse-headlines.js index fcb50fc17..bb75c9ef4 100644 --- a/src/headless/converse-headlines.js +++ b/src/headless/converse-headlines.js @@ -63,9 +63,10 @@ converse.plugins.add('converse-headlines', { } }, - initialize () { - this.initMessages(); + async initialize () { this.set({'box_id': `box-${this.get('jid')}`}); + this.initMessages(); + await this.fetchMessages(); /** * Triggered once a {@link _converse.HeadlinesBox} has been created and initialized. * @event _converse#headlinesBoxInitialized