2020-04-25 06:04:39 +02:00
|
|
|
import { filter, sortBy, includes } from 'lodash'
|
2018-12-28 20:39:54 +01:00
|
|
|
|
|
|
|
export const notificationsFromStore = store => store.state.statuses.notifications.data
|
|
|
|
|
|
|
|
export const visibleTypes = store => ([
|
|
|
|
store.state.config.notificationVisibility.likes && 'like',
|
|
|
|
store.state.config.notificationVisibility.mentions && 'mention',
|
|
|
|
store.state.config.notificationVisibility.repeats && 'repeat',
|
2019-12-10 16:00:10 +01:00
|
|
|
store.state.config.notificationVisibility.follows && 'follow',
|
2020-04-25 06:04:39 +02:00
|
|
|
store.state.config.notificationVisibility.followRequest && 'follow_request',
|
2020-02-11 13:24:51 +01:00
|
|
|
store.state.config.notificationVisibility.moves && 'move',
|
|
|
|
store.state.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reaction'
|
2018-12-28 20:39:54 +01:00
|
|
|
].filter(_ => _))
|
|
|
|
|
2020-04-25 06:04:39 +02:00
|
|
|
const statusNotifications = ['like', 'mention', 'repeat', 'pleroma:emoji_reaction']
|
|
|
|
|
|
|
|
export const isStatusNotification = (type) => includes(statusNotifications, type)
|
|
|
|
|
2019-01-24 22:49:37 +01:00
|
|
|
const sortById = (a, b) => {
|
2019-03-14 12:55:39 +01:00
|
|
|
const seqA = Number(a.id)
|
|
|
|
const seqB = Number(b.id)
|
2019-01-24 23:39:19 +01:00
|
|
|
const isSeqA = !Number.isNaN(seqA)
|
|
|
|
const isSeqB = !Number.isNaN(seqB)
|
2019-01-24 22:49:37 +01:00
|
|
|
if (isSeqA && isSeqB) {
|
|
|
|
return seqA > seqB ? -1 : 1
|
|
|
|
} else if (isSeqA && !isSeqB) {
|
|
|
|
return 1
|
|
|
|
} else if (!isSeqA && isSeqB) {
|
|
|
|
return -1
|
|
|
|
} else {
|
2019-03-14 12:55:39 +01:00
|
|
|
return a.id > b.id ? -1 : 1
|
2019-01-24 22:49:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-14 14:28:57 +01:00
|
|
|
export const filteredNotificationsFromStore = (store, types) => {
|
2019-01-11 00:40:17 +01:00
|
|
|
// map is just to clone the array since sort mutates it and it causes some issues
|
2019-01-24 22:49:37 +01:00
|
|
|
let sortedNotifications = notificationsFromStore(store).map(_ => _).sort(sortById)
|
2018-12-28 20:39:54 +01:00
|
|
|
sortedNotifications = sortBy(sortedNotifications, 'seen')
|
2019-05-14 21:38:16 +02:00
|
|
|
return sortedNotifications.filter(
|
|
|
|
(notification) => (types || visibleTypes(store)).includes(notification.type)
|
|
|
|
)
|
2018-12-28 20:39:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const unseenNotificationsFromStore = store =>
|
2020-01-14 14:28:57 +01:00
|
|
|
filter(filteredNotificationsFromStore(store), ({ seen }) => !seen)
|