logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git
commit: c25170d7d9cb35d7209a63628905136e5fcab80a
parent a5f09b726307367c31c0efdf365eb9b02a852eb5
Author: Henry Jameson <me@hjkos.com>
Date:   Wed, 22 Nov 2023 21:56:48 +0200

fix tests and make utils consistent in where they pull configuration from

Diffstat:

Msrc/services/notification_utils/notification_utils.js41++++++++++++++++++++++++-----------------
Mtest/unit/specs/services/notification_utils/notification_utils.spec.js12++++++++----
2 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js @@ -10,18 +10,21 @@ let cachedBadgeUrl = null export const notificationsFromStore = store => store.state.notifications.data export const visibleTypes = store => { - const rootState = store.rootState || store.state + // 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 ([ - rootState.config.notificationVisibility.likes && 'like', - rootState.config.notificationVisibility.mentions && 'mention', - rootState.config.notificationVisibility.repeats && 'repeat', - rootState.config.notificationVisibility.follows && 'follow', - rootState.config.notificationVisibility.followRequest && 'follow_request', - rootState.config.notificationVisibility.moves && 'move', - rootState.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reaction', - rootState.config.notificationVisibility.reports && 'pleroma:report', - rootState.config.notificationVisibility.polls && 'poll' + notificationVisibility.likes && 'like', + notificationVisibility.mentions && 'mention', + notificationVisibility.repeats && 'repeat', + notificationVisibility.follows && 'follow', + notificationVisibility.followRequest && 'follow_request', + notificationVisibility.moves && 'move', + notificationVisibility.emojiReactions && 'pleroma:emoji_reaction', + notificationVisibility.reports && 'pleroma:report', + notificationVisibility.polls && 'poll' ].filter(_ => _)) } @@ -54,17 +57,19 @@ const sortById = (a, b) => { const isMutedNotification = (store, notification) => { if (!notification.status) return - return notification.status.muted || muteWordHits(notification.status, store.rootGetters.mergedConfig.muteWords).length > 0 + const rootGetters = store.rootGetters || store.getters + return notification.status.muted || muteWordHits(notification.status, rootGetters.mergedConfig.muteWords).length > 0 } export const maybeShowNotification = (store, notification) => { const rootState = store.rootState || store.state + const rootGetters = store.rootGetters || store.getters if (notification.seen) return if (!visibleTypes(store).includes(notification.type)) return if (notification.type === 'mention' && isMutedNotification(store, notification)) return - const notificationObject = prepareNotificationObject(notification, store.rootGetters.i18n) + const notificationObject = prepareNotificationObject(notification, rootGetters.i18n) showDesktopNotification(rootState, notificationObject) } @@ -78,7 +83,8 @@ export const filteredNotificationsFromStore = (store, types) => { } export const unseenNotificationsFromStore = store => { - const ignoreInactionableSeen = store.getters.mergedConfig.ignoreInactionableSeen + const rootGetters = store.rootGetters || store.getters + const ignoreInactionableSeen = rootGetters.mergedConfig.ignoreInactionableSeen return filteredNotificationsFromStore(store).filter(({ seen, type }) => { if (!ignoreInactionableSeen) return !seen @@ -149,15 +155,16 @@ export const prepareNotificationObject = (notification, i18n) => { } export const countExtraNotifications = (store) => { - const mergedConfig = store.getters.mergedConfig + const rootGetters = store.rootGetters || store.getters + const mergedConfig = rootGetters.mergedConfig if (!mergedConfig.showExtraNotifications) { return 0 } return [ - mergedConfig.showChatsInExtraNotifications ? store.getters.unreadChatCount : 0, - mergedConfig.showAnnouncementsInExtraNotifications ? store.getters.unreadAnnouncementCount : 0, - mergedConfig.showFollowRequestsInExtraNotifications ? store.getters.followRequestCount : 0 + mergedConfig.showChatsInExtraNotifications ? rootGetters.unreadChatCount : 0, + mergedConfig.showAnnouncementsInExtraNotifications ? rootGetters.unreadAnnouncementCount : 0, + mergedConfig.showFollowRequestsInExtraNotifications ? rootGetters.followRequestCount : 0 ].reduce((a, c) => a + c, 0) } diff --git a/test/unit/specs/services/notification_utils/notification_utils.spec.js b/test/unit/specs/services/notification_utils/notification_utils.spec.js @@ -23,8 +23,10 @@ describe('NotificationUtils', () => { type: 'repeat' } ] - }, - config: { + } + }, + getters: { + mergedConfig: { notificationVisibility: { likes: true, repeats: true, @@ -66,8 +68,10 @@ describe('NotificationUtils', () => { seen: true } ] - }, - config: { + } + }, + getters: { + mergedConfig: { notificationVisibility: { likes: true, repeats: true,