From fc1736618b4e1a9f178c0ae287754c6ac1244b08 Mon Sep 17 00:00:00 2001 From: shpuld Date: Tue, 21 Nov 2017 16:12:47 +0200 Subject: attempt to recognize when holes in timeline for various reasons, clear timeline and fetch older when showing new to get rid of holes --- src/services/timeline_fetcher/timeline_fetcher.service.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/services/timeline_fetcher/timeline_fetcher.service.js') diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index 6b76eb54..a02d67d0 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -29,8 +29,12 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false args['tag'] = tag return apiService.fetchTimeline(args) - .then((statuses) => update({store, statuses, timeline, showImmediately}), - () => store.dispatch('setError', { value: true })) + .then((statuses) => { + if (!older && statuses.length >= 20) { + store.dispatch('queueFlush', { timeline: timeline, id: timelineData.maxId }) + } + update({store, statuses, timeline, showImmediately}) + }, () => store.dispatch('setError', { value: true })) } const startFetching = ({timeline = 'friends', credentials, store, userId = false, tag = false}) => { -- cgit v1.2.3-70-g09d2 From 6b773902e8dae36b2c4cf4c970fd1437cfdc13bc Mon Sep 17 00:00:00 2001 From: shpuld Date: Thu, 23 Nov 2017 13:46:37 +0200 Subject: Fix mistake in flushMarker init, make startFetching behave properly with older statuses existing. --- src/components/timeline/timeline.js | 4 ++-- src/modules/statuses.js | 22 ++++++++++++++-------- .../timeline_fetcher/timeline_fetcher.service.js | 5 ++++- 3 files changed, 20 insertions(+), 11 deletions(-) (limited to 'src/services/timeline_fetcher/timeline_fetcher.service.js') diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index 10ad4561..660a8752 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -31,7 +31,7 @@ const Timeline = { return this.timeline.newStatusCount }, newStatusCountStr () { - if (this.timeline.flushMarker > 0) { + if (this.timeline.flushMarker !== 0) { return '' } else { return ` (${this.newStatusCount})` @@ -71,7 +71,7 @@ const Timeline = { }, methods: { showNewStatuses () { - if (this.timeline.flushMarker) { + if (this.timeline.flushMarker !== 0) { this.$store.commit('clearTimeline', { timeline: this.timelineName }) this.$store.commit('queueFlush', { timeline: this.timelineName, id: 0 }) this.fetchOlderStatuses() diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 82a7eda1..18191424 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -9,7 +9,6 @@ export const defaultState = { notifications: [], favorites: new Set(), error: false, - flushMarker: 0, timelines: { mentions: { statuses: [], @@ -23,7 +22,8 @@ export const defaultState = { loading: false, followers: [], friends: [], - viewing: 'statuses' + viewing: 'statuses', + flushMarker: 0 }, public: { statuses: [], @@ -37,7 +37,8 @@ export const defaultState = { loading: false, followers: [], friends: [], - viewing: 'statuses' + viewing: 'statuses', + flushMarker: 0 }, user: { statuses: [], @@ -51,7 +52,8 @@ export const defaultState = { loading: false, followers: [], friends: [], - viewing: 'statuses' + viewing: 'statuses', + flushMarker: 0 }, publicAndExternal: { statuses: [], @@ -65,7 +67,8 @@ export const defaultState = { loading: false, followers: [], friends: [], - viewing: 'statuses' + viewing: 'statuses', + flushMarker: 0 }, friends: { statuses: [], @@ -79,7 +82,8 @@ export const defaultState = { loading: false, followers: [], friends: [], - viewing: 'statuses' + viewing: 'statuses', + flushMarker: 0 }, tag: { statuses: [], @@ -93,7 +97,8 @@ export const defaultState = { loading: false, followers: [], friends: [], - viewing: 'statuses' + viewing: 'statuses', + flushMarker: 0 } } } @@ -382,7 +387,8 @@ export const mutations = { loading: false, followers: [], friends: [], - viewing: 'statuses' + viewing: 'statuses', + flushMarker: 0 } state.timelines[timeline] = emptyTimeline diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index a02d67d0..a4a80df0 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -38,7 +38,10 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false } const startFetching = ({timeline = 'friends', credentials, store, userId = false, tag = false}) => { - fetchAndUpdate({timeline, credentials, store, showImmediately: true, userId, tag}) + const rootState = store.rootState || store.state + const timelineData = rootState.statuses.timelines[camelCase(timeline)] + const showImmediately = timelineData.visibleStatuses.length === 0 + fetchAndUpdate({timeline, credentials, store, showImmediately, userId, tag}) const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, userId, tag }) return setInterval(boundFetchAndUpdate, 10000) } -- cgit v1.2.3-70-g09d2