Fetch Public and TWKN timelines when viewed.
This commit is contained in:
parent
14f07dde5d
commit
832bd3cdd2
|
@ -5,6 +5,12 @@ const PublicAndExternalTimeline = {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
timeline () { return this.$store.state.statuses.timelines.publicAndExternal }
|
timeline () { return this.$store.state.statuses.timelines.publicAndExternal }
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.$store.dispatch('startFetching', 'publicAndExternal')
|
||||||
|
},
|
||||||
|
destroyed () {
|
||||||
|
this.$store.dispatch('stopFetching', 'publicAndExternal')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,14 @@ const PublicTimeline = {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
timeline () { return this.$store.state.statuses.timelines.public }
|
timeline () { return this.$store.state.statuses.timelines.public }
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.$store.dispatch('startFetching', 'public')
|
||||||
|
},
|
||||||
|
destroyed () {
|
||||||
|
this.$store.dispatch('stopFetching', 'public')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PublicTimeline
|
export default PublicTimeline
|
||||||
|
|
|
@ -2,11 +2,32 @@ import backendInteractorService from '../services/backend_interactor_service/bac
|
||||||
|
|
||||||
const api = {
|
const api = {
|
||||||
state: {
|
state: {
|
||||||
backendInteractor: backendInteractorService()
|
backendInteractor: backendInteractorService(),
|
||||||
|
fetchers: {}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setBackendInteractor (state, backendInteractor) {
|
setBackendInteractor (state, backendInteractor) {
|
||||||
state.backendInteractor = backendInteractor
|
state.backendInteractor = backendInteractor
|
||||||
|
},
|
||||||
|
addFetcher (state, {timeline, fetcher}) {
|
||||||
|
state.fetchers[timeline] = fetcher
|
||||||
|
},
|
||||||
|
removeFetcher (state, {timeline}) {
|
||||||
|
delete state.fetchers[timeline]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
startFetching (store, timeline) {
|
||||||
|
// Don't start fetching if we already are.
|
||||||
|
if (!store.state.fetchers[timeline]) {
|
||||||
|
const fetcher = store.state.backendInteractor.startFetching({timeline, store})
|
||||||
|
store.commit('addFetcher', {timeline, fetcher})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
stopFetching (store, timeline) {
|
||||||
|
const fetcher = store.state.fetchers[timeline]
|
||||||
|
window.clearInterval(fetcher)
|
||||||
|
store.commit('removeFetcher', {timeline})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import timelineFetcher from '../services/timeline_fetcher/timeline_fetcher.service.js'
|
|
||||||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
||||||
import { compact, map, each, find, merge } from 'lodash'
|
import { compact, map, each, find, merge } from 'lodash'
|
||||||
import { set } from 'vue'
|
import { set } from 'vue'
|
||||||
|
@ -74,12 +73,12 @@ const users = {
|
||||||
commit('setCurrentUser', user)
|
commit('setCurrentUser', user)
|
||||||
commit('addNewUsers', [user])
|
commit('addNewUsers', [user])
|
||||||
|
|
||||||
// Start getting fresh tweets.
|
|
||||||
timelineFetcher.startFetching({store, credentials: userCredentials})
|
|
||||||
|
|
||||||
// Set our new backend interactor
|
// Set our new backend interactor
|
||||||
commit('setBackendInteractor', backendInteractorService(userCredentials))
|
commit('setBackendInteractor', backendInteractorService(userCredentials))
|
||||||
|
|
||||||
|
// Start getting fresh tweets.
|
||||||
|
store.dispatch('startFetching', 'friends')
|
||||||
|
|
||||||
// Fetch our friends
|
// Fetch our friends
|
||||||
store.rootState.api.backendInteractor.fetchFriends()
|
store.rootState.api.backendInteractor.fetchFriends()
|
||||||
.then((friends) => commit('addNewUsers', friends))
|
.then((friends) => commit('addNewUsers', friends))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import apiService from '../api/api.service.js'
|
import apiService from '../api/api.service.js'
|
||||||
|
import timelineFetcherService from '../timeline_fetcher/timeline_fetcher.service.js'
|
||||||
|
|
||||||
const backendInteractorService = (credentials) => {
|
const backendInteractorService = (credentials) => {
|
||||||
const fetchStatus = ({id}) => {
|
const fetchStatus = ({id}) => {
|
||||||
|
@ -29,6 +30,10 @@ const backendInteractorService = (credentials) => {
|
||||||
return apiService.unfollowUser({credentials, id})
|
return apiService.unfollowUser({credentials, id})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startFetching = ({timeline, store}) => {
|
||||||
|
return timelineFetcherService.startFetching({timeline, store, credentials})
|
||||||
|
}
|
||||||
|
|
||||||
const backendInteractorServiceInstance = {
|
const backendInteractorServiceInstance = {
|
||||||
fetchStatus,
|
fetchStatus,
|
||||||
fetchConversation,
|
fetchConversation,
|
||||||
|
@ -37,7 +42,8 @@ const backendInteractorService = (credentials) => {
|
||||||
followUser,
|
followUser,
|
||||||
unfollowUser,
|
unfollowUser,
|
||||||
fetchAllFollowing,
|
fetchAllFollowing,
|
||||||
verifyCredentials: apiService.verifyCredentials
|
verifyCredentials: apiService.verifyCredentials,
|
||||||
|
startFetching
|
||||||
}
|
}
|
||||||
|
|
||||||
return backendInteractorServiceInstance
|
return backendInteractorServiceInstance
|
||||||
|
|
|
@ -30,8 +30,7 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false
|
||||||
const startFetching = ({ timeline = 'friends', credentials, store }) => {
|
const startFetching = ({ timeline = 'friends', credentials, store }) => {
|
||||||
fetchAndUpdate({timeline, credentials, store, showImmediately: true})
|
fetchAndUpdate({timeline, credentials, store, showImmediately: true})
|
||||||
const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store })
|
const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store })
|
||||||
|
return setInterval(boundFetchAndUpdate, 10000)
|
||||||
setInterval(boundFetchAndUpdate, 10000)
|
|
||||||
}
|
}
|
||||||
const timelineFetcher = {
|
const timelineFetcher = {
|
||||||
fetchAndUpdate,
|
fetchAndUpdate,
|
||||||
|
|
Loading…
Reference in New Issue