Refactor and remove old window mgmt code/globals

pull/749/head
lilia 10 years ago
parent 3bc64cbed5
commit e3c56a0c03

@ -175,10 +175,13 @@
var deliveries = message.get('delivered') || 0; var deliveries = message.get('delivered') || 0;
var conversationId = message.get('conversationId'); var conversationId = message.get('conversationId');
if (conversationId === pushMessage.source || groups.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 // notify frontend listeners
updateConversation.bind(window,conversationId) var conversation = ConversationController.get(conversationId);
); if (conversation) {
conversation.reload();
}
});
return; return;
// TODO: consider keeping a list of numbers we've // TODO: consider keeping a list of numbers we've
// successfully delivered to? // successfully delivered to?

@ -16,7 +16,6 @@
*/ */
// This script should only be included in background.html // This script should only be included in background.html
// Whisper.windowMap is defined in background.js
(function () { (function () {
'use strict'; 'use strict';
@ -24,7 +23,6 @@
textsecure.protocol_wrapper.startWorker(); textsecure.protocol_wrapper.startWorker();
var windowMap = new Whisper.Bimap('windowId', 'modelId');
var conversations = new Whisper.ConversationCollection(); var conversations = new Whisper.ConversationCollection();
window.inbox = new Whisper.ConversationCollection([], { window.inbox = new Whisper.ConversationCollection([], {
@ -44,6 +42,9 @@
}); });
window.ConversationController = { window.ConversationController = {
get: function(id) {
return conversations.get(id);
},
create: function(attrs) { create: function(attrs) {
var conversation = conversations.add(attrs); var conversation = conversations.add(attrs);
if (conversation.get('active_at')) { 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) { window.notifyConversation = function(message) {
var conversationId = message.get('conversationId'); var conversationId = message.get('conversationId');
var conversation = conversations.add({id: conversationId}); var conversation = conversations.add({id: conversationId});
@ -122,21 +108,22 @@
tag: conversation.id tag: conversation.id
}); });
notification.onclick = function() { notification.onclick = function() {
openInbox(); openConversation(conversation);
}; };
}); });
}); });
conversation.fetchMessages(); conversation.fetchMessages();
} else { } else {
openInbox(); conversation.reload();
openConversation(conversation);
ConversationController.updateInbox(); ConversationController.updateInbox();
} }
}; };
window.openConversation = function openConversation (modelId) { function openConversation(conversation) {
var conversation = conversations.add({id: modelId}); openInbox();
conversation.reload(); var appWindow = chrome.app.window.get(inboxWindowId);
return conversation; appWindow.contentWindow.trigger('open', {conversation: conversation});
}; };
/* Inbox window controller */ /* Inbox window controller */
@ -159,7 +146,8 @@
inboxWindowId = windowInfo.id; inboxWindowId = windowInfo.id;
windowInfo.onClosed.addListener(function () { windowInfo.onClosed.addListener(function () {
onWindowClosed(inboxWindowId); inboxWindowId = 0;
inboxOpened = false;
}); });
// close the panel if background.html is refreshed // 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;
}
};
})(); })();

Loading…
Cancel
Save