Remove updateAfterMessagesFetched method

In MUCs, messages are fetched too late in order for it to be practical
to wait for messages before rendering various parts of the MUC view.

Previously there was a bug, in the sense that `messages.fetched` was
`undefined` when being `await`ed in `updateAfterMessagesFetched`.
Once this was fixed, this issue became clear.
This commit is contained in:
JC Brand 2020-10-28 13:02:12 +01:00
parent 59e216ad34
commit fbc4adff99
4 changed files with 20 additions and 23 deletions

View File

@ -80,8 +80,10 @@ export const ChatBoxView = View.extend({
this.listenTo(this.model.notifications, 'change', this.renderNotifications); this.listenTo(this.model.notifications, 'change', this.renderNotifications);
this.listenTo(this.model, 'change:show_help_messages', this.renderHelpMessages); this.listenTo(this.model, 'change:show_help_messages', this.renderHelpMessages);
await this.updateAfterMessagesFetched(); await this.model.messages.fetched;
this.insertIntoDOM();
this.model.maybeShow(); this.model.maybeShow();
this.scrollDown();
/** /**
* Triggered once the {@link _converse.ChatBoxView} has been initialized * Triggered once the {@link _converse.ChatBoxView} has been initialized
* @event _converse#chatBoxViewInitialized * @event _converse#chatBoxViewInitialized
@ -337,21 +339,6 @@ export const ChatBoxView = View.extend({
return {}; return {};
}, },
async updateAfterMessagesFetched () {
await this.model.messages.fetched;
this.renderChatContent();
this.insertIntoDOM();
this.scrollDown();
/**
* Triggered whenever a `_converse.ChatBox` instance has fetched its messages from
* `sessionStorage` but **NOT** from the server.
* @event _converse#afterMessagesFetched
* @type {_converse.ChatBoxView | _converse.ChatRoomView}
* @example _converse.api.listen.on('afterMessagesFetched', view => { ... });
*/
api.trigger('afterMessagesFetched', this.model);
},
/** /**
* Scrolls the chat down, *if* appropriate. * Scrolls the chat down, *if* appropriate.
* *

View File

@ -24,7 +24,7 @@ const HeadlinesBoxView = ChatBoxView.extend({
'keypress textarea.chat-textarea': 'onKeyDown' 'keypress textarea.chat-textarea': 'onKeyDown'
}, },
initialize () { async initialize () {
this.initDebounced(); this.initDebounced();
this.model.disable_mam = true; // Don't do MAM queries for this box this.model.disable_mam = true; // Don't do MAM queries for this box
@ -35,9 +35,10 @@ const HeadlinesBoxView = ChatBoxView.extend({
this.render(); this.render();
this.renderHeading(); this.renderHeading();
this.updateAfterMessagesFetched(); await this.model.messages.fetched;
this.insertIntoDOM().hide(); this.insertIntoDOM();
this.model.maybeShow(); this.model.maybeShow();
this.scrollDown();
/** /**
* Triggered once the {@link _converse.HeadlinesBoxView} has been initialized * Triggered once the {@link _converse.HeadlinesBoxView} has been initialized
* @event _converse#headlinesBoxViewInitialized * @event _converse#headlinesBoxViewInitialized

View File

@ -121,15 +121,14 @@ export const ChatRoomView = ChatBoxView.extend({
this.listenTo(this.model.occupants, 'change:show', this.showJoinOrLeaveNotification); this.listenTo(this.model.occupants, 'change:show', this.showJoinOrLeaveNotification);
this.listenTo(this.model.occupants, 'remove', this.onOccupantRemoved); this.listenTo(this.model.occupants, 'remove', this.onOccupantRemoved);
await this.updateAfterMessagesFetched(); this.renderChatContent();
this.insertIntoDOM();
// Register later due to await // Register later due to await
const user_settings = await _converse.api.user.settings.getModel(); const user_settings = await _converse.api.user.settings.getModel();
this.listenTo(user_settings, 'change:mucs_with_hidden_subject', this.renderHeading); this.listenTo(user_settings, 'change:mucs_with_hidden_subject', this.renderHeading);
this.onConnectionStatusChanged(); this.onConnectionStatusChanged();
this.model.maybeShow(); this.model.maybeShow();
this.scrollDown();
/** /**
* Triggered once a { @link _converse.ChatRoomView } has been opened * Triggered once a { @link _converse.ChatRoomView } has been opened
* @event _converse#chatRoomViewInitialized * @event _converse#chatRoomViewInitialized

View File

@ -356,6 +356,16 @@ converse.plugins.add('converse-chat', {
initMessages () { initMessages () {
this.messages = new this.messagesCollection(); this.messages = new this.messagesCollection();
this.messages.fetched = u.getResolveablePromise(); this.messages.fetched = u.getResolveablePromise();
this.messages.fetched.then(() => {
/**
* Triggered whenever a `_converse.ChatBox` instance has fetched its messages from
* `sessionStorage` but **NOT** from the server.
* @event _converse#afterMessagesFetched
* @type {_converse.ChatBoxView | _converse.ChatRoomView}
* @example _converse.api.listen.on('afterMessagesFetched', view => { ... });
*/
api.trigger('afterMessagesFetched', this);
});
this.messages.chatbox = this; this.messages.chatbox = this;
this.messages.browserStorage = _converse.createStore(this.getMessagesCacheKey()); this.messages.browserStorage = _converse.createStore(this.getMessagesCacheKey());
this.listenTo(this.messages, 'change:upload', message => { this.listenTo(this.messages, 'change:upload', message => {