diff --git a/index.html b/index.html index 1e6b45bab..7f95b7aed 100644 --- a/index.html +++ b/index.html @@ -50,6 +50,7 @@
  • by Open Whisper Systems
  • Need Help?
  • + diff --git a/js/models/conversations.js b/js/models/conversations.js index 2d2811eb9..d48608044 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -89,6 +89,13 @@ options = options || {}; options.conditions = {conversationId: this.id }; return this.messageCollection.fetch(options); + }, + + destroyMessages: function() { + var models = this.messageCollection.models; + this.messageCollection.reset([]); + _.each(models, function(message) { message.destroy(); }); + return this.save({active: false}); } }); diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 03f313c2f..a3ad0b6c5 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -14,7 +14,7 @@ * along with this program. If not, see . */ (function () { - 'use strict'; + 'use strict'; window.Whisper = window.Whisper || {}; Whisper.ConversationView = Backbone.View.extend({ @@ -39,7 +39,17 @@ events: { 'submit .send': 'sendMessage', - 'close': 'remove' + 'close': 'remove', + 'click .destroy': 'destroyMessages' + }, + + destroyMessages: function(e) { + if (confirm("Permanently delete this conversation?")) { + this.model.destroyMessages(); + this.model.collection.remove(this.model); + this.remove(); + this.model.trigger('destroy'); + } }, sendMessage: function(e) { diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index 9ed424922..407d7d409 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -32,7 +32,11 @@ collection : this.conversations }); - this.conversations.fetch({reset: true}).then(function() { + this.conversations.fetch({ reset: true }).then(function() { + this.conversations.reset( + //TODO: Add an index to support this operation at the db level + this.conversations.filter(function(c) { return c.get('active'); }) + ); if (this.conversations.length) { this.conversations.at(0).trigger('render'); }