Add support for deleting a conversation
Note that the conversation record is not actually destroyed, merely marked inactive, preserving the contact name, photo, etc...
This commit is contained in:
parent
7b23e24b71
commit
8257fa7478
4 changed files with 25 additions and 3 deletions
|
@ -50,6 +50,7 @@
|
||||||
<li>by <a href="http://whispersystems.org">Open Whisper Systems</a></li>
|
<li>by <a href="http://whispersystems.org">Open Whisper Systems</a></li>
|
||||||
<li><a href="http://support.whispersystems.org/">Need Help?</a></li>
|
<li><a href="http://support.whispersystems.org/">Need Help?</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<button class='destroy'>Delete this conversation</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -89,6 +89,13 @@
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.conditions = {conversationId: this.id };
|
options.conditions = {conversationId: this.id };
|
||||||
return this.messageCollection.fetch(options);
|
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});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,17 @@
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'submit .send': 'sendMessage',
|
'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) {
|
sendMessage: function(e) {
|
||||||
|
|
|
@ -33,6 +33,10 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
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) {
|
if (this.conversations.length) {
|
||||||
this.conversations.at(0).trigger('render');
|
this.conversations.at(0).trigger('render');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue