fix(lobby): update store from server response

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
This commit is contained in:
Maksim Sukharev
2025-07-16 11:20:01 +02:00
parent 6705630255
commit f4236f0d9b
2 changed files with 29 additions and 20 deletions

View File

@ -625,22 +625,15 @@ const actions = {
},
async toggleLobby({ commit, getters }, { token, enableLobby }) {
if (!getters.conversations[token]) {
return
}
try {
const conversation = Object.assign({}, getters.conversations[token])
const response = await changeLobbyState(token, enableLobby ? WEBINAR.LOBBY.NON_MODERATORS : WEBINAR.LOBBY.NONE)
commit('addConversation', response.data.ocs.data)
if (enableLobby) {
await changeLobbyState(token, WEBINAR.LOBBY.NON_MODERATORS)
conversation.lobbyState = WEBINAR.LOBBY.NON_MODERATORS
showSuccess(t('spreed', 'You restricted the conversation to moderators'))
} else {
await changeLobbyState(token, WEBINAR.LOBBY.NONE)
conversation.lobbyState = WEBINAR.LOBBY.NONE
showSuccess(t('spreed', 'You opened the conversation to everyone'))
}
commit('addConversation', conversation)
} catch (error) {
console.error('Error occurred while updating webinar lobby: ', error)
if (enableLobby) {
@ -721,15 +714,10 @@ const actions = {
},
async setLobbyTimer({ commit, getters }, { token, timestamp }) {
if (!getters.conversations[token]) {
return
}
try {
const conversation = Object.assign({}, getters.conversations[token], { lobbyTimer: timestamp })
// The backend requires the state and timestamp to be set together.
await changeLobbyState(token, conversation.lobbyState, timestamp)
commit('addConversation', conversation)
const response = await changeLobbyState(token, WEBINAR.LOBBY.NON_MODERATORS, timestamp)
commit('addConversation', response.data.ocs.data)
} catch (error) {
console.error('Error while updating webinar lobby: ', error)
}

View File

@ -714,7 +714,14 @@ describe('conversationsStore', () => {
store.dispatch('addConversation', testConversation)
changeLobbyState.mockResolvedValue()
const response = generateOCSResponse({
payload: {
...testConversation,
lobbyState: WEBINAR.LOBBY.NON_MODERATORS,
lobbyTimer: 0,
},
})
changeLobbyState.mockResolvedValue(response)
await store.dispatch('toggleLobby', {
token: testToken,
@ -732,7 +739,14 @@ describe('conversationsStore', () => {
store.dispatch('addConversation', testConversation)
changeLobbyState.mockResolvedValue()
const response = generateOCSResponse({
payload: {
...testConversation,
lobbyState: WEBINAR.LOBBY.NONE,
lobbyTimer: 0,
},
})
changeLobbyState.mockResolvedValue(response)
await store.dispatch('toggleLobby', {
token: testToken,
@ -841,7 +855,14 @@ describe('conversationsStore', () => {
store.dispatch('addConversation', testConversation)
changeLobbyState.mockResolvedValue()
const response = generateOCSResponse({
payload: {
...testConversation,
lobbyState: WEBINAR.LOBBY.NON_MODERATORS,
lobbyTimer: 2300400,
},
})
changeLobbyState.mockResolvedValue(response)
await store.dispatch('setLobbyTimer', {
token: testToken,