From fc1736618b4e1a9f178c0ae287754c6ac1244b08 Mon Sep 17 00:00:00 2001 From: shpuld Date: Tue, 21 Nov 2017 16:12:47 +0200 Subject: [PATCH 1/3] attempt to recognize when holes in timeline for various reasons, clear timeline and fetch older when showing new to get rid of holes --- src/components/timeline/timeline.js | 17 +++++++++++++++-- src/components/timeline/timeline.vue | 2 +- src/modules/statuses.js | 7 +++++++ src/services/api/api.service.js | 2 ++ .../timeline_fetcher.service.js | 8 ++++++-- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index be0aefc1f3..9ef8406b7a 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -29,6 +29,13 @@ const Timeline = { }, newStatusCount () { return this.timeline.newStatusCount + }, + newStatusCountStr () { + if (this.timeline.flushMarker) { + return '' + } else { + return ` (${this.newStatusCount})` + } } }, components: { @@ -64,8 +71,14 @@ const Timeline = { }, methods: { showNewStatuses () { - this.$store.commit('showNewStatuses', { timeline: this.timelineName }) - this.paused = false + if (this.timeline.flushMarker) { + this.$store.commit('clearTimeline', { timeline: this.timelineName }) + this.$store.commit('queueFlush', { timeline: this.timelineName, id: 0 }) + this.fetchOlderStatuses() + } else { + this.$store.commit('showNewStatuses', { timeline: this.timelineName }) + this.paused = false + } }, fetchOlderStatuses () { const store = this.$store diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue index 0e2ed92c42..365c823634 100644 --- a/src/components/timeline/timeline.vue +++ b/src/components/timeline/timeline.vue @@ -5,7 +5,7 @@ {{title}}
{{$t('timeline.error_fetching')}} diff --git a/src/modules/statuses.js b/src/modules/statuses.js index d954b02378..82a7eda176 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -9,6 +9,7 @@ export const defaultState = { notifications: [], favorites: new Set(), error: false, + flushMarker: 0, timelines: { mentions: { statuses: [], @@ -422,6 +423,9 @@ export const mutations = { each(notifications, (notification) => { notification.seen = true }) + }, + queueFlush (state, { timeline, id }) { + state.timelines[timeline].flushMarker = id } } @@ -458,6 +462,9 @@ const statuses = { // Optimistic retweeting... commit('setRetweeted', { status, value: true }) apiService.retweet({ id: status.id, credentials: rootState.users.currentUser.credentials }) + }, + queueFlush ({ rootState, commit }, { timeline, id }) { + commit('queueFlush', { timeline, id }) } }, mutations diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 5de0a457b9..fa95b870b4 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -281,6 +281,8 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use url += `/${tag}.json` } + params.push(['count', 20]) + const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') url += `?${queryString}` diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index 6b76eb5466..a02d67d034 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}) => { From 912be5aed9c8616d4c5772617ab4eef9a50d9061 Mon Sep 17 00:00:00 2001 From: shpuld Date: Wed, 22 Nov 2017 00:47:20 +0200 Subject: [PATCH 2/3] Make the timeline button use the correct func for its text. --- src/components/timeline/timeline.js | 2 +- src/components/timeline/timeline.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index 9ef8406b7a..10ad4561fa 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) { + if (this.timeline.flushMarker > 0) { return '' } else { return ` (${this.newStatusCount})` diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue index 365c823634..9d2e1ea1fa 100644 --- a/src/components/timeline/timeline.vue +++ b/src/components/timeline/timeline.vue @@ -5,7 +5,7 @@ {{title}}
{{$t('timeline.error_fetching')}} From 6b773902e8dae36b2c4cf4c970fd1437cfdc13bc Mon Sep 17 00:00:00 2001 From: shpuld Date: Thu, 23 Nov 2017 13:46:37 +0200 Subject: [PATCH 3/3] 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.service.js | 5 ++++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index 10ad4561fa..660a87527c 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 82a7eda176..181914246e 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 a02d67d034..a4a80df070 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) }