Commit c5383ac2 authored by JC Brand's avatar JC Brand

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.
parent 26cd567c
......@@ -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();
},
......
......@@ -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));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment