Files
Signal-Desktop/js/panel_controller.js
lilia a569e34b33 Refactor new message notification and frontend updates
Create a cleaner seperation between generating notifications
and updating frontend conversation views. The former is now
handled by `conversation.notify` while the latter is achieved
by triggering an event on the conversation model, which will
only be acted on if there are any views listening for it.

Additionally, instead of re-fetching the entire message history,
which is overkill, just add or update the new/modified message.
This will help speed up the newmessage event handler and also
help avoid unnecessary re-rendering when resolving key conflicts.

// FREEBIE
2015-11-07 14:11:13 -08:00

97 lines
2.8 KiB
JavaScript

/*global $, Whisper, Backbone, textsecure, extension*/
/*
* vim: ts=4:sw=4:expandtab
*/
// This script should only be included in background.html
(function () {
'use strict';
window.Whisper = window.Whisper || {};
window.setUnreadCount = function(count) {
if (count > 0) {
extension.navigator.setBadgeText(count);
} else {
extension.navigator.setBadgeText("");
}
};
window.isFocused = function() {
return inboxFocused;
};
window.isOpen = function() {
return inboxOpened;
};
window.drawAttention = function() {
if (inboxOpened && !inboxFocused) {
extension.windows.drawAttention(inboxWindowId);
}
};
/* Inbox window controller */
var inboxFocused = false;
var inboxOpened = false;
var inboxWindowId = 'inbox';
var appWindow = null;
window.openInbox = function() {
if (inboxOpened === false) {
inboxOpened = true;
extension.windows.open({
id: 'inbox',
url: 'index.html',
focused: true,
width: 580,
height: 440,
minWidth: 600,
minHeight: 360
}, function (windowInfo) {
inboxWindowId = windowInfo.id;
appWindow = windowInfo;
windowInfo.onClosed.addListener(function () {
inboxOpened = false;
appWindow = null;
});
appWindow.contentWindow.addEventListener('blur', function() {
inboxFocused = false;
});
appWindow.contentWindow.addEventListener('focus', function() {
inboxFocused = true;
});
// close the panel if background.html is refreshed
extension.windows.beforeUnload(function() {
// TODO: reattach after reload instead of closing.
extension.windows.remove(inboxWindowId);
});
});
} else if (inboxOpened === true) {
extension.windows.focus(inboxWindowId, function (error) {
if (error) {
inboxOpened = false;
openInbox();
}
});
}
};
var open;
window.openConversation = function(conversation) {
if (inboxOpened === true) {
var appWindow = chrome.app.window.get(inboxWindowId);
appWindow.contentWindow.openConversation(conversation);
} else {
open = conversation;
}
openInbox();
};
window.getOpenConversation = function() {
var o = open;
open = null;
return o;
};
})();