Let thread collection double as contacts db

When a thread is 'destroyed' from the UI we delete its messages and mark
the thread as inactive, (in other words, keep it around as contact info).
Additionally, we only load active threads when initializing the UI, and
reactivate threads when new messages are added to them.

Conflicts:
	js/models/messages.js
	js/models/threads.js
	js/views/conversations/show.js
This commit is contained in:
lilia 2014-06-07 18:00:51 -07:00
parent c6b79236d9
commit 06ff6c3087
4 changed files with 21 additions and 9 deletions

View file

@ -46,10 +46,11 @@ var Whisper = Whisper || {};
m.save();
if (decrypted.message.timestamp > thread.get('timestamp')) {
thread.set({timestamp: decrypted.message.timestamp});
thread.set({unreadCount: thread.get('unreadCount') + 1});
thread.save();
thread.set('timestamp', decrypted.message.timestamp);
}
thread.set('unreadCount', thread.get('unreadCount') + 1);
thread.set('active', true);
thread.save();
return m;
},
@ -61,6 +62,11 @@ var Whisper = Whisper || {};
timestamp: new Date().getTime()
});
m.save();
thread.set('timestamp', new Date().getTime());
thread.set('unreadCount', 0);
thread.set('active', true);
thread.save();
return m;
}
}))();

View file

@ -1,4 +1,4 @@
/* vim: ts=2:sw=2:expandtab: */
// vim: ts=2:sw=2:expandtab:
var Whisper = Whisper || {};
(function () {
@ -9,7 +9,8 @@ var Whisper = Whisper || {};
return {
image: '/images/default.png',
unreadCount: 0,
timestamp: new Date().getTime()
timestamp: new Date().getTime(),
active: true
};
},

View file

@ -33,11 +33,15 @@ var Whisper = Whisper || {};
addAll: function() {
this.$el.html('');
this.threads.each(this.addThread, this);
_.each(this.threads.where({'active': true}), this.addThread, this);
},
addMessage: function(message) {
message.thread().trigger('message', message);
var thread = message.thread();
if (!_.has(this.views, thread.id)) {
this.addThread(thread);
}
thread.trigger('message', message);
}
});
})();

View file

@ -12,9 +12,10 @@ var Whisper = Whisper || {};
},
destroy: function() {
this.model.messages().each(function(message) { message.destroy(); });
this.model.destroy();
this.model.set('active', false);
this.model.save();
this.model.trigger('destroy');
}
});