var notifications = (function () { var exports = {}; var notice_memory = {}; // When you start Zulip, window_has_focus should be true, but it might not be the // case after a server-initiated reload. var window_has_focus = document.hasFocus && document.hasFocus(); var supports_sound; var unread_pms_favicon = '/static/images/favicon/favicon-pms.png'; var current_favicon; var previous_favicon; var flashing = false; var notifications_api; exports.set_notification_api = function (n) { notifications_api = n; }; if (window.webkitNotifications) { notifications_api = window.webkitNotifications; } else if (window.Notification) { // Build a shim to the new notification API notifications_api = { checkPermission: function checkPermission() { if (window.Notification.permission === 'granted') { return 0; } return 2; }, requestPermission: window.Notification.requestPermission, createNotification: function createNotification(icon, title, content, tag) { var notification_object = new window.Notification(title, {icon: icon, body: content, tag: tag}); notification_object.show = function () {}; notification_object.cancel = function () { notification_object.close(); }; return notification_object; }, }; } function browser_desktop_notifications_on() { return (notifications_api && // Firefox on Ubuntu claims to do webkitNotifications but its notifications are terrible /webkit/i.test(navigator.userAgent) && // 0 is PERMISSION_ALLOWED notifications_api.checkPermission() === 0) || // window.bridge is the desktop client (window.bridge !== undefined); } function cancel_notification_object(notification_object) { // We must remove the .onclose so that it does not trigger on .cancel notification_object.onclose = function () {}; notification_object.onclick = function () {}; notification_object.cancel(); } exports.get_notifications = function () { return notice_memory; }; exports.initialize = function () { $(window).focus(function () { window_has_focus = true; _.each(notice_memory, function (notice_mem_entry) { cancel_notification_object(notice_mem_entry.obj); }); notice_memory = {}; // Update many places on the DOM to reflect unread // counts. unread_ops.process_visible(); }).blur(function () { window_has_focus = false; }); if (window.bridge !== undefined) { supports_sound = true; return; } var audio = $("