Fetch activites by last id

This commit is contained in:
jasper 2019-02-27 17:45:08 -08:00
parent d5348c13ff
commit 9aec49bacb
2 changed files with 11 additions and 10 deletions

View file

@ -10,6 +10,7 @@ const emptyTl = (userId = 0) => ({
visibleStatusesObject: {}, visibleStatusesObject: {},
newStatusCount: 0, newStatusCount: 0,
maxId: 0, maxId: 0,
minId: 0,
minVisibleId: 0, minVisibleId: 0,
loading: false, loading: false,
followers: [], followers: [],
@ -117,11 +118,16 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
const timelineObject = state.timelines[timeline] const timelineObject = state.timelines[timeline]
const maxNew = statuses.length > 0 ? maxBy(statuses, 'id').id : 0 const maxNew = statuses.length > 0 ? maxBy(statuses, 'id').id : 0
const older = timeline && maxNew < timelineObject.maxId const minNew = statuses.length > 0 ? minBy(statuses, 'id').id : 0
const newer = timeline && maxNew > timelineObject.maxId && statuses.length > 0
const older = timeline && (minNew < timelineObject.minId || timelineObject.minId === 0) && statuses.length > 0
if (timeline && !noIdUpdate && statuses.length > 0 && !older) { if (!noIdUpdate && newer) {
timelineObject.maxId = maxNew timelineObject.maxId = maxNew
} }
if (!noIdUpdate && older) {
timelineObject.minId = minNew
}
// This makes sure that user timeline won't get data meant for other // This makes sure that user timeline won't get data meant for other
// user. I.e. opening different user profiles makes request which could // user. I.e. opening different user profiles makes request which could
@ -256,12 +262,7 @@ 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
}
}
} }
const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes }) => { const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes }) => {

View file

@ -21,7 +21,7 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false
const timelineData = rootState.statuses.timelines[camelCase(timeline)] const timelineData = rootState.statuses.timelines[camelCase(timeline)]
if (older) { if (older) {
args['until'] = until || timelineData.minVisibleId args['until'] = until || timelineData.minId
} else { } else {
args['since'] = timelineData.maxId args['since'] = timelineData.maxId
} }