From 6bf5c096c14d1a2591b16790e060186e84d0ae46 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Thu, 24 Oct 2024 14:44:26 +0200 Subject: [PATCH] fix: pass conversation to callView store via actions Signed-off-by: Maksim Sukharev --- src/store/participantsStore.js | 2 +- src/store/participantsStore.spec.js | 8 ++++++++ src/stores/__tests__/callView.spec.js | 12 ++++++++++-- src/stores/callView.js | 12 +++++++----- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/store/participantsStore.js b/src/store/participantsStore.js index 66b3ef4ca3b..09fc6f91f93 100644 --- a/src/store/participantsStore.js +++ b/src/store/participantsStore.js @@ -845,7 +845,7 @@ const actions = { }, 10000) const callViewStore = useCallViewStore() - callViewStore.handleJoinCall({ token }) + callViewStore.handleJoinCall(getters.conversation(token)) }, async leaveCall({ commit, getters }, { token, participantIdentifier, all = false }) { diff --git a/src/store/participantsStore.spec.js b/src/store/participantsStore.spec.js index 36fd7494d88..70dc8baac55 100644 --- a/src/store/participantsStore.spec.js +++ b/src/store/participantsStore.spec.js @@ -540,6 +540,10 @@ describe('participantsStore', () => { const flags = PARTICIPANT.CALL_FLAG.WITH_AUDIO | PARTICIPANT.CALL_FLAG.WITH_VIDEO beforeEach(async () => { + testStoreConfig.getters.conversation = () => jest.fn().mockReturnValue({ + token: TOKEN, + type: 3, + }) store = new Vuex.Store(testStoreConfig) store.dispatch('addParticipant', { token: TOKEN, @@ -876,6 +880,10 @@ describe('participantsStore', () => { attendeeId: 1, sessionId: 'session-id-1', }) + testStoreConfig.getters.conversation = () => jest.fn().mockReturnValue({ + token: TOKEN, + type: 3, + }) store = new Vuex.Store(testStoreConfig) store.dispatch('addParticipant', { diff --git a/src/stores/__tests__/callView.spec.js b/src/stores/__tests__/callView.spec.js index 922cb831880..6231c864582 100644 --- a/src/stores/__tests__/callView.spec.js +++ b/src/stores/__tests__/callView.spec.js @@ -38,11 +38,12 @@ describe('callViewStore', () => { function testDefaultGridState(type, state, browserStorageState = null) { // Arrange BrowserStorage.getItem.mockReturnValueOnce(browserStorageState) + const conversation = { token: TOKEN, type } // using commit instead of dispatch because the action also processes participants - vuexStore.commit('addConversation', { token: TOKEN, type }) + vuexStore.commit('addConversation', conversation) // Act - callViewStore.handleJoinCall({ token: TOKEN }) + callViewStore.handleJoinCall(conversation) // Assert expect(BrowserStorage.getItem).toHaveBeenCalledWith(BROWSER_STORAGE_KEY) @@ -50,6 +51,13 @@ describe('callViewStore', () => { expect(callViewStore.isStripeOpen).toBeTruthy() } + it('does not proceed without conversation object', () => { + // Act + callViewStore.handleJoinCall() + // Assert + expect(BrowserStorage.getItem).not.toHaveBeenCalledWith(BROWSER_STORAGE_KEY) + }) + it('restores grid state from BrowserStorage when joining call (true)', () => { // Arrange testDefaultGridState(CONVERSATION.TYPE.GROUP, true, 'true') diff --git a/src/stores/callView.js b/src/stores/callView.js index 7202755febd..360be6eafcf 100644 --- a/src/stores/callView.js +++ b/src/stores/callView.js @@ -7,7 +7,6 @@ import { defineStore } from 'pinia' import { CONVERSATION } from '../constants.js' import BrowserStorage from '../services/BrowserStorage.js' -import store from '../store/index.js' export const useCallViewStore = defineStore('callView', { state: () => ({ @@ -44,13 +43,16 @@ export const useCallViewStore = defineStore('callView', { this.selectedVideoPeerId = value }, - handleJoinCall({ token }) { - const gridPreference = BrowserStorage.getItem(`callprefs-${token}-isgrid`) + handleJoinCall(conversation) { + if (!conversation) { + return + } + const gridPreference = BrowserStorage.getItem(`callprefs-${conversation.token}-isgrid`) const isGrid = gridPreference === null // not defined yet, default to grid view for group/public calls, otherwise speaker view - ? [CONVERSATION.TYPE.GROUP, CONVERSATION.TYPE.PUBLIC].includes(store.getters.conversations[token].type) + ? [CONVERSATION.TYPE.GROUP, CONVERSATION.TYPE.PUBLIC].includes(conversation.type) : gridPreference === 'true' - this.setCallViewMode({ isGrid, isStripeOpen: true }) + this.setCallViewMode({ token: conversation.token, isGrid, isStripeOpen: true }) }, /**