Move key change advisory content to the model

Return this content from a helper method so it can be used to populate
the last message on conversations.
This commit is contained in:
lilia 2017-01-22 20:20:53 -08:00
parent 260f50c104
commit a623f909f2
2 changed files with 16 additions and 6 deletions

View file

@ -73,6 +73,9 @@
} }
return this.get('body'); return this.get('body');
}, },
isKeyChange: function() {
return this.get('type') === 'keychange';
},
getNotificationText: function() { getNotificationText: function() {
var description = this.getDescription(); var description = this.getDescription();
if (description) { if (description) {
@ -88,6 +91,10 @@
) )
); );
} }
if (this.isKeyChange()) {
var conversation = this.getModelForKeyChange();
return i18n('keychanged', conversation.getTitle());
}
return ''; return '';
}, },
@ -145,12 +152,15 @@
}, },
getModelForKeyChange: function() { getModelForKeyChange: function() {
var id = this.get('key_changed'); var id = this.get('key_changed');
var c = ConversationController.get(id); if (!this.modelForKeyChange) {
if (!c) { var c = ConversationController.get(id);
c = ConversationController.create({ id: id, type: 'private' }); if (!c) {
c.fetch(); c = ConversationController.create({ id: id, type: 'private' });
c.fetch();
}
this.modelForKeyChange = c;
} }
return c; return this.modelForKeyChange;
}, },
isOutgoing: function() { isOutgoing: function() {
return this.get('type') === 'outgoing'; return this.get('type') === 'outgoing';

View file

@ -91,7 +91,7 @@
}, },
render_attributes: function() { render_attributes: function() {
return { return {
content: i18n('keychanged', this.conversation.getTitle()) content: this.model.getNotificationText()
}; };
}, },
verifyIdentity: function() { verifyIdentity: function() {