Files
Signal-Desktop/js/models/messages.js
lilia 2601c3cc3a Rename some things to be a little more semantic
The 'sender' field actually holds the recipient for outgoing
messages. Rename that field to 'person', indicating the 2nd
party generically.

Also decouples the thread name from thread recipients at the
view layer, in preparation for group support.
2014-05-18 13:49:11 -07:00

33 lines
837 B
JavaScript

var Whisper = Whisper || {};
(function () {
'use strict';
var Message = Backbone.Model.extend();
Whisper.Messages = new (Backbone.Collection.extend({
localStorage: new Backbone.LocalStorage("Messages"),
model: Message,
comparator: 'timestamp',
addIncomingMessage: function(decrypted) {
Whisper.Messages.add({
person: decrypted.pushMessage.source,
group: decrypted.message.group,
body: decrypted.message.body,
type: 'incoming',
timestamp: decrypted.message.timestamp
}).save();
},
addOutgoingMessage: function(messageProto, recipients) {
Whisper.Messages.add({
person: recipients[0], // TODO: groups
body: messageProto.body,
type: 'outgoing',
timestamp: new Date().getTime()
}).save();
}
}))();
})()