Connect only after-store instead of when user gets token

This commit is contained in:
shpuld 2019-01-29 17:16:25 +02:00
parent 4185452b52
commit 41c4d59341
3 changed files with 13 additions and 4 deletions

View file

@ -89,6 +89,8 @@ const afterStoreSetup = ({ store, i18n }) => {
if ((config.chatDisabled)) { if ((config.chatDisabled)) {
store.dispatch('disableChat') store.dispatch('disableChat')
} else {
store.dispatch('initializeSocket')
} }
const router = new VueRouter({ const router = new VueRouter({

View file

@ -20,6 +20,9 @@ const api = {
removeFetcher (state, {timeline}) { removeFetcher (state, {timeline}) {
delete state.fetchers[timeline] delete state.fetchers[timeline]
}, },
setWsToken (state, token) {
state.wsToken = token
},
setSocket (state, socket) { setSocket (state, socket) {
state.socket = socket state.socket = socket
}, },
@ -51,10 +54,14 @@ const api = {
window.clearInterval(fetcher) window.clearInterval(fetcher)
store.commit('removeFetcher', {timeline}) store.commit('removeFetcher', {timeline})
}, },
initializeSocket (store, token) { setWsToken (store, token) {
store.commit('setWsToken', token)
},
initializeSocket (store) {
// Set up websocket connection // Set up websocket connection
if (!store.state.chatDisabled) { if (!store.state.chatDisabled) {
let socket = new Socket('/socket', {params: {token: token}}) const token = store.state.wsToken
const socket = new Socket('/socket', {params: {token}})
socket.connect() socket.connect()
store.dispatch('initializeChat', socket) store.dispatch('initializeChat', socket)
} }

View file

@ -222,10 +222,10 @@ const users = {
commit('setBackendInteractor', backendInteractorService(accessToken)) commit('setBackendInteractor', backendInteractorService(accessToken))
if (user.token) { if (user.token) {
store.dispatch('initializeSocket', user.token) store.dispatch('setWsToken', user.token)
} }
// Start getting fresh tweets. // Start getting fresh posts.
store.dispatch('startFetching', 'friends') store.dispatch('startFetching', 'friends')
// Get user mutes and follower info // Get user mutes and follower info