diff --git a/src/components/settings_modal/tabs/notifications_tab.vue b/src/components/settings_modal/tabs/notifications_tab.vue
index ffaa572338..a6f0cba2d3 100644
--- a/src/components/settings_modal/tabs/notifications_tab.vue
+++ b/src/components/settings_modal/tabs/notifications_tab.vue
@@ -114,6 +114,21 @@
+
+ {{ $t('settings.notification_visibility_follow_requests') }}
+
+ -
+
+ {{ $t('settings.notification_visibility_in_column') }}
+
+
+ -
+
+ {{ $t('settings.notification_visibility_native_notifications') }}
+
+
+
+
{{ $t('settings.notification_visibility_moves') }}
diff --git a/src/i18n/en.json b/src/i18n/en.json
index 658e3b8eab..40da71550a 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -564,6 +564,7 @@
"notification_visibility_in_column": "Show in notifications column/drawer",
"notification_visibility_native_notifications": "Show a native notification",
"notification_visibility_follows": "Follows",
+ "notification_visibility_follow_requests": "Follow requests",
"notification_visibility_likes": "Favorites",
"notification_visibility_mentions": "Mentions",
"notification_visibility_repeats": "Repeats",
diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js
index 342fe6eff1..cc7e681730 100644
--- a/src/services/notification_utils/notification_utils.js
+++ b/src/services/notification_utils/notification_utils.js
@@ -91,6 +91,7 @@ export const prepareNotificationObject = (notification, i18n) => {
const notifObj = {
tag: notification.id,
+ type: notification.type,
badge: cachedBadgeUrl
}
const status = notification.status
diff --git a/src/sw.js b/src/sw.js
index f5fccc6a96..469291b97a 100644
--- a/src/sw.js
+++ b/src/sw.js
@@ -15,7 +15,8 @@ const i18n = createI18n({
const state = {
lastFocused: null,
- notificationIds: new Set()
+ notificationIds: new Set(),
+ allowedNotificationTypes: null
}
function getWindowClients () {
@@ -23,15 +24,43 @@ function getWindowClients () {
.then((clientList) => clientList.filter(({ type }) => type === 'window'))
}
-const setLocale = async () => {
- const state = await localForage.getItem('vuex-lz')
- const locale = state.config.interfaceLanguage || 'en'
+const setSettings = async () => {
+ const vuexState = await localForage.getItem('vuex-lz')
+ const locale = vuexState.config.interfaceLanguage || 'en'
i18n.locale = locale
+ const notificationsNativeArray = Object.entries(vuexState.config.notificationNative)
+
+ state.allowedNotificationTypes = new Set(
+ notificationsNativeArray
+ .filter(([k, v]) => v)
+ .map(([k]) => {
+ switch (k) {
+ case 'mentions':
+ return 'mention'
+ case 'likes':
+ return 'like'
+ case 'repeats':
+ return 'repeat'
+ case 'emojiReactions':
+ return 'pleroma:emoji_reaction'
+ case 'reports':
+ return 'pleroma:report'
+ case 'followRequest':
+ return 'follow_request'
+ case 'follows':
+ return 'follow'
+ case 'polls':
+ return 'poll'
+ default:
+ return k
+ }
+ })
+ )
}
const showPushNotification = async (event) => {
const activeClients = await getWindowClients()
- await setLocale()
+ await setSettings()
// Only show push notifications if all tabs/windows are closed
if (activeClients.length === 0) {
const data = event.data.json()
@@ -43,27 +72,31 @@ const showPushNotification = async (event) => {
const res = prepareNotificationObject(parsedNotification, i18n)
- self.registration.showNotification(res.title, res)
+ if (state.allowedNotificationTypes.has(parsedNotification.type)) {
+ self.registration.showNotification(res.title, res)
+ }
}
}
self.addEventListener('push', async (event) => {
- console.log(event)
if (event.data) {
event.waitUntil(showPushNotification(event))
}
})
self.addEventListener('message', async (event) => {
+ await setSettings()
const { type, content } = event.data
if (type === 'desktopNotification') {
const { title, ...rest } = content
- const { tag } = rest
+ const { tag, type } = rest
if (state.notificationIds.has(tag)) return
state.notificationIds.add(tag)
setTimeout(() => state.notificationIds.delete(tag), 10000)
- self.registration.showNotification(title, rest)
+ if (state.allowedNotificationTypes.has(type)) {
+ self.registration.showNotification(title, rest)
+ }
}
if (type === 'desktopNotificationClose') {