Separate timeline and notification

This commit is contained in:
jasper 2019-04-04 09:03:56 -07:00
parent 7c2b65e9a3
commit a1275be4c0
7 changed files with 34 additions and 23 deletions

View file

@ -7,7 +7,7 @@ const PublicAndExternalTimeline = {
timeline () { return this.$store.state.statuses.timelines.publicAndExternal } timeline () { return this.$store.state.statuses.timelines.publicAndExternal }
}, },
created () { created () {
this.$store.dispatch('startFetching', { timeline: 'publicAndExternal' }) this.$store.dispatch('startFetchingTimeline', { timeline: 'publicAndExternal' })
}, },
destroyed () { destroyed () {
this.$store.dispatch('stopFetching', 'publicAndExternal') this.$store.dispatch('stopFetching', 'publicAndExternal')

View file

@ -7,7 +7,7 @@ const PublicTimeline = {
timeline () { return this.$store.state.statuses.timelines.public } timeline () { return this.$store.state.statuses.timelines.public }
}, },
created () { created () {
this.$store.dispatch('startFetching', { timeline: 'public' }) this.$store.dispatch('startFetchingTimeline', { timeline: 'public' })
}, },
destroyed () { destroyed () {
this.$store.dispatch('stopFetching', 'public') this.$store.dispatch('stopFetching', 'public')

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', { timeline: 'tag', tag: this.tag }) this.$store.dispatch('startFetchingTimeline', { timeline: 'tag', tag: 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', { timeline: 'tag', tag: this.tag }) this.$store.dispatch('startFetchingTimeline', { timeline: 'tag', tag: this.tag })
} }
}, },
destroyed () { destroyed () {

View file

@ -90,7 +90,7 @@ const UserProfile = {
methods: { methods: {
startFetchFavorites () { startFetchFavorites () {
if (this.isUs) { if (this.isUs) {
this.$store.dispatch('startFetching', { timeline: 'favorites', userId: this.userId }) this.$store.dispatch('startFetchingTimeline', { timeline: 'favorites', userId: this.userId })
} }
}, },
fetchUserId () { fetchUserId () {
@ -118,8 +118,8 @@ const UserProfile = {
}, },
startUp () { startUp () {
if (this.userId) { if (this.userId) {
this.$store.dispatch('startFetching', { timeline: 'user', userId: this.userId }) this.$store.dispatch('startFetchingTimeline', { timeline: 'user', userId: this.userId })
this.$store.dispatch('startFetching', { timeline: 'media', userId: this.userId }) this.$store.dispatch('startFetchingTimeline', { timeline: 'media', userId: this.userId })
this.startFetchFavorites() this.startFetchFavorites()
} }
}, },

View file

@ -13,11 +13,11 @@ const api = {
setBackendInteractor (state, backendInteractor) { setBackendInteractor (state, backendInteractor) {
state.backendInteractor = backendInteractor state.backendInteractor = backendInteractor
}, },
addFetcher (state, {timeline, fetcher}) { addFetcher (state, {fetcherName, fetcher}) {
state.fetchers[timeline] = fetcher state.fetchers[fetcherName] = fetcher
}, },
removeFetcher (state, {timeline}) { removeFetcher (state, { fetcherName }) {
delete state.fetchers[timeline] delete state.fetchers[fetcherName]
}, },
setWsToken (state, token) { setWsToken (state, token) {
state.wsToken = token state.wsToken = token
@ -33,17 +33,24 @@ const api = {
} }
}, },
actions: { actions: {
startFetching (store, {timeline = 'friends', tag = false, userId = false}) { startFetchingTimeline (store, {timeline = 'friends', tag = false, userId = false}) {
// Don't start fetching if we already are. // Don't start fetching if we already are.
if (store.state.fetchers[timeline]) return if (store.state.fetchers[timeline]) return
const fetcher = store.state.backendInteractor.startFetching({ timeline, store, userId, tag }) const fetcher = store.state.backendInteractor.startFetchingTimeline({ timeline, store, userId, tag })
store.commit('addFetcher', { timeline, fetcher }) store.commit('addFetcher', { fetcherName: timeline, fetcher })
}, },
stopFetching (store, timeline) { startFetchingNotifications (store) {
const fetcher = store.state.fetchers[timeline] // Don't start fetching if we already are.
if (store.state.fetchers['notifications']) return
const fetcher = store.state.backendInteractor.startFetchingNotifications({ store })
store.commit('addFetcher', { fetcherName: 'notifications', fetcher })
},
stopFetching (store, fetcherName) {
const fetcher = store.state.fetchers[fetcherName]
window.clearInterval(fetcher) window.clearInterval(fetcher)
store.commit('removeFetcher', {timeline}) store.commit('removeFetcher', { fetcherName })
}, },
setWsToken (store, token) { setWsToken (store, token) {
store.commit('setWsToken', token) store.commit('setWsToken', token)

View file

@ -364,10 +364,10 @@ const users = {
} }
// Start getting fresh posts. // Start getting fresh posts.
store.dispatch('startFetching', { timeline: 'friends' }) store.dispatch('startFetchingTimeline', { timeline: 'friends' })
// Start fetching notifications // Start fetching notifications
store.dispatch('startFetching', { timeline: 'notifications' }) store.dispatch('startFetchingNotifications')
// Get user mutes // Get user mutes
store.dispatch('fetchMutes') store.dispatch('fetchMutes')

View file

@ -59,11 +59,14 @@ const backendInteractorService = (credentials) => {
return apiService.denyUser({credentials, id}) return apiService.denyUser({credentials, id})
} }
const startFetching = ({timeline, store, userId = false, tag}) => { const startFetchingTimeline = ({ timeline, store, userId = false, tag }) => {
if (timeline === 'notifications') { return notificationsFetcher.startFetching({store, credentials}) }
return timelineFetcherService.startFetching({ timeline, store, credentials, userId, tag }) return timelineFetcherService.startFetching({ timeline, store, credentials, userId, tag })
} }
const startFetchingNotifications = ({ store }) => {
return notificationsFetcher.startFetching({ store, credentials })
}
const fetchMutes = () => apiService.fetchMutes({credentials}) const fetchMutes = () => apiService.fetchMutes({credentials})
const muteUser = (id) => apiService.muteUser({credentials, id}) const muteUser = (id) => apiService.muteUser({credentials, id})
const unmuteUser = (id) => apiService.unmuteUser({credentials, id}) const unmuteUser = (id) => apiService.unmuteUser({credentials, id})
@ -99,7 +102,8 @@ const backendInteractorService = (credentials) => {
fetchUserRelationship, fetchUserRelationship,
fetchAllFollowing, fetchAllFollowing,
verifyCredentials: apiService.verifyCredentials, verifyCredentials: apiService.verifyCredentials,
startFetching, startFetchingTimeline,
startFetchingNotifications,
fetchMutes, fetchMutes,
muteUser, muteUser,
unmuteUser, unmuteUser,