From 7c4cc56ff44b61b216a7ed0deca387058de9e9c3 Mon Sep 17 00:00:00 2001 From: notfire Date: Mon, 10 Feb 2025 15:56:25 -0500 Subject: [PATCH] add the ability to have custom notification sounds for specific users --- src/i18n/en.json | 2 +- .../notification_utils/notification_utils.js | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/i18n/en.json b/src/i18n/en.json index b36bce1f..7b75fff5 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -767,7 +767,7 @@ "show_yous": "Show (You)s", "sound_on_notification": "Play a sound when you get a notification", "sound_on_notification_custom": "Custom sounds", - "sound_on_notification_custom_exp": "Put URLs to custom sounds in this box, one line for each. If you want one sound to have a different volume, put a semicolon after the link and the volume as a number between 0 and 1.", + "sound_on_notification_custom_exp": "Put URLs to custom sounds in this box, one line for each. If you want one sound to have a different volume, put a semicolon after the link and the volume as a number between 0 and 1. If you want a sound to affect a certain user, use a second semicolon and then their ID.", "sound_on_notification_volume": "Volume of the default notification sound", "stop_gifs": "Pause animated images until you hover on them", "streaming": "Automatically show new posts when scrolled to the top", diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index 6cee3ffa..f61a956d 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -136,9 +136,25 @@ export const prepareNotificationObject = (notification, i18n, store) => { if (store.getters.mergedConfig.soundOnNotif) { if (store.getters.mergedConfig.soundOnNotifCustom !== '') { + var fallback = true + var soundVol var soundList = store.getters.mergedConfig.soundOnNotifCustom.split("\n") - var randomSound = soundList[Math.floor(Math.random() * soundList.length)] - var soundVol = (randomSound.split(";").length > 1 ? randomSound.split(";")[1] : store.getters.mergedConfig.soundOnNotifVolume) + var randomSound + soundList.forEach(sound => { + // if there's more args, assume specific user tied to sound + if (sound.split(";").length > 2) { + var user = [sound.split(";")[2]] + if (user == notification.from_profile.id) { + randomSound = sound.split(";")[0] + soundVol = (sound.split(";")[1].length > 0 ? sound.split(";")[1] : store.getters.mergedConfig.soundOnNotifVolume) + fallback = false + } + } + }); + if (fallback) { + randomSound = soundList[Math.floor(Math.random() * soundList.length)] + soundVol = (randomSound.split(";").length > 1 ? randomSound.split(";")[1] : store.getters.mergedConfig.soundOnNotifVolume) + } var sound = new Audio(randomSound.split(";")[0]) sound.volume = soundVol