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