made it work

This commit is contained in:
Henry Jameson 2026-02-13 15:18:56 +02:00
commit 496099bb00
4 changed files with 44 additions and 30 deletions

View file

@ -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() {

View file

@ -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(

View file

@ -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),
)
}

View file

@ -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 = [
{