Fetch all conversations on startup of app, not on inbox load (#1437)
* Fetch all conversations on startup of app, not on inbox load A recent change to fetch conversations less didn't take into account all that can happen in the app without the inbox loaded. That only happens when the window is shown, and messages can come in with the app in the background. In that case, the conversation wouldn't have been loaded from the database, but would be saved to the database anyway, losing data. This change fetches all conversations as soon as the the data store is ready for a fetch. It also introduces failsafe throws to ensure that synchronous ConversationController accesses don't happen until the initial fetch is complete. A new getUnsafe() method was required to account for some of the model setup that happens during that initial conversation fetch. Fixes #1428 FREEBIE * Fix tests: ConversationController.load() required before get() FREEBIE
This commit is contained in:
parent
8caecd50cd
commit
4cba16cb61
6 changed files with 82 additions and 24 deletions
|
@ -4,11 +4,13 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
function clear(done) {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
return messages.fetch().then(function() {
|
||||
messages.destroyAll();
|
||||
done();
|
||||
function deleteAllMessages() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
return messages.fetch().then(function() {
|
||||
messages.destroyAll();
|
||||
resolve();
|
||||
}, reject);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -21,9 +23,18 @@
|
|||
var attachment = { data: 'datasaurus',
|
||||
contentType: 'plain/text' };
|
||||
|
||||
var source = '+14155555555';
|
||||
|
||||
describe('MessageCollection', function() {
|
||||
before(clear);
|
||||
after(clear);
|
||||
before(function() {
|
||||
return Promise.all([
|
||||
deleteAllMessages(),
|
||||
ConversationController.load()
|
||||
]);
|
||||
});
|
||||
after(function() {
|
||||
return deleteAllMessages();
|
||||
});
|
||||
|
||||
it('has no image url', function() {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
|
@ -49,7 +60,10 @@
|
|||
|
||||
it('gets incoming contact', function() {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
var message = messages.add({ type: 'incoming' });
|
||||
var message = messages.add({
|
||||
type: 'incoming',
|
||||
source: source
|
||||
});
|
||||
message.getContact();
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue