Option to enable streaming
This commit is contained in:
parent
505fb26061
commit
6acd889589
8 changed files with 62 additions and 4 deletions
|
@ -31,6 +31,18 @@ const api = {
|
|||
}
|
||||
},
|
||||
actions: {
|
||||
// Global MastoAPI socket control, in future should disable ALL sockets/(re)start relevant sockets
|
||||
enableMastoSockets (store) {
|
||||
const { state, dispatch } = store
|
||||
if (state.mastoUserSocket) return
|
||||
dispatch('startMastoUserSocket')
|
||||
},
|
||||
disableMastoSockets (store) {
|
||||
const { state, dispatch } = store
|
||||
if (!state.mastoUserSocket) return
|
||||
dispatch('stopMastoUserSocket')
|
||||
},
|
||||
|
||||
// MastoAPI 'User' sockets
|
||||
startMastoUserSocket (store) {
|
||||
const { state, dispatch } = store
|
||||
|
@ -81,6 +93,12 @@ const api = {
|
|||
dispatch('stopFetchingNotifications')
|
||||
})
|
||||
},
|
||||
stopMastoUserSocket ({ state, dispatch }) {
|
||||
dispatch('startFetchingTimeline', { timeline: 'friends' })
|
||||
dispatch('startFetchingNotifications')
|
||||
console.log(state.mastoUserSocket)
|
||||
state.mastoUserSocket.close()
|
||||
},
|
||||
|
||||
// Timelines
|
||||
startFetchingTimeline (store, {
|
||||
|
|
|
@ -35,6 +35,7 @@ export const defaultState = {
|
|||
highlight: {},
|
||||
interfaceLanguage: browserLocale,
|
||||
hideScopeNotice: false,
|
||||
useStreamingApi: false,
|
||||
scopeCopy: undefined, // instance default
|
||||
subjectLineBehavior: undefined, // instance default
|
||||
alwaysShowSubjectInput: undefined, // instance default
|
||||
|
|
|
@ -469,14 +469,22 @@ const users = {
|
|||
store.dispatch('initializeSocket')
|
||||
}
|
||||
|
||||
store.dispatch('startMastoUserSocket').catch((error) => {
|
||||
console.error('Failed initializing MastoAPI Streaming socket', error)
|
||||
const startPolling = () => {
|
||||
// Start getting fresh posts.
|
||||
store.dispatch('startFetchingTimeline', { timeline: 'friends' })
|
||||
|
||||
// Start fetching notifications
|
||||
store.dispatch('startFetchingNotifications')
|
||||
})
|
||||
}
|
||||
|
||||
if (store.getters.mergedConfig.useStreamingApi) {
|
||||
store.dispatch('enableMastoSockets').catch((error) => {
|
||||
console.error('Failed initializing MastoAPI Streaming socket', error)
|
||||
startPolling()
|
||||
})
|
||||
} else {
|
||||
startPolling()
|
||||
}
|
||||
|
||||
// Get user mutes
|
||||
store.dispatch('fetchMutes')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue