I broke timelines again, fixed now again (hopefully).

This commit is contained in:
shpuld 2018-04-14 22:13:28 +03:00
parent 3488141fdd
commit e88bb1a23e
1 changed files with 11 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, max, min, isArray } from 'lodash' import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash'
import apiService from '../services/api/api.service.js' import apiService from '../services/api/api.service.js'
// import parse from '../services/status_parser/status_parser.js' // import parse from '../services/status_parser/status_parser.js'
@ -106,6 +106,7 @@ const mergeOrAdd = (arr, obj, item) => {
const sortTimeline = (timeline) => { const sortTimeline = (timeline) => {
timeline.visibleStatuses = sortBy(timeline.visibleStatuses, ({id}) => -id) timeline.visibleStatuses = sortBy(timeline.visibleStatuses, ({id}) => -id)
timeline.statuses = sortBy(timeline.statuses, ({id}) => -id) timeline.statuses = sortBy(timeline.statuses, ({id}) => -id)
timeline.minVisibleId = (last(timeline.visibleStatuses) || {}).id
return timeline return timeline
} }
@ -119,12 +120,11 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
const allStatusesObject = state.allStatusesObject const allStatusesObject = state.allStatusesObject
const timelineObject = state.timelines[timeline] const timelineObject = state.timelines[timeline]
if (timeline && !noIdUpdate && statuses.length > 0) { const maxNew = statuses.length > 0 ? maxBy(statuses, 'id').id : 0
timelineObject.maxId = max([maxBy(statuses, 'id').id, timelineObject.maxId]) const older = maxNew < timelineObject.maxId
timelineObject.minVisibleId = min([minBy(statuses, 'id').id, timelineObject.minVisibleId])
if (timelineObject.minVisibleId <= 0) { if (timeline && !noIdUpdate && statuses.length > 0 && !older) {
timelineObject.minVisibleId = minBy(statuses, 'id').id timelineObject.maxId = maxNew
}
} }
const addStatus = (status, showImmediately, addToTimeline = true) => { const addStatus = (status, showImmediately, addToTimeline = true) => {
@ -289,6 +289,9 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
// 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) {
timelineObject.minVisibleId = minBy(statuses, 'id').id
}
} }
} }
@ -299,6 +302,7 @@ export const mutations = {
oldTimeline.newStatusCount = 0 oldTimeline.newStatusCount = 0
oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50) oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50)
oldTimeline.minVisibleId = last(oldTimeline.visibleStatuses).id
oldTimeline.visibleStatusesObject = {} oldTimeline.visibleStatusesObject = {}
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status }) each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
}, },