this attempts converting id to number to sort them numerically, since "99" >
"100" while 99 < 100
This commit is contained in:
parent
03ffa7e84e
commit
9d0d6b86c8
3 changed files with 50 additions and 4 deletions
|
@ -1,9 +1,25 @@
|
||||||
import { reduce, filter, sortBy } from 'lodash'
|
import { reduce, filter, sortBy } from 'lodash'
|
||||||
import Status from '../status/status.vue'
|
import Status from '../status/status.vue'
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const sortAndFilterConversation = (conversation) => {
|
const sortAndFilterConversation = (conversation) => {
|
||||||
conversation = filter(conversation, (status) => status.type !== 'retweet')
|
conversation = filter(conversation, (status) => status.type !== 'retweet')
|
||||||
return sortBy(conversation, 'id')
|
return sortBy(conversation, sortById)
|
||||||
}
|
}
|
||||||
|
|
||||||
const conversation = {
|
const conversation = {
|
||||||
|
|
|
@ -81,7 +81,21 @@ const mergeOrAdd = (arr, obj, item) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortById = (a, b) => a.id > b.id ? -1 : 1
|
const sortById = (a, b) => {
|
||||||
|
const seqA = Number(a.id)
|
||||||
|
const seqB = Number(b.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.id > b.id ? -1 : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const sortTimeline = (timeline) => {
|
const sortTimeline = (timeline) => {
|
||||||
timeline.visibleStatuses = timeline.visibleStatuses.sort(sortById)
|
timeline.visibleStatuses = timeline.visibleStatuses.sort(sortById)
|
||||||
|
@ -239,7 +253,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
processor(status)
|
processor(status)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Keep the visible statuses sorted
|
// Keep the visible statuses sorted
|
||||||
if (timeline) {
|
if (timeline) {
|
||||||
sortTimeline(timelineObject)
|
sortTimeline(timelineObject)
|
||||||
if ((older || timelineObject.minVisibleId <= 0) && statuses.length > 0) {
|
if ((older || timelineObject.minVisibleId <= 0) && statuses.length > 0) {
|
||||||
|
|
|
@ -9,9 +9,25 @@ export const visibleTypes = store => ([
|
||||||
store.state.config.notificationVisibility.follows && 'follow'
|
store.state.config.notificationVisibility.follows && 'follow'
|
||||||
].filter(_ => _))
|
].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 => {
|
export const visibleNotificationsFromStore = store => {
|
||||||
// map is just to clone the array since sort mutates it and it causes some issues
|
// 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')
|
sortedNotifications = sortBy(sortedNotifications, 'seen')
|
||||||
return sortedNotifications.filter((notification) => visibleTypes(store).includes(notification.type))
|
return sortedNotifications.filter((notification) => visibleTypes(store).includes(notification.type))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue