From 496099bb00034e2f5d6f25a7d9e74fb8c5601d8e Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 13 Feb 2026 15:18:56 +0200 Subject: [PATCH] made it work --- src/components/notifications/notifications.js | 20 ++++++++++------ src/lib/language.js | 7 +++--- .../notification_utils/notification_utils.js | 23 ++++++++++-------- .../notification_utils.spec.js | 24 ++++++++++++------- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index cebabc812..544901ebf 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -81,15 +81,21 @@ const Notifications = { filteredNotifications() { if (this.unseenAtTop) { return [ - ...filteredNotificationsFromStore(this.$store).filter((n) => - this.shouldShowUnseen(n), - ), - ...filteredNotificationsFromStore(this.$store).filter( - (n) => !this.shouldShowUnseen(n), - ), + ...filteredNotificationsFromStore( + this.$store, + useSyncConfigStore().mergedConfig.notificationVisibility, + ).filter((n) => this.shouldShowUnseen(n)), + ...filteredNotificationsFromStore( + this.$store, + useSyncConfigStore().mergedConfig.notificationVisibility, + ).filter((n) => !this.shouldShowUnseen(n)), ] } else { - return filteredNotificationsFromStore(this.$store, this.filterMode) + return filteredNotificationsFromStore( + this.$store, + useSyncConfigStore().mergedConfig.notificationVisibility, + this.filterMode, + ) } }, unseenCountBadgeText() { diff --git a/src/lib/language.js b/src/lib/language.js index f5c9be484..68e3a0989 100644 --- a/src/lib/language.js +++ b/src/lib/language.js @@ -1,5 +1,7 @@ -import { useI18nStore } from 'src/stores/i18n.js' +import Cookies from 'js-cookie' + import { useEmojiStore } from 'src/stores/emoji.js' +import { useI18nStore } from 'src/stores/i18n.js' import { useSyncConfigStore } from 'src/stores/sync_config.js' import messages from 'src/i18n/messages' @@ -14,9 +16,6 @@ export const piniaLanguagePlugin = ({ store, options }) => { const { path, value } = args[0] if (path === 'simple.interfaceLanguage') { useI18nStore().setLanguage(value) - const value = - originalValue || useSyncConfigStore().mergedConfig.interfaceLanguage - messages.setLanguage(this.i18n, value) useEmojiStore().loadUnicodeEmojiData(value) Cookies.set( diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index 14785a685..e5baa9a20 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -16,12 +16,7 @@ let cachedBadgeUrl = null export const notificationsFromStore = (store) => store.state.notifications.data -export const visibleTypes = (store) => { - // When called from within a module we need rootGetters to access wider scope - // however when called from a component (i.e. this.$store) we already have wider scope - const rootGetters = store.rootGetters || store.getters - const { notificationVisibility } = rootGetters.mergedConfig - +const visibleTypes = (notificationVisibility) => { return [ notificationVisibility.likes && 'like', notificationVisibility.mentions && 'mention', @@ -76,11 +71,15 @@ const isMutedNotification = (notification) => { return muteFilterHits(notification.status).length > 0 } -export const maybeShowNotification = (store, notification) => { +export const maybeShowNotification = ( + store, + notificationVisibility, + notification, +) => { const rootState = store.rootState || store.state if (notification.seen) return - if (!visibleTypes(store).includes(notification.type)) return + if (!visibleTypes(notificationVisibility).includes(notification.type)) return if (notification.type === 'mention' && isMutedNotification(notification)) return @@ -91,14 +90,18 @@ export const maybeShowNotification = (store, notification) => { showDesktopNotification(rootState, notificationObject) } -export const filteredNotificationsFromStore = (store, types) => { +export const filteredNotificationsFromStore = ( + store, + notificationVisibility, + types, +) => { // map is just to clone the array since sort mutates it and it causes some issues const sortedNotifications = notificationsFromStore(store) .map((_) => _) .sort(sortById) // TODO implement sorting elsewhere and make it optional return sortedNotifications.filter((notification) => - (types || visibleTypes(store)).includes(notification.type), + (types || visibleTypes(notificationVisibility)).includes(notification.type), ) } diff --git a/test/unit/specs/services/notification_utils/notification_utils.spec.js b/test/unit/specs/services/notification_utils/notification_utils.spec.js index baafd8961..0db318e3c 100644 --- a/test/unit/specs/services/notification_utils/notification_utils.spec.js +++ b/test/unit/specs/services/notification_utils/notification_utils.spec.js @@ -1,6 +1,21 @@ +import { createTestingPinia } from '@pinia/testing' + +import { useSyncConfigStore } from 'src/stores/sync_config.js' + import * as NotificationUtils from 'src/services/notification_utils/notification_utils.js' describe('NotificationUtils', () => { + beforeEach(() => { + const store = useSyncConfigStore(createTestingPinia()) + store.mergedConfig = { + notificationVisibility: { + likes: true, + repeats: true, + mentions: false, + }, + } + }) + describe('filteredNotificationsFromStore', () => { it('should return sorted notifications with configured types', () => { const store = { @@ -25,15 +40,6 @@ describe('NotificationUtils', () => { ], }, }, - getters: { - mergedConfig: { - notificationVisibility: { - likes: true, - repeats: true, - mentions: false, - }, - }, - }, } const expected = [ {