const render_compose_notification = require('../templates/compose_notification.hbs'); const render_notification = require('../templates/notification.hbs'); const settings_config = require("./settings_config"); const notice_memory = new Map(); // When you start Zulip, window_has_focus should be true, but it might not be the // case after a server-initiated reload. let window_has_focus = document.hasFocus && document.hasFocus(); let supports_sound; const unread_pms_favicon = '/static/images/favicon/favicon-pms.png'; let current_favicon; let previous_favicon; let flashing = false; let 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) { const 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 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; }; function get_audio_file_path(audio_element, audio_file_without_extension) { if (audio_element.canPlayType('audio/ogg; codecs="vorbis"')) { return audio_file_without_extension + ".ogg"; } return audio_file_without_extension + ".mp3"; } exports.initialize = function () { $(window).focus(function () { window_has_focus = true; for (const notice_mem_entry of notice_memory.values()) { cancel_notification_object(notice_mem_entry.obj); } notice_memory.clear(); // Update many places on the DOM to reflect unread // counts. unread_ops.process_visible(); }).blur(function () { window_has_focus = false; }); const audio = $("