Fetch group contacts before fetching new messages

Messages must wait for sender info to arrive before rendering.

// FREEBIE
This commit is contained in:
lilia 2015-09-13 20:59:51 -07:00
parent edbf2371bf
commit 1a30d003f5
2 changed files with 26 additions and 18 deletions

View file

@ -174,21 +174,28 @@
}, },
fetchContacts: function(options) { fetchContacts: function(options) {
if (this.isPrivate()) { return new Promise(function(resolve) {
this.contactCollection.reset([this]); if (this.isPrivate()) {
} else { this.contactCollection.reset([this]);
var members = this.get('members') || []; resolve();
this.contactCollection.reset( } else {
members.map(function(number) { var promises = [];
var c = ConversationController.create({ var members = this.get('members') || [];
id : number, this.contactCollection.reset(
type : 'private' members.map(function(number) {
}); var c = ConversationController.create({
c.fetch(); id : number,
return c; type : 'private'
}.bind(this)) });
); promises.push(new Promise(function(resolve) {
} c.fetch().always(resolve);
}));
return c;
}.bind(this))
);
resolve(Promise.all(promises));
}
}.bind(this));
}, },
reload: function() { reload: function() {

View file

@ -54,7 +54,6 @@
appWindow: this.model.appWindow appWindow: this.model.appWindow
}); });
$el = view.$el; $el = view.$el;
conversation.fetchContacts();
if (conversation.messageCollection.length === 0) { if (conversation.messageCollection.length === 0) {
$el.find('.message-list').addClass('loading'); $el.find('.message-list').addClass('loading');
} }
@ -62,8 +61,10 @@
$el.prependTo(this.el); $el.prependTo(this.el);
$el.find('.message-list').trigger('reset-scroll'); $el.find('.message-list').trigger('reset-scroll');
$el.trigger('force-resize'); $el.trigger('force-resize');
conversation.fetchMessages().then(function() { conversation.fetchContacts().then(function() {
$el.find('.message-list').removeClass('loading'); conversation.fetchMessages().then(function() {
$el.find('.message-list').removeClass('loading');
});
}); });
conversation.markRead(); conversation.markRead();
} }