From 9d0d6b86c83a4fad4038077a65149f0f3677fb82 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 25 Jan 2019 00:49:37 +0300 Subject: this attempts converting id to number to sort them numerically, since "99" > "100" while 99 < 100 --- src/services/notification_utils/notification_utils.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/services/notification_utils/notification_utils.js') diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index c3879677..4a59bef2 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 => { // map is just to clone the array since sort mutates it and it causes some issues - let sortedNotifications = notificationsFromStore(store).map(_ => _).sort((a, b) => a.action.id > b.action.id ? -1 : 1) + let sortedNotifications = notificationsFromStore(store).map(_ => _).sort(sortById) sortedNotifications = sortBy(sortedNotifications, 'seen') return sortedNotifications.filter((notification) => visibleTypes(store).includes(notification.type)) } -- cgit v1.2.3-70-g09d2