Add option for disabling chat.

This commit is contained in:
eal 2017-12-07 18:20:44 +02:00
parent 6c4e3a509a
commit 612fb18367
3 changed files with 18 additions and 5 deletions

View file

@ -6,7 +6,8 @@ const api = {
state: {
backendInteractor: backendInteractorService(),
fetchers: {},
socket: null
socket: null,
chatDisabled: false
},
mutations: {
setBackendInteractor (state, backendInteractor) {
@ -20,6 +21,9 @@ const api = {
},
setSocket (state, socket) {
state.socket = socket
},
setChatDisabled (state, value) {
state.chatDisabled = value
}
},
actions: {
@ -45,9 +49,14 @@ const api = {
},
initializeSocket (store, token) {
// Set up websocket connection
let socket = new Socket('/socket', {params: {token: token}})
socket.connect()
store.dispatch('initializeChat', socket)
if (!store.state.chatDisabled) {
let socket = new Socket('/socket', {params: {token: token}})
socket.connect()
store.dispatch('initializeChat', socket)
}
},
disableChat (store) {
store.commit('setChatDisabled', true)
}
}
}