Use common method for fetching group and tag timeline.

This commit is contained in:
eal 2017-11-19 17:41:50 +02:00
parent 9c90b019d1
commit 54d3b0cd7e
4 changed files with 13 additions and 12 deletions

View file

@ -3,7 +3,7 @@ import Timeline from '../timeline/timeline.vue'
const TagTimeline = { const TagTimeline = {
created () { created () {
this.$store.commit('clearTimeline', { timeline: 'tag' }) this.$store.commit('clearTimeline', { timeline: 'tag' })
this.$store.dispatch('startFetching', { 'tag': this.tag }) this.$store.dispatch('startFetching', ['identifier', this.tag])
}, },
components: { components: {
Timeline Timeline
@ -15,7 +15,7 @@ const TagTimeline = {
watch: { watch: {
tag () { tag () {
this.$store.commit('clearTimeline', { timeline: 'tag' }) this.$store.commit('clearTimeline', { timeline: 'tag' })
this.$store.dispatch('startFetching', { 'tag': this.tag }) this.$store.dispatch('startFetching', ['identifier', this.tag])
} }
}, },
destroyed () { destroyed () {

View file

@ -9,6 +9,7 @@ const Timeline = {
'timelineName', 'timelineName',
'title', 'title',
'userId', 'userId',
'groupName',
'tag' 'tag'
], ],
data () { data () {
@ -49,7 +50,7 @@ const Timeline = {
timeline: this.timelineName, timeline: this.timelineName,
showImmediately, showImmediately,
userId: this.userId, userId: this.userId,
tag: this.tag identifier: this.tag || this.groupName
}) })
// don't fetch followers for public, friend, twkn // don't fetch followers for public, friend, twkn
@ -77,7 +78,7 @@ const Timeline = {
older: true, older: true,
showImmediately: true, showImmediately: true,
userId: this.userId, userId: this.userId,
tag: this.tag identifier: this.tag || this.groupName
}).then(() => store.commit('setLoading', { timeline: this.timelineName, value: false })) }).then(() => store.commit('setLoading', { timeline: this.timelineName, value: false }))
}, },
fetchFollowers () { fetchFollowers () {

View file

@ -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 = { const timelineUrls = {
public: PUBLIC_TIMELINE_URL, public: PUBLIC_TIMELINE_URL,
friends: FRIENDS_TIMELINE_URL, friends: FRIENDS_TIMELINE_URL,
@ -284,8 +284,8 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use
if (userId) { if (userId) {
params.push(['user_id', userId]) params.push(['user_id', userId])
} }
if (tag) { if (identifier) {
url += `/${tag}.json` url += `/${identifier}.json`
} }
const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&')

View file

@ -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 args = { timeline, credentials }
const rootState = store.rootState || store.state const rootState = store.rootState || store.state
const timelineData = rootState.statuses.timelines[camelCase(timeline)] const timelineData = rootState.statuses.timelines[camelCase(timeline)]
@ -26,16 +26,16 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false
} }
args['userId'] = userId args['userId'] = userId
args['tag'] = tag args['identifier'] = identifier
return apiService.fetchTimeline(args) return apiService.fetchTimeline(args)
.then((statuses) => update({store, statuses, timeline, showImmediately}), .then((statuses) => update({store, statuses, timeline, showImmediately}),
() => store.dispatch('setError', { value: true })) () => store.dispatch('setError', { value: true }))
} }
const startFetching = ({timeline = 'friends', credentials, store, userId = false, tag = false}) => { const startFetching = ({timeline = 'friends', credentials, store, userId = false, identifier = false}) => {
fetchAndUpdate({timeline, credentials, store, showImmediately: true, userId, tag}) fetchAndUpdate({timeline, credentials, store, showImmediately: true, userId, identifier})
const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, userId, tag }) const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, showImmediately: false, userId, identifier })
return setInterval(boundFetchAndUpdate, 10000) return setInterval(boundFetchAndUpdate, 10000)
} }
const timelineFetcher = { const timelineFetcher = {