diff --git a/js/background.js b/js/background.js index df74a1824f..143b5abc3c 100644 --- a/js/background.js +++ b/js/background.js @@ -175,10 +175,13 @@ var deliveries = message.get('delivered') || 0; var conversationId = message.get('conversationId'); if (conversationId === pushMessage.source || groups.get(conversationId)) { - message.save({delivered: deliveries + 1}).then( + message.save({delivered: deliveries + 1}).then(function() { // notify frontend listeners - updateConversation.bind(window,conversationId) - ); + var conversation = ConversationController.get(conversationId); + if (conversation) { + conversation.reload(); + } + }); return; // TODO: consider keeping a list of numbers we've // successfully delivered to? diff --git a/js/panel_controller.js b/js/panel_controller.js index 65ef928770..ac7455dcbf 100644 --- a/js/panel_controller.js +++ b/js/panel_controller.js @@ -16,7 +16,6 @@ */ // This script should only be included in background.html -// Whisper.windowMap is defined in background.js (function () { 'use strict'; @@ -24,7 +23,6 @@ textsecure.protocol_wrapper.startWorker(); - var windowMap = new Whisper.Bimap('windowId', 'modelId'); var conversations = new Whisper.ConversationCollection(); window.inbox = new Whisper.ConversationCollection([], { @@ -44,6 +42,9 @@ }); window.ConversationController = { + get: function(id) { + return conversations.get(id); + }, create: function(attrs) { var conversation = conversations.add(attrs); if (conversation.get('active_at')) { @@ -91,21 +92,6 @@ } } - window.getConversationForWindow = function(windowId) { - return conversations.get(windowMap.modelIdFrom(windowId)); - }; - - window.updateConversation = function(conversationId) { - var conversation = conversations.get(conversationId); - if (conversation) { - conversation.reload(); - } - }; - - function closeConversation (windowId) { - windowMap.remove('windowId', windowId); - } - window.notifyConversation = function(message) { var conversationId = message.get('conversationId'); var conversation = conversations.add({id: conversationId}); @@ -122,21 +108,22 @@ tag: conversation.id }); notification.onclick = function() { - openInbox(); + openConversation(conversation); }; }); }); conversation.fetchMessages(); } else { - openInbox(); + conversation.reload(); + openConversation(conversation); ConversationController.updateInbox(); } }; - window.openConversation = function openConversation (modelId) { - var conversation = conversations.add({id: modelId}); - conversation.reload(); - return conversation; + function openConversation(conversation) { + openInbox(); + var appWindow = chrome.app.window.get(inboxWindowId); + appWindow.contentWindow.trigger('open', {conversation: conversation}); }; /* Inbox window controller */ @@ -159,7 +146,8 @@ inboxWindowId = windowInfo.id; windowInfo.onClosed.addListener(function () { - onWindowClosed(inboxWindowId); + inboxWindowId = 0; + inboxOpened = false; }); // close the panel if background.html is refreshed @@ -187,16 +175,4 @@ } }); }); - - // make sure windows are cleaned up on close - var onWindowClosed = function (windowId) { - if (windowMap.windowId[windowId]) { - closeConversation(windowId); - } - - if (windowId === inboxWindowId) { - inboxWindowId = 0; - inboxOpened = false; - } - }; })();