diff --git a/CHANGELOG.md b/CHANGELOG.md index 29cd7c9..6a10712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Allow users to login with either username or email * Change site_name default to Infinity One * Use site_name title on authentication pages +* Add notification count to page title ### Bug Fixes diff --git a/assets/js/notifier.js b/assets/js/notifier.js index 844f7fa..593399e 100644 --- a/assets/js/notifier.js +++ b/assets/js/notifier.js @@ -11,8 +11,9 @@ class Notifier { constructor(one_chat) { this.one_chat = one_chat; Notification.requestPermission().then(function(result) { - console.log(result); + console.log('request permissions', result); }); + this.useNewNotification = this.supportsNewNofification(); } desktop(title, body, opts = {}) { @@ -22,7 +23,7 @@ class Notifier { icon = opts.icon; } - var notification = new Notification(title, { + var notification = this.newNotification(title, { body: body, icon: icon, }); @@ -40,10 +41,33 @@ class Notifier { } } + newNotification(title, opts = {}) { + let not; + if (this.useNewNotification) { + not = new Notification(title, opts); + } else { + not = Notification(title, opts); + } + return not; + } + audio(sound) { if (debug) { console.log('notify_audio', sound) } $('audio#' + sound)[0].play() } + + supportsNewNofification() { + if (!window.Notification || !Notification.requestPermission) + return false; + + try { + new Notification(''); + } catch (e) { + if (e.name == 'TypeError') + return false; + } + return true; + } } export default Notifier diff --git a/assets/js/room_manager.js b/assets/js/room_manager.js index 308138b..cfed9ff 100644 --- a/assets/js/room_manager.js +++ b/assets/js/room_manager.js @@ -172,17 +172,36 @@ class RoomManager { } } update_burger_alert() { + let title = $('head title').text(); + console.log('update_burger_alert', title); + if($('.rooms-list li.has-alert').length > 0) { let count = 0; for (const has_unread of $('li.room-link span.unread')) { count += parseInt($(has_unread).text()); } this.set_burger_unreads(count); + console.log('set title count', count); + + let new_title; + let count_str = `(${count})`; + + if (/\(\d*\)/.test(title)) { + new_title = title.replace(/\(\d*\)/, count_str); + } else { + new_title = title + count_str; + } + console.log('.. new_title', new_title); + $('head title').text(new_title); } else { + console.log('clear title count'); this.clear_burger_unreads(); + $('head title').text(title.replace(/\(\d*\)/, "")); } + console.log('new title', $('head title').text()); } set_burger_unreads(count) { + console.log('set_burger_unreads', count); let value = '•' if (count > 0) { value = count; } let alert = `