fix tests and make utils consistent in where they pull configuration from
This commit is contained in:
parent
a5f09b7263
commit
c25170d7d9
|
@ -10,18 +10,21 @@ let cachedBadgeUrl = null
|
||||||
export const notificationsFromStore = store => store.state.notifications.data
|
export const notificationsFromStore = store => store.state.notifications.data
|
||||||
|
|
||||||
export const visibleTypes = store => {
|
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 ([
|
return ([
|
||||||
rootState.config.notificationVisibility.likes && 'like',
|
notificationVisibility.likes && 'like',
|
||||||
rootState.config.notificationVisibility.mentions && 'mention',
|
notificationVisibility.mentions && 'mention',
|
||||||
rootState.config.notificationVisibility.repeats && 'repeat',
|
notificationVisibility.repeats && 'repeat',
|
||||||
rootState.config.notificationVisibility.follows && 'follow',
|
notificationVisibility.follows && 'follow',
|
||||||
rootState.config.notificationVisibility.followRequest && 'follow_request',
|
notificationVisibility.followRequest && 'follow_request',
|
||||||
rootState.config.notificationVisibility.moves && 'move',
|
notificationVisibility.moves && 'move',
|
||||||
rootState.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reaction',
|
notificationVisibility.emojiReactions && 'pleroma:emoji_reaction',
|
||||||
rootState.config.notificationVisibility.reports && 'pleroma:report',
|
notificationVisibility.reports && 'pleroma:report',
|
||||||
rootState.config.notificationVisibility.polls && 'poll'
|
notificationVisibility.polls && 'poll'
|
||||||
].filter(_ => _))
|
].filter(_ => _))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,17 +57,19 @@ const sortById = (a, b) => {
|
||||||
|
|
||||||
const isMutedNotification = (store, notification) => {
|
const isMutedNotification = (store, notification) => {
|
||||||
if (!notification.status) return
|
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) => {
|
export const maybeShowNotification = (store, notification) => {
|
||||||
const rootState = store.rootState || store.state
|
const rootState = store.rootState || store.state
|
||||||
|
const rootGetters = store.rootGetters || store.getters
|
||||||
|
|
||||||
if (notification.seen) return
|
if (notification.seen) return
|
||||||
if (!visibleTypes(store).includes(notification.type)) return
|
if (!visibleTypes(store).includes(notification.type)) return
|
||||||
if (notification.type === 'mention' && isMutedNotification(store, notification)) 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)
|
showDesktopNotification(rootState, notificationObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +83,8 @@ export const filteredNotificationsFromStore = (store, types) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const unseenNotificationsFromStore = store => {
|
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 }) => {
|
return filteredNotificationsFromStore(store).filter(({ seen, type }) => {
|
||||||
if (!ignoreInactionableSeen) return !seen
|
if (!ignoreInactionableSeen) return !seen
|
||||||
|
@ -149,15 +155,16 @@ export const prepareNotificationObject = (notification, i18n) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const countExtraNotifications = (store) => {
|
export const countExtraNotifications = (store) => {
|
||||||
const mergedConfig = store.getters.mergedConfig
|
const rootGetters = store.rootGetters || store.getters
|
||||||
|
const mergedConfig = rootGetters.mergedConfig
|
||||||
|
|
||||||
if (!mergedConfig.showExtraNotifications) {
|
if (!mergedConfig.showExtraNotifications) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
mergedConfig.showChatsInExtraNotifications ? store.getters.unreadChatCount : 0,
|
mergedConfig.showChatsInExtraNotifications ? rootGetters.unreadChatCount : 0,
|
||||||
mergedConfig.showAnnouncementsInExtraNotifications ? store.getters.unreadAnnouncementCount : 0,
|
mergedConfig.showAnnouncementsInExtraNotifications ? rootGetters.unreadAnnouncementCount : 0,
|
||||||
mergedConfig.showFollowRequestsInExtraNotifications ? store.getters.followRequestCount : 0
|
mergedConfig.showFollowRequestsInExtraNotifications ? rootGetters.followRequestCount : 0
|
||||||
].reduce((a, c) => a + c, 0)
|
].reduce((a, c) => a + c, 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,10 @@ describe('NotificationUtils', () => {
|
||||||
type: 'repeat'
|
type: 'repeat'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
config: {
|
},
|
||||||
|
getters: {
|
||||||
|
mergedConfig: {
|
||||||
notificationVisibility: {
|
notificationVisibility: {
|
||||||
likes: true,
|
likes: true,
|
||||||
repeats: true,
|
repeats: true,
|
||||||
|
@ -66,8 +68,10 @@ describe('NotificationUtils', () => {
|
||||||
seen: true
|
seen: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
config: {
|
},
|
||||||
|
getters: {
|
||||||
|
mergedConfig: {
|
||||||
notificationVisibility: {
|
notificationVisibility: {
|
||||||
likes: true,
|
likes: true,
|
||||||
repeats: true,
|
repeats: true,
|
||||||
|
|
Loading…
Reference in New Issue