2015-01-19 02:43:25 +01:00
|
|
|
/*global $, Whisper, Backbone, textsecure, extension*/
|
2015-09-07 23:53:43 +02:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-01-19 02:43:25 +01:00
|
|
|
*/
|
|
|
|
|
2015-01-22 05:27:42 +01:00
|
|
|
// This script should only be included in background.html
|
2015-01-19 02:43:25 +01:00
|
|
|
(function () {
|
2015-02-11 11:47:50 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
2015-09-17 08:13:17 +02:00
|
|
|
window.setUnreadCount = function(count) {
|
2015-05-26 22:28:43 +02:00
|
|
|
if (count > 0) {
|
|
|
|
extension.navigator.setBadgeText(count);
|
|
|
|
} else {
|
|
|
|
extension.navigator.setBadgeText("");
|
|
|
|
}
|
2015-09-17 08:13:17 +02:00
|
|
|
};
|
2015-05-26 22:28:43 +02:00
|
|
|
|
2015-03-17 23:06:21 +01:00
|
|
|
window.notifyConversation = function(message) {
|
2015-05-25 01:19:33 +02:00
|
|
|
var conversationId = message.get('conversationId');
|
2015-09-09 04:19:30 +02:00
|
|
|
var conversation = ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
2015-09-17 07:47:42 +02:00
|
|
|
conversation = ConversationController.create({id: conversationId});
|
2015-09-09 04:19:30 +02:00
|
|
|
conversation.fetch();
|
|
|
|
}
|
2015-09-16 03:49:41 +02:00
|
|
|
|
2015-08-27 01:10:44 +02:00
|
|
|
if (inboxOpened) {
|
2015-09-14 22:47:47 +02:00
|
|
|
conversation.trigger('newmessages');
|
2015-08-27 01:10:44 +02:00
|
|
|
extension.windows.drawAttention(inboxWindowId);
|
2015-09-16 03:49:41 +02:00
|
|
|
if (!appWindow.isMinimized()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Whisper.Notifications.isEnabled()) {
|
2015-09-09 04:19:30 +02:00
|
|
|
var sender = ConversationController.create({id: message.get('source')});
|
2015-03-17 23:06:21 +01:00
|
|
|
conversation.fetch().then(function() {
|
2015-03-20 00:17:26 +01:00
|
|
|
sender.fetch().then(function() {
|
2015-09-14 05:25:04 +02:00
|
|
|
sender.getNotificationIcon().then(function(iconUrl) {
|
|
|
|
Whisper.Notifications.add({
|
|
|
|
title : sender.getTitle(),
|
|
|
|
message : message.getNotificationText(),
|
|
|
|
iconUrl : iconUrl,
|
|
|
|
imageUrl : message.getImageUrl(),
|
|
|
|
conversationId: conversation.id
|
2015-09-10 09:46:50 +02:00
|
|
|
});
|
2015-03-20 00:17:26 +01:00
|
|
|
});
|
2015-03-17 23:06:21 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2015-08-28 00:21:25 +02:00
|
|
|
openConversation(conversation);
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-11 11:47:50 +01:00
|
|
|
/* Inbox window controller */
|
|
|
|
var inboxOpened = false;
|
2015-05-23 02:10:01 +02:00
|
|
|
var inboxWindowId = 'inbox';
|
2015-09-16 03:49:41 +02:00
|
|
|
var appWindow = null;
|
2015-05-12 23:01:45 +02:00
|
|
|
window.openInbox = function() {
|
2015-02-11 11:47:50 +01:00
|
|
|
if (inboxOpened === false) {
|
|
|
|
inboxOpened = true;
|
|
|
|
extension.windows.open({
|
2015-05-12 23:01:45 +02:00
|
|
|
id: 'inbox',
|
2015-02-11 11:47:50 +01:00
|
|
|
url: 'index.html',
|
|
|
|
type: 'panel',
|
2015-05-21 22:05:52 +02:00
|
|
|
frame: 'none',
|
2015-02-11 11:47:50 +01:00
|
|
|
focused: true,
|
2015-08-26 01:47:15 +02:00
|
|
|
width: 580,
|
2015-07-29 20:23:56 +02:00
|
|
|
height: 440,
|
|
|
|
minWidth: 230,
|
|
|
|
minHeight: 150
|
2015-02-11 11:47:50 +01:00
|
|
|
}, function (windowInfo) {
|
|
|
|
inboxWindowId = windowInfo.id;
|
2015-09-16 03:49:41 +02:00
|
|
|
appWindow = windowInfo;
|
2015-03-12 19:23:41 +01:00
|
|
|
|
2015-07-01 22:28:06 +02:00
|
|
|
windowInfo.onClosed.addListener(function () {
|
2015-08-28 00:21:25 +02:00
|
|
|
inboxOpened = false;
|
2015-09-16 03:49:41 +02:00
|
|
|
appWindow = null;
|
2015-07-01 22:28:06 +02:00
|
|
|
});
|
|
|
|
|
2015-03-12 19:23:41 +01:00
|
|
|
// close the panel if background.html is refreshed
|
2015-05-13 20:23:59 +02:00
|
|
|
extension.windows.beforeUnload(function() {
|
2015-03-12 19:23:41 +01:00
|
|
|
// TODO: reattach after reload instead of closing.
|
2015-07-01 22:28:06 +02:00
|
|
|
extension.windows.remove(inboxWindowId);
|
2015-03-12 19:23:41 +01:00
|
|
|
});
|
2015-02-11 11:47:50 +01:00
|
|
|
});
|
|
|
|
} else if (inboxOpened === true) {
|
2015-05-12 23:01:45 +02:00
|
|
|
extension.windows.focus(inboxWindowId, function (error) {
|
|
|
|
if (error) {
|
|
|
|
inboxOpened = false;
|
|
|
|
openInbox();
|
|
|
|
}
|
|
|
|
});
|
2015-01-22 05:27:42 +01:00
|
|
|
}
|
2015-05-12 23:01:45 +02:00
|
|
|
};
|
2015-05-15 22:54:29 +02:00
|
|
|
|
2015-09-05 03:33:14 +02:00
|
|
|
var open;
|
2015-09-14 05:25:04 +02:00
|
|
|
window.openConversation = function(conversation) {
|
2015-09-05 03:33:14 +02:00
|
|
|
if (inboxOpened === true) {
|
|
|
|
var appWindow = chrome.app.window.get(inboxWindowId);
|
|
|
|
appWindow.contentWindow.openConversation(conversation);
|
|
|
|
} else {
|
|
|
|
open = conversation;
|
|
|
|
}
|
2015-09-16 05:41:48 +02:00
|
|
|
openInbox();
|
2015-09-14 05:25:04 +02:00
|
|
|
};
|
2015-09-05 03:33:14 +02:00
|
|
|
window.getOpenConversation = function() {
|
|
|
|
var o = open;
|
|
|
|
open = null;
|
|
|
|
return o;
|
|
|
|
};
|
2015-01-22 05:27:42 +01:00
|
|
|
})();
|