2018-12-28 19:39:54 +00:00
|
|
|
import { filter, sortBy } from 'lodash'
|
|
|
|
|
|
|
|
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',
|
|
|
|
store.state.config.notificationVisibility.follows && 'follow'
|
|
|
|
].filter(_ => _))
|
|
|
|
|
|
|
|
export const visibleNotificationsFromStore = store => {
|
2019-01-10 23:40:17 +00:00
|
|
|
// map is just to clone the array since sort mutates it and it causes some issues
|
2019-01-11 00:38:23 +00:00
|
|
|
let sortedNotifications = notificationsFromStore(store).map(_ => _).sort((a, b) => a.action.id > b.action.id ? -1 : 1)
|
2018-12-28 19:39:54 +00:00
|
|
|
sortedNotifications = sortBy(sortedNotifications, 'seen')
|
|
|
|
return sortedNotifications.filter((notification) => visibleTypes(store).includes(notification.type))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const unseenNotificationsFromStore = store =>
|
|
|
|
filter(visibleNotificationsFromStore(store), ({seen}) => !seen)
|