diff options
| author | shpuld <shp@cock.li> | 2019-01-26 17:50:41 +0200 |
|---|---|---|
| committer | shpuld <shp@cock.li> | 2019-01-26 17:50:41 +0200 |
| commit | 0ab828bb30e70e190c1b26eda658ea1d14cc129f (patch) | |
| tree | 5b6816dbc839a0cf821a6b4945fb0a81c109b0f2 /src/services/notification_utils/notification_utils.js | |
| parent | 3978aaef84cc023908155343af76983f2715cf90 (diff) | |
| parent | 8197c77f75929aad557c98a5f698159b1a6d0c90 (diff) | |
Merge develop and fix conflict
Diffstat (limited to 'src/services/notification_utils/notification_utils.js')
| -rw-r--r-- | src/services/notification_utils/notification_utils.js | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index f5ac0d47..cd8f3f9e 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -9,9 +9,25 @@ export const visibleTypes = store => ([ store.state.config.notificationVisibility.follows && 'follow' ].filter(_ => _)) +const sortById = (a, b) => { + const seqA = Number(a.action.id) + const seqB = Number(b.action.id) + const isSeqA = !Number.isNaN(seqA) + const isSeqB = !Number.isNaN(seqB) + if (isSeqA && isSeqB) { + return seqA > seqB ? -1 : 1 + } else if (isSeqA && !isSeqB) { + return 1 + } else if (!isSeqA && isSeqB) { + return -1 + } else { + return a.action.id > b.action.id ? -1 : 1 + } +} + export const visibleNotificationsFromStore = store => { - // Don't know why, but sortBy([seen, -action.id]) doesn't work. - let sortedNotifications = sortBy(notificationsFromStore(store), ({action}) => -action.id) + // map is just to clone the array since sort mutates it and it causes some issues + let sortedNotifications = notificationsFromStore(store).map(_ => _).sort(sortById) sortedNotifications = sortBy(sortedNotifications, 'seen') return sortedNotifications.filter((notification) => visibleTypes(store).includes(notification.type)) } |
