made it work
This commit is contained in:
parent
6967151275
commit
496099bb00
4 changed files with 44 additions and 30 deletions
|
|
@ -81,15 +81,21 @@ const Notifications = {
|
||||||
filteredNotifications() {
|
filteredNotifications() {
|
||||||
if (this.unseenAtTop) {
|
if (this.unseenAtTop) {
|
||||||
return [
|
return [
|
||||||
...filteredNotificationsFromStore(this.$store).filter((n) =>
|
...filteredNotificationsFromStore(
|
||||||
this.shouldShowUnseen(n),
|
this.$store,
|
||||||
),
|
useSyncConfigStore().mergedConfig.notificationVisibility,
|
||||||
...filteredNotificationsFromStore(this.$store).filter(
|
).filter((n) => this.shouldShowUnseen(n)),
|
||||||
(n) => !this.shouldShowUnseen(n),
|
...filteredNotificationsFromStore(
|
||||||
),
|
this.$store,
|
||||||
|
useSyncConfigStore().mergedConfig.notificationVisibility,
|
||||||
|
).filter((n) => !this.shouldShowUnseen(n)),
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
return filteredNotificationsFromStore(this.$store, this.filterMode)
|
return filteredNotificationsFromStore(
|
||||||
|
this.$store,
|
||||||
|
useSyncConfigStore().mergedConfig.notificationVisibility,
|
||||||
|
this.filterMode,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
unseenCountBadgeText() {
|
unseenCountBadgeText() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import { useI18nStore } from 'src/stores/i18n.js'
|
import Cookies from 'js-cookie'
|
||||||
|
|
||||||
import { useEmojiStore } from 'src/stores/emoji.js'
|
import { useEmojiStore } from 'src/stores/emoji.js'
|
||||||
|
import { useI18nStore } from 'src/stores/i18n.js'
|
||||||
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
||||||
|
|
||||||
import messages from 'src/i18n/messages'
|
import messages from 'src/i18n/messages'
|
||||||
|
|
@ -14,9 +16,6 @@ export const piniaLanguagePlugin = ({ store, options }) => {
|
||||||
const { path, value } = args[0]
|
const { path, value } = args[0]
|
||||||
if (path === 'simple.interfaceLanguage') {
|
if (path === 'simple.interfaceLanguage') {
|
||||||
useI18nStore().setLanguage(value)
|
useI18nStore().setLanguage(value)
|
||||||
const value =
|
|
||||||
originalValue || useSyncConfigStore().mergedConfig.interfaceLanguage
|
|
||||||
|
|
||||||
messages.setLanguage(this.i18n, value)
|
messages.setLanguage(this.i18n, value)
|
||||||
useEmojiStore().loadUnicodeEmojiData(value)
|
useEmojiStore().loadUnicodeEmojiData(value)
|
||||||
Cookies.set(
|
Cookies.set(
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,7 @@ let cachedBadgeUrl = null
|
||||||
|
|
||||||
export const notificationsFromStore = (store) => store.state.notifications.data
|
export const notificationsFromStore = (store) => store.state.notifications.data
|
||||||
|
|
||||||
export const visibleTypes = (store) => {
|
const visibleTypes = (notificationVisibility) => {
|
||||||
// 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
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
notificationVisibility.likes && 'like',
|
notificationVisibility.likes && 'like',
|
||||||
notificationVisibility.mentions && 'mention',
|
notificationVisibility.mentions && 'mention',
|
||||||
|
|
@ -76,11 +71,15 @@ const isMutedNotification = (notification) => {
|
||||||
return muteFilterHits(notification.status).length > 0
|
return muteFilterHits(notification.status).length > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export const maybeShowNotification = (store, notification) => {
|
export const maybeShowNotification = (
|
||||||
|
store,
|
||||||
|
notificationVisibility,
|
||||||
|
notification,
|
||||||
|
) => {
|
||||||
const rootState = store.rootState || store.state
|
const rootState = store.rootState || store.state
|
||||||
|
|
||||||
if (notification.seen) return
|
if (notification.seen) return
|
||||||
if (!visibleTypes(store).includes(notification.type)) return
|
if (!visibleTypes(notificationVisibility).includes(notification.type)) return
|
||||||
if (notification.type === 'mention' && isMutedNotification(notification))
|
if (notification.type === 'mention' && isMutedNotification(notification))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -91,14 +90,18 @@ export const maybeShowNotification = (store, notification) => {
|
||||||
showDesktopNotification(rootState, notificationObject)
|
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
|
// map is just to clone the array since sort mutates it and it causes some issues
|
||||||
const sortedNotifications = notificationsFromStore(store)
|
const sortedNotifications = notificationsFromStore(store)
|
||||||
.map((_) => _)
|
.map((_) => _)
|
||||||
.sort(sortById)
|
.sort(sortById)
|
||||||
// TODO implement sorting elsewhere and make it optional
|
// TODO implement sorting elsewhere and make it optional
|
||||||
return sortedNotifications.filter((notification) =>
|
return sortedNotifications.filter((notification) =>
|
||||||
(types || visibleTypes(store)).includes(notification.type),
|
(types || visibleTypes(notificationVisibility)).includes(notification.type),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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'
|
import * as NotificationUtils from 'src/services/notification_utils/notification_utils.js'
|
||||||
|
|
||||||
describe('NotificationUtils', () => {
|
describe('NotificationUtils', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
const store = useSyncConfigStore(createTestingPinia())
|
||||||
|
store.mergedConfig = {
|
||||||
|
notificationVisibility: {
|
||||||
|
likes: true,
|
||||||
|
repeats: true,
|
||||||
|
mentions: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
describe('filteredNotificationsFromStore', () => {
|
describe('filteredNotificationsFromStore', () => {
|
||||||
it('should return sorted notifications with configured types', () => {
|
it('should return sorted notifications with configured types', () => {
|
||||||
const store = {
|
const store = {
|
||||||
|
|
@ -25,15 +40,6 @@ describe('NotificationUtils', () => {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getters: {
|
|
||||||
mergedConfig: {
|
|
||||||
notificationVisibility: {
|
|
||||||
likes: true,
|
|
||||||
repeats: true,
|
|
||||||
mentions: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
const expected = [
|
const expected = [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue