mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-05-08 17:08:57 +01:00
06ff6c3087
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
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
var Whisper = Whisper || {};
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
Whisper.ConversationListView = Backbone.View.extend({
|
|
|
|
tagName: 'ul',
|
|
id: 'conversations',
|
|
initialize: function() {
|
|
this.views = [];
|
|
this.threads = Whisper.Threads;
|
|
this.listenTo(this.threads, 'change:completed', this.render); // auto update
|
|
this.listenTo(this.threads, 'add', this.addThread);
|
|
this.listenTo(this.threads, 'reset', this.addAll);
|
|
this.listenTo(this.threads, 'all', this.render);
|
|
this.listenTo(Whisper.Messages, 'add', this.addMessage);
|
|
|
|
// Suppresses 'add' events with {reset: true} and prevents the app view
|
|
// from being re-rendered for every model. Only renders when the 'reset'
|
|
// event is triggered at the end of the fetch.
|
|
//this.messages.threads({reset: true});
|
|
Whisper.Threads.fetch({reset: true});
|
|
Whisper.Messages.fetch();
|
|
|
|
this.$el.appendTo($('#inbox'));
|
|
},
|
|
|
|
addThread: function(thread) {
|
|
this.views[thread.id] = new Whisper.ConversationView({model: thread});
|
|
this.$el.prepend(this.views[thread.id].render().el);
|
|
},
|
|
|
|
addAll: function() {
|
|
this.$el.html('');
|
|
_.each(this.threads.where({'active': true}), this.addThread, this);
|
|
},
|
|
|
|
addMessage: function(message) {
|
|
var thread = message.thread();
|
|
if (!_.has(this.views, thread.id)) {
|
|
this.addThread(thread);
|
|
}
|
|
thread.trigger('message', message);
|
|
}
|
|
});
|
|
})();
|