logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git
commit: 072a06fc89844a5ed2f557634b7e04c1ef63041d
parent d178a56924dfd3dec180270fa197493b3a505780
Author: Henry Jameson <me@hjkos.com>
Date:   Sun, 19 Nov 2023 16:40:30 +0200

reports visibility setting + actual filtering for desktop notifs

Diffstat:

Msrc/components/settings_modal/tabs/notifications_tab.vue15+++++++++++++++
Msrc/i18n/en.json1+
Msrc/services/notification_utils/notification_utils.js1+
Msrc/sw.js51++++++++++++++++++++++++++++++++++++++++++---------
4 files changed, 59 insertions(+), 9 deletions(-)

diff --git a/src/components/settings_modal/tabs/notifications_tab.vue b/src/components/settings_modal/tabs/notifications_tab.vue @@ -115,6 +115,21 @@ </ul> </li> <li> + <h4> {{ $t('settings.notification_visibility_follow_requests') }}</h4> + <ul class="setting-list"> + <li> + <BooleanSetting path="notificationVisibility.follow_request"> + {{ $t('settings.notification_visibility_in_column') }} + </BooleanSetting> + </li> + <li> + <BooleanSetting path="notificationNative.follow_request" > + {{ $t('settings.notification_visibility_native_notifications') }} + </BooleanSetting> + </li> + </ul> + </li> + <li> <h4> {{ $t('settings.notification_visibility_moves') }}</h4> <ul class="setting-list"> <li> diff --git 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 @@ -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 @@ -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') {