aboutsummaryrefslogtreecommitdiff
path: root/src/services/notification_utils/notification_utils.js
blob: f5ac0d4766a8a9e3e1b92c4e5bba9967fff8a357 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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 => {
  // Don't know why, but sortBy([seen, -action.id]) doesn't work.
  let sortedNotifications = sortBy(notificationsFromStore(store), ({action}) => -action.id)
  sortedNotifications = sortBy(sortedNotifications, 'seen')
  return sortedNotifications.filter((notification) => visibleTypes(store).includes(notification.type))
}

export const unseenNotificationsFromStore = store =>
  filter(visibleNotificationsFromStore(store), ({seen}) => !seen)