From 54d3b0cd7e39341f5db5804960407d3f1d0cebe8 Mon Sep 17 00:00:00 2001 From: eal Date: Sun, 19 Nov 2017 17:41:50 +0200 Subject: [PATCH] Use common method for fetching group and tag timeline. --- src/components/tag_timeline/tag_timeline.js | 4 ++-- src/components/timeline/timeline.js | 5 +++-- src/services/api/api.service.js | 6 +++--- .../timeline_fetcher/timeline_fetcher.service.js | 10 +++++----- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/tag_timeline/tag_timeline.js b/src/components/tag_timeline/tag_timeline.js index 43de4f49..89b123b0 100644 --- a/src/components/tag_timeline/tag_timeline.js +++ b/src/components/tag_timeline/tag_timeline.js @@ -3,7 +3,7 @@ import Timeline from '../timeline/timeline.vue' const TagTimeline = { created () { this.$store.commit('clearTimeline', { timeline: 'tag' }) - this.$store.dispatch('startFetching', { 'tag': this.tag }) + this.$store.dispatch('startFetching', ['identifier', this.tag]) }, components: { Timeline @@ -15,7 +15,7 @@ const TagTimeline = { watch: { tag () { this.$store.commit('clearTimeline', { timeline: 'tag' }) - this.$store.dispatch('startFetching', { 'tag': this.tag }) + this.$store.dispatch('startFetching', ['identifier', this.tag]) } }, destroyed () { diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index 613b8a34..3169e355 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -9,6 +9,7 @@ const Timeline = { 'timelineName', 'title', 'userId', + 'groupName', 'tag' ], data () { @@ -49,7 +50,7 @@ const Timeline = { timeline: this.timelineName, showImmediately, userId: this.userId, - tag: this.tag + identifier: this.tag || this.groupName }) // don't fetch followers for public, friend, twkn @@ -77,7 +78,7 @@ const Timeline = { older: true, showImmediately: true, userId: this.userId, - tag: this.tag + identifier: this.tag || this.groupName }).then(() => store.commit('setLoading', { timeline: this.timelineName, value: false })) }, fetchFollowers () { diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 94da6d10..1aff0c8e 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -260,7 +260,7 @@ const setUserMute = ({id, credentials, muted = true}) => { }) } -const fetchTimeline = ({timeline, credentials, since = false, until = false, userId = false, tag = false}) => { +const fetchTimeline = ({timeline, credentials, since = false, until = false, userId = false, identifier = false}) => { const timelineUrls = { public: PUBLIC_TIMELINE_URL, friends: FRIENDS_TIMELINE_URL, @@ -284,8 +284,8 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use if (userId) { params.push(['user_id', userId]) } - if (tag) { - url += `/${tag}.json` + if (identifier) { + url += `/${identifier}.json` } const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index 6b76eb54..e2a8bc1a 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -14,7 +14,7 @@ const update = ({store, statuses, timeline, showImmediately}) => { }) } -const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false, userId = false, tag = false}) => { +const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false, userId = false, identifier = false}) => { const args = { timeline, credentials } const rootState = store.rootState || store.state const timelineData = rootState.statuses.timelines[camelCase(timeline)] @@ -26,16 +26,16 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false } args['userId'] = userId - args['tag'] = tag + args['identifier'] = identifier return apiService.fetchTimeline(args) .then((statuses) => update({store, statuses, timeline, showImmediately}), () => store.dispatch('setError', { value: true })) } -const startFetching = ({timeline = 'friends', credentials, store, userId = false, tag = false}) => { - fetchAndUpdate({timeline, credentials, store, showImmediately: true, userId, tag}) - const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, userId, tag }) +const startFetching = ({timeline = 'friends', credentials, store, userId = false, identifier = false}) => { + fetchAndUpdate({timeline, credentials, store, showImmediately: true, userId, identifier}) + const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, showImmediately: false, userId, identifier }) return setInterval(boundFetchAndUpdate, 10000) } const timelineFetcher = {