mirror of https://github.com/zulip/zulip.git
Send notifications over the JS→C++ bridge if it exists.
When determining if desktop notifications are enabled, we can check whether there is a "window.bridge" element. Now when it comes time to actually send out notifications, we can just test again for the existence of "window.bridge" and if so, shunt the data over it. (imported from commit 8104c91ea9da7bc485c86a3c21edc88905d2f47b)
This commit is contained in:
parent
3ee4161ace
commit
c5d3ca0247
|
@ -13,7 +13,9 @@ function browser_desktop_notifications_on () {
|
|||
// Firefox on Ubuntu claims to do webkitNotifications but its notifications are terrible
|
||||
$.browser.webkit &&
|
||||
// 0 is PERMISSION_ALLOWED
|
||||
window.webkitNotifications.checkPermission() === 0);
|
||||
window.webkitNotifications.checkPermission() === 0) ||
|
||||
// window.bridge is the desktop client
|
||||
(window.bridge !== undefined);
|
||||
}
|
||||
|
||||
exports.initialize = function () {
|
||||
|
@ -132,7 +134,7 @@ function process_desktop_notification(message) {
|
|||
content += " [...]";
|
||||
}
|
||||
|
||||
if (notice_memory[key] !== undefined) {
|
||||
if (window.bridge === undefined && notice_memory[key] !== undefined) {
|
||||
msg_count = notice_memory[key].msg_count + 1;
|
||||
title = msg_count + " messages from " + title;
|
||||
notification_object = notice_memory[key].obj;
|
||||
|
@ -156,20 +158,25 @@ function process_desktop_notification(message) {
|
|||
title += " (to " + message.stream + " > " + message.subject + ")";
|
||||
}
|
||||
|
||||
notice_memory[key] = {
|
||||
obj: window.webkitNotifications.createNotification(
|
||||
gravatar_url(message), title, content),
|
||||
msg_count: msg_count
|
||||
};
|
||||
notification_object = notice_memory[key].obj;
|
||||
notification_object.onclick = function () {
|
||||
notification_object.cancel();
|
||||
window.focus();
|
||||
};
|
||||
notification_object.onclose = function () {
|
||||
delete notice_memory[key];
|
||||
};
|
||||
notification_object.show();
|
||||
if (window.bridge === undefined) {
|
||||
notice_memory[key] = {
|
||||
obj: window.webkitNotifications.createNotification(
|
||||
gravatar_url(message), title, content),
|
||||
msg_count: msg_count
|
||||
};
|
||||
notification_object = notice_memory[key].obj;
|
||||
notification_object.onclick = function () {
|
||||
notification_object.cancel();
|
||||
window.focus();
|
||||
};
|
||||
notification_object.onclose = function () {
|
||||
delete notice_memory[key];
|
||||
};
|
||||
notification_object.show();
|
||||
} else {
|
||||
// Shunt the message along to the desktop client
|
||||
window.bridge.notify({title: title, content: content});
|
||||
}
|
||||
}
|
||||
|
||||
exports.speaking_at_me = function (message) {
|
||||
|
|
Loading…
Reference in New Issue