diff --git a/src/components/settings_modal/helpers/float_setting.js b/src/components/settings_modal/helpers/float_setting.js
new file mode 100644
index 00000000..21110a56
--- /dev/null
+++ b/src/components/settings_modal/helpers/float_setting.js
@@ -0,0 +1,41 @@
+import { get, set } from 'lodash'
+import ModifiedIndicator from './modified_indicator.vue'
+export default {
+ components: {
+ ModifiedIndicator
+ },
+ props: {
+ path: String,
+ disabled: Boolean,
+ min: Number,
+ expert: [Number, String]
+ },
+ computed: {
+ pathDefault () {
+ const [firstSegment, ...rest] = this.path.split('.')
+ return [firstSegment + 'DefaultValue', ...rest].join('.')
+ },
+ state () {
+ const value = get(this.$parent, this.path)
+ if (value === undefined) {
+ return this.defaultState
+ } else {
+ return value
+ }
+ },
+ defaultState () {
+ return get(this.$parent, this.pathDefault)
+ },
+ isChanged () {
+ return this.state !== this.defaultState
+ },
+ matchesExpertLevel () {
+ return (this.expert || 0) <= this.$parent.expertLevel
+ }
+ },
+ methods: {
+ update (e) {
+ set(this.$parent, this.path, parseFloat(e.target.value))
+ }
+ }
+}
diff --git a/src/components/settings_modal/helpers/float_setting.vue b/src/components/settings_modal/helpers/float_setting.vue
new file mode 100644
index 00000000..ba16be77
--- /dev/null
+++ b/src/components/settings_modal/helpers/float_setting.vue
@@ -0,0 +1,25 @@
+
+
+
+
+ {{ ' ' }}
+
{{ $t('settings.notification_mutes') }}
{{ $t('settings.notification_blocks') }}
diff --git a/src/i18n/en.json b/src/i18n/en.json index 6b41cfb8..53606a72 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -674,6 +674,7 @@ "notification_setting_hide_if_cw": "Hide the contents of push notifications if under a Content Warning", "notification_setting_hide_notification_contents": "Hide the sender and contents of push notifications", "notification_setting_privacy": "Privacy", + "notification_setting_sounds": "Sounds", "notification_visibility": "Types of notifications to show", "notification_visibility_bites": "Bites", "notification_visibility_emoji_reactions": "Reactions", @@ -763,6 +764,10 @@ "show_page_backgrounds": "Show page-specific backgrounds, e.g. for user profiles", "show_wider_shortcuts": "Show wider gap between top panel shortcuts", "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_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", "style": { diff --git a/src/modules/config.js b/src/modules/config.js index e7764dde..cff8580b 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -109,6 +109,9 @@ export const defaultState = { virtualScrolling: undefined, // instance default sensitiveByDefault: undefined, // instance default sensitiveIfSubject: undefined, + soundOnNotif: false, + soundOnNotifVolume: 0.2, + soundOnNotifCustom: '', renderMisskeyMarkdown: undefined, renderMfmOnHover: undefined, // instance default conversationDisplay: undefined, // instance default diff --git a/src/modules/instance.js b/src/modules/instance.js index 3cc70c02..fad5175c 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -67,6 +67,9 @@ const defaultState = { virtualScrolling: true, sensitiveByDefault: false, sensitiveIfSubject: true, + soundOnNotif: false, + soundOnNotifVolume: 0.2, + soundOnNotifCustom: '', renderMisskeyMarkdown: true, renderMfmOnHover: false, conversationDisplay: 'linear', diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index f4bde1e0..6cee3ffa 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -134,5 +134,24 @@ export const prepareNotificationObject = (notification, i18n, store) => { notifObj.image = status.attachments[0].url } + if (store.getters.mergedConfig.soundOnNotif) { + if (store.getters.mergedConfig.soundOnNotifCustom !== '') { + 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 sound = new Audio(randomSound.split(";")[0]) + sound.volume = soundVol + sound.play() + } else { + var soundList = ['/static/misskey-notif.mp3'] + randomSound = soundList[Math.floor(Math.random() * soundList.length)] + + var sound = new Audio(randomSound) + sound.volume = store.getters.mergedConfig.soundOnNotifVolume + sound.play() + } + } + return notifObj } diff --git a/static/misskey-notif.mp3 b/static/misskey-notif.mp3 new file mode 100644 index 00000000..c13d1324 Binary files /dev/null and b/static/misskey-notif.mp3 differ