Ver código fonte

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.
JC Brand 4 anos atrás
pai
commit
fbc4adff99

+ 3 - 16
src/converse-chatview.js

@@ -80,8 +80,10 @@ export const ChatBoxView = View.extend({
         this.listenTo(this.model.notifications, 'change', this.renderNotifications);
         this.listenTo(this.model, 'change:show_help_messages', this.renderHelpMessages);
 
-        await this.updateAfterMessagesFetched();
+        await this.model.messages.fetched;
+        this.insertIntoDOM();
         this.model.maybeShow();
+        this.scrollDown();
         /**
          * Triggered once the {@link _converse.ChatBoxView} has been initialized
          * @event _converse#chatBoxViewInitialized
@@ -337,21 +339,6 @@ export const ChatBoxView = View.extend({
         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.
      *

+ 4 - 3
src/converse-headlines-view.js

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

+ 3 - 4
src/converse-muc-views.js

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

+ 10 - 0
src/headless/converse-chat.js

@@ -356,6 +356,16 @@ converse.plugins.add('converse-chat', {
             initMessages () {
                 this.messages = new this.messagesCollection();
                 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.browserStorage = _converse.createStore(this.getMessagesCacheKey());
                 this.listenTo(this.messages, 'change:upload', message => {