Merge branch 'fix/chat-issues' into 'develop'

Initialize chat only if user is logged in and it wasn't initialized before

Closes pleroma#1067, pleroma#856, pleroma#1080, and #394

See merge request pleroma/pleroma-fe!894
This commit is contained in:
Shpuld Shpludson 2019-08-17 08:18:42 +00:00
commit 7f35489e3e
7 changed files with 17 additions and 30 deletions

View File

@ -109,12 +109,6 @@ const setSettings = async ({ apiConfig, staticConfig, store }) => {
copyInstanceOption('noAttachmentLinks')
copyInstanceOption('showFeaturesPanel')
if ((config.chatDisabled)) {
store.dispatch('disableChat')
} else {
store.dispatch('initializeSocket')
}
return store.dispatch('setTheme', config['theme'])
}

View File

@ -1,8 +1,6 @@
const FeaturesPanel = {
computed: {
chat: function () {
return this.$store.state.instance.chatAvailable && (!this.$store.state.chatDisabled)
},
chat: function () { return this.$store.state.instance.chatAvailable },
gopher: function () { return this.$store.state.instance.gopherAvailable },
whoToFollow: function () { return this.$store.state.instance.suggestionsEnabled },
mediaProxy: function () { return this.$store.state.instance.mediaProxyAvailable },

View File

@ -6,7 +6,6 @@ const api = {
backendInteractor: backendInteractorService(),
fetchers: {},
socket: null,
chatDisabled: false,
followRequests: []
},
mutations: {
@ -25,9 +24,6 @@ const api = {
setSocket (state, socket) {
state.socket = socket
},
setChatDisabled (state, value) {
state.chatDisabled = value
},
setFollowRequests (state, value) {
state.followRequests = value
}
@ -55,17 +51,20 @@ const api = {
setWsToken (store, token) {
store.commit('setWsToken', token)
},
initializeSocket (store) {
initializeSocket ({ dispatch, commit, state, rootState }) {
// Set up websocket connection
if (!store.state.chatDisabled) {
const token = store.state.wsToken
const token = state.wsToken
if (rootState.instance.chatAvailable && typeof token !== 'undefined' && state.socket === null) {
const socket = new Socket('/socket', { params: { token } })
socket.connect()
store.dispatch('initializeChat', socket)
commit('setSocket', socket)
dispatch('initializeChat', socket)
}
},
disableChat (store) {
store.commit('setChatDisabled', true)
disconnectFromSocket ({ commit, state }) {
state.socket && state.socket.disconnect()
commit('setSocket', null)
},
removeFollowRequest (store, request) {
let requests = store.state.followRequests.filter((it) => it !== request)

View File

@ -1,16 +1,12 @@
const chat = {
state: {
messages: [],
channel: { state: '' },
socket: null
channel: { state: '' }
},
mutations: {
setChannel (state, channel) {
state.channel = channel
},
setSocket (state, socket) {
state.socket = socket
},
addMessage (state, message) {
state.messages.push(message)
state.messages = state.messages.slice(-19, 20)
@ -20,12 +16,8 @@ const chat = {
}
},
actions: {
disconnectFromChat (store) {
store.state.socket && store.state.socket.disconnect()
},
initializeChat (store, socket) {
const channel = socket.channel('chat:public')
store.commit('setSocket', socket)
channel.on('new_msg', (msg) => {
store.commit('addMessage', msg)
})

View File

@ -79,6 +79,11 @@ const instance = {
case 'name':
dispatch('setPageTitle')
break
case 'chatAvailable':
if (value) {
dispatch('initializeSocket')
}
break
}
},
setTheme ({ commit }, themeName) {

View File

@ -410,7 +410,7 @@ const users = {
})
.then(() => {
store.commit('clearCurrentUser')
store.dispatch('disconnectFromChat')
store.dispatch('disconnectFromSocket')
store.commit('clearToken')
store.dispatch('stopFetching', 'friends')
store.commit('setBackendInteractor', backendInteractorService(store.getters.getToken()))

View File

@ -6,7 +6,6 @@
"logoMargin": ".1em",
"redirectRootNoLogin": "/main/all",
"redirectRootLogin": "/main/friends",
"chatDisabled": false,
"showInstanceSpecificPanel": false,
"collapseMessageWithSubject": false,
"scopeCopy": true,