From b5a942bf0ceeffdf3383135c6d6afb6c1421f320 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 11 Apr 2021 14:02:17 +0200 Subject: [PATCH] Take account of new settings --- assets/js/components/notifications/song.js | 28 ++++++++++++++++--- .../pages/settings/sections/notifications.js | 3 ++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/assets/js/components/notifications/song.js b/assets/js/components/notifications/song.js index 125bc001..477eced1 100644 --- a/assets/js/components/notifications/song.js +++ b/assets/js/components/notifications/song.js @@ -8,23 +8,43 @@ const NotificationsSong = { /** * Song element : null by default + * + * @type {HTMLAudioElement} */ songElem: null, + /** + * Check whether notifications song is enabled or not + */ + enableSong: false, + /** * Play notification song once */ play: function(){ + if (!NotificationsSong.enableSong) + return; + //Create song element if required - if(this.songElem == null){ - this.songElem = new SongPlayer([ + if(NotificationsSong.songElem == null){ + NotificationsSong.songElem = new SongPlayer([ ComunicWeb.__config.assetsURL + "audio/notif_song.mp3", ComunicWeb.__config.assetsURL + "audio/notif_song.ogg" ]); } //Play song - this.songElem.playOnce(); + NotificationsSong.songElem.playOnce(); } -} \ No newline at end of file +} + +// Get notification settings as soon as the page is loaded +document.addEventListener("wsOpen", async () => { + try { + const settings = await SettingsInterface.getNotifications(); + NotificationsSong.enableSong = settings.allow_notifications_sound; + } catch(e) { + console.error(e); + } +}) \ No newline at end of file diff --git a/assets/js/pages/settings/sections/notifications.js b/assets/js/pages/settings/sections/notifications.js index c6d36246..deebe5b1 100644 --- a/assets/js/pages/settings/sections/notifications.js +++ b/assets/js/pages/settings/sections/notifications.js @@ -36,6 +36,9 @@ class NotificationsSettings { await SettingsInterface.setNotifications(newSettings); + // Apply new settings immediatly + NotificationsSong.enableSong = newSettings.allow_notifications_sound; + notify(tr("Successfully updated settings!"), "success") } catch(e) {