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

View file

@ -362,26 +362,6 @@ function isRegistrationDone() {
return storage.getUnencrypted("registration_done") !== undefined;
}
function getMessageMap() {
return storage.getEncrypted("messageMap", {});
}
function storeMessage(messageObject) {
var messageMap = getMessageMap();
var conversation = messageMap[messageObject.pushMessage.source]; //TODO: Also support Group message IDs here
if (conversation === undefined) {
conversation = [];
messageMap[messageObject.pushMessage.source] = conversation;
}
conversation[conversation.length] = { message: messageObject.message.body != null && getString(messageObject.message.body),
sender: messageObject.pushMessage.source,
timestamp: messageObject.pushMessage.timestamp.div(dcodeIO.Long.fromNumber(1000)).toNumber() };
storage.putEncrypted("messageMap", messageMap);
chrome.runtime.sendMessage(conversation[conversation.length - 1]);
}
/**********************
*** NaCL Interface ***
**********************/
@ -493,7 +473,7 @@ window.textsecure.subscribeToPush = function() {
promises[i] = handleAttachment(decrypted.message.attachments[i]);
}
return Promise.all(promises).then(function() {
storeMessage(decrypted);
Whisper.Messages.addIncomingMessage(decrypted);
message_callback(decrypted);
});
})