Get conversations loading through localStorage

This commit is contained in:
Riley Shaw 2015-01-16 11:40:17 -10:00 committed by lilia
parent 2cbcb28ee3
commit 7ec27f814f
3 changed files with 28 additions and 21 deletions

View file

@ -222,4 +222,7 @@
console.log('got delivery receipt for unknown message', pushMessage.source, timestamp);
});
};
extension.on('log', console.log.bind(console));
})();

View file

@ -24,31 +24,33 @@
conversation.fetch().then(function () {
new Whisper.ConversationView({ model: conversation}).render().$el.appendTo($('#conversation-container'));
});
// clean 'er up
conversationInfo = undefined;
};
var conversationInfo = {
id: '',
idPairs: {}
};
var windowId, windowMap = {};
extension.on('loadConversation', function (message) {
debugger;
if (conversationInfo.id) {
if (message.windowId === conversationInfo.id) {
loadConversation(message.conversationId);
extension.trigger('log', 'loaded page');
window.addEventListener('storage', function (e) {
extension.trigger('log', 'got storage event');
if (e.key = 'idPairs') {
windowMap = JSON.parse(e.newValue);
if (windowId) {
var conversationId = windowMap[windowId];
if (conversationId) {
loadConversation(conversationId);
}
}
} else {
conversationInfo.idPairs[message.windowId] = message.conversationId;
}
});
chrome.windows.getCurrent(function (windowInfo) {
window.document.title = conversationInfo.id = windowInfo.id;
window.document.title = windowId = windowInfo.id;
var conversationId = conversationInfo.idPairs[conversationInfo.id];
extension.trigger('log', 'got page id');
var conversationId = windowMap[windowId];
if (typeof conversationId !== 'undefined') {
loadConversation(conversationId);

View file

@ -52,11 +52,13 @@ var Whisper = Whisper || {};
width: 280,
height: 420
}, function (windowInfo) {
debugger;
extension.trigger('loadConversation', {
windowId: windowInfo.id,
conversationId: modelId
});
extension.trigger('log', 'maybe up here?');
extension.trigger('log', localStorage.getItem('idPairs'));
var idPairs = JSON.parse(localStorage.getItem('idPairs') || '{}');
idPairs[windowInfo.id] = modelId;
localStorage.setItem('idPairs', JSON.stringify(idPairs));
extension.trigger('log', 'set idPairs item');
});
this.model.collection.trigger('selected', this.view);