aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-12-10 21:30:27 +0200
committerHenry Jameson <me@hjkos.com>2019-12-10 21:30:27 +0200
commit6acd889589e46b18491d96b5fa992154b4e58d88 (patch)
treedebcdf1551aa869703bc032ee57b55266e8bc788 /src/modules
parent505fb260610e557e27bbc5d27515337ea07e0e3e (diff)
Option to enable streaming
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/api.js18
-rw-r--r--src/modules/config.js1
-rw-r--r--src/modules/users.js14
3 files changed, 30 insertions, 3 deletions
diff --git a/src/modules/api.js b/src/modules/api.js
index 593f8498..dc91d00e 100644
--- a/src/modules/api.js
+++ b/src/modules/api.js
@@ -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, {
diff --git a/src/modules/config.js b/src/modules/config.js
index 329b4091..74025db1 100644
--- a/src/modules/config.js
+++ b/src/modules/config.js
@@ -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
diff --git a/src/modules/users.js b/src/modules/users.js
index 6bdaf193..cbec6063 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -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')