Backbone message storage and views

Adds Backbone-based Whisper.Messages model/collection with local storage
extension. Saves sent and received messages in Whisper.Messages instead
of message map. This will assign a unique id to the message and save it
to localStorage.

Adds Backbone-based view to popup.html
  Automatically updates itself when new messages are saved to
  Whisper.Messages db from the background page.

Added some shiny new styles, and started splitting up css into multiple
files for sanity's sake.
This commit is contained in:
lilia 2014-05-11 17:13:09 -07:00
parent 170257dafb
commit b852e68290
14 changed files with 3832 additions and 323 deletions

32
js/models/messages.js Normal file
View file

@ -0,0 +1,32 @@
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({
sender: decrypted.pushMessage.source,
group: decrypted.message.group,
body: decrypted.message.body,
type: 'incoming',
timestamp: decrypted.message.timestamp
}).save();
},
addOutgoingMessage: function(messageProto, sender) {
Whisper.Messages.add({
sender: sender,
body: messageProto.body,
type: 'outgoing',
timestamp: new Date().getTime()
}).save();
}
}))();
})()