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 = {
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 () {

View file

@ -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 () {

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 = {
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('&')

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 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 = {