Browse Source

chatview: trigger 'add' event when fetching messages

Otherwise they don't appear when reloading the page.

I'm not completely happy with the resulting workaround to avoid that messages
restored from sessionStorage increment the unread messages counter, but it'll
have to do for now.
JC Brand 8 năm trước cách đây
mục cha
commit
c5383ac22f
2 tập tin đã thay đổi với 21 bổ sung9 xóa
  1. 9 2
      src/converse-chatview.js
  2. 12 7
      src/converse-core.js

+ 9 - 2
src/converse-chatview.js

@@ -151,6 +151,7 @@
                 },
 
                 afterMessagesFetched: function () {
+                    this.model.set('fetching_messages', false);
                     this.insertIntoDOM();
                     this.scrollDown();
                     // We only start listening for the scroll event after
@@ -159,8 +160,9 @@
                 },
 
                 fetchMessages: function () {
+                    this.model.set('fetching_messages', true);
                     this.model.messages.fetch({
-                        'add': false,
+                        'add': true,
                         'success': this.afterMessagesFetched.bind(this),
                         'error': this.afterMessagesFetched.bind(this),
                     });
@@ -437,7 +439,12 @@
                     }
                 },
 
-                isNewMessageHidden: function() {
+                isNewMessageHidden: function () {
+                    if (this.model.get('fetching_messages')) {
+                        // We seem to be busy fetching sessionStorage archived
+                        // messages, so the message is not considered new.
+                        return false;
+                    }
                     return _converse.windowState === 'hidden' || this.model.isScrolledUp();
                 },
 

+ 12 - 7
src/converse-core.js

@@ -770,6 +770,17 @@
 
         this.RosterContact = Backbone.Model.extend({
 
+            defaults: {
+                'bookmarked': false,
+                'chat_state': undefined,
+                'chat_status': 'offline',
+                'groups': [],
+                'image': DEFAULT_IMAGE,
+                'image_type': DEFAULT_IMAGE_TYPE,
+                'num_unread': 0,
+                'status': '',
+            },
+
             initialize: function (attributes) {
                 var jid = attributes.jid;
                 var bare_jid = Strophe.getBareJidFromJid(jid).toLowerCase();
@@ -779,14 +790,8 @@
                     'id': bare_jid,
                     'jid': bare_jid,
                     'fullname': bare_jid,
-                    'chat_status': 'offline',
                     'user_id': Strophe.getNodeFromJid(jid),
-                    'resources': resource ? {'resource':0} : {},
-                    'groups': [],
-                    'image_type': DEFAULT_IMAGE_TYPE,
-                    'image': DEFAULT_IMAGE,
-                    'status': '',
-                    'num_unread': 0
+                    'resources': resource ? {resource :0} : {},
                 }, attributes));
 
                 this.on('destroy', function () { this.removeFromRoster(); }.bind(this));