Skip to content

Commit

Permalink
fix: remove redundant and unrelated getters
Browse files Browse the repository at this point in the history
- remove isQualityWarningTooltipDismissed from store (reset on each call, so make sense to store in component only)
- move participantRaisedHands to participantsStore
- remove backgroundImageAverageColorCache from store (was dropped in 9094628)

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Oct 14, 2024
1 parent 665bfc8 commit 6158a88
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 132 deletions.
4 changes: 3 additions & 1 deletion src/components/RightSidebar/Participants/Participant.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { createLocalVue, shallowMount } from '@vue/test-utils'
import flushPromises from 'flush-promises'
import { cloneDeep } from 'lodash'
import { createPinia, setActivePinia } from 'pinia'
import Vuex from 'vuex'

import HandBackLeft from 'vue-material-design-icons/HandBackLeft.vue'
Expand Down Expand Up @@ -38,6 +39,7 @@ describe('Participant.vue', () => {
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
setActivePinia(createPinia())

participant = {
displayName: 'Alice',
Expand Down Expand Up @@ -271,7 +273,7 @@ describe('Participant.vue', () => {
getParticipantRaisedHandMock = jest.fn().mockReturnValue({ state: false })

testStoreConfig = cloneDeep(storeConfig)
testStoreConfig.modules.callViewStore.getters.getParticipantRaisedHand = () => getParticipantRaisedHandMock
testStoreConfig.modules.participantsStore.getters.getParticipantRaisedHand = () => getParticipantRaisedHandMock
store = new Vuex.Store(testStoreConfig)
})

Expand Down
7 changes: 2 additions & 5 deletions src/components/TopBar/TopBarMediaControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export default {
boundaryElement: document.querySelector('.main-view'),
mouseover: false,
qualityWarningInGracePeriodTimeout: null,
isQualityWarningTooltipDismissed: false,
}
},
Expand Down Expand Up @@ -256,10 +257,6 @@ export default {
: t('spreed', 'Enable screensharing')
},
isQualityWarningTooltipDismissed() {
return this.$store.getters.isQualityWarningTooltipDismissed
},
showQualityWarningTooltip() {
return this.qualityWarningTooltip && (!this.isQualityWarningTooltipDismissed || this.mouseover)
},
Expand Down Expand Up @@ -510,7 +507,7 @@ export default {
},
dismissQualityWarningTooltip() {
this.$store.dispatch('dismissQualityWarningTooltip')
this.isQualityWarningTooltipDismissed = true
},
},
}
Expand Down
61 changes: 0 additions & 61 deletions src/store/callViewStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,67 +32,6 @@ describe('callViewStore', () => {
jest.clearAllMocks()
})

describe('raised hand', () => {
test('get whether participants raised hands with single session id', () => {
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-1',
raisedHand: { state: true, timestamp: 1 },
})
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-2',
raisedHand: { state: true, timestamp: 2 },
})

expect(store.getters.getParticipantRaisedHand(['session-id-1']))
.toStrictEqual({ state: true, timestamp: 1 })

expect(store.getters.getParticipantRaisedHand(['session-id-2']))
.toStrictEqual({ state: true, timestamp: 2 })

expect(store.getters.getParticipantRaisedHand(['session-id-another']))
.toStrictEqual({ state: false, timestamp: null })
})

test('get raised hands after lowering', () => {
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-2',
raisedHand: { state: true, timestamp: 1 },
})
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-2',
raisedHand: { state: false, timestamp: 3 },
})

expect(store.getters.getParticipantRaisedHand(['session-id-2']))
.toStrictEqual({ state: false, timestamp: null })
})

test('clears raised hands state after leaving call', () => {
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-2',
raisedHand: { state: true, timestamp: 1 },
})
store.dispatch('leaveCall')

expect(store.getters.getParticipantRaisedHand(['session-id-2']))
.toStrictEqual({ state: false, timestamp: null })
})

test('get raised hands with multiple session ids only returns first found', () => {
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-2',
raisedHand: { state: true, timestamp: 1 },
})
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-3',
raisedHand: { state: true, timestamp: 1 },
})

expect(store.getters.getParticipantRaisedHand(['session-id-1', 'session-id-2', 'session-id-3']))
.toStrictEqual({ state: true, timestamp: 1 })
})
})

describe('call view mode and presentation', () => {
test('restores grid state when joining call (true)', () => {
localStorage.getItem.mockReturnValueOnce('true')
Expand Down
38 changes: 38 additions & 0 deletions src/store/participantsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const state = {
},
speaking: {
},
// TODO: moved from callViewStore, separate to callExtras (with typing + speaking)
participantRaisedHands: {
},
initialised: {
},
/**
Expand Down Expand Up @@ -177,6 +180,19 @@ const getters = {
return state.speaking[attendeeId]
},

participantRaisedHandList: (state) => {
return state.participantRaisedHands
},
getParticipantRaisedHand: (state) => (sessionIds) => {
for (let i = 0; i < sessionIds.length; i++) {
if (state.participantRaisedHands[sessionIds[i]]) {
// note: only the raised states are stored, so no need to confirm
return state.participantRaisedHands[sessionIds[i]]
}
}

return { state: false, timestamp: null }
},
/**
* Replaces the legacy getParticipant getter. Returns a callback function in which you can
* pass in the token and attendeeId as arguments to get the participant object.
Expand Down Expand Up @@ -461,6 +477,21 @@ const mutations = {
}
},

setParticipantHandRaised(state, { sessionId, raisedHand }) {
if (!sessionId) {
throw new Error('Missing or empty sessionId argument in call to setParticipantHandRaised')
}
if (raisedHand && raisedHand.state) {
Vue.set(state.participantRaisedHands, sessionId, raisedHand)
} else {
Vue.delete(state.participantRaisedHands, sessionId)
}
},

clearParticipantHandRaised(state) {
state.participantRaisedHands = {}
},

/**
* Purge a given conversation from the previously added participants.
*
Expand Down Expand Up @@ -831,6 +862,9 @@ const actions = {
}
commit('updateParticipant', { token, attendeeId: attendee.attendeeId, updatedData })

// clear raised hands as they were specific to the call
commit('clearParticipantHandRaised')

commit('setInCall', {
token,
sessionId: participantIdentifier.sessionId,
Expand Down Expand Up @@ -1099,6 +1133,10 @@ const actions = {
context.commit('purgeSpeakingStore')
},

setParticipantHandRaised(context, { sessionId, raisedHand }) {
context.commit('setParticipantHandRaised', { sessionId, raisedHand })
},

processDialOutAnswer(context, { callid }) {
context.commit('setPhoneState', { callid })
},
Expand Down
67 changes: 67 additions & 0 deletions src/store/participantsStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,73 @@ describe('participantsStore', () => {
},
])
})

describe('raised hand', () => {
test('get whether participants raised hands with single session id', () => {
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-1',
raisedHand: { state: true, timestamp: 1 },
})
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-2',
raisedHand: { state: true, timestamp: 2 },
})

expect(store.getters.getParticipantRaisedHand(['session-id-1']))
.toStrictEqual({ state: true, timestamp: 1 })

expect(store.getters.getParticipantRaisedHand(['session-id-2']))
.toStrictEqual({ state: true, timestamp: 2 })

expect(store.getters.getParticipantRaisedHand(['session-id-another']))
.toStrictEqual({ state: false, timestamp: null })
})

test('get raised hands after lowering', () => {
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-2',
raisedHand: { state: true, timestamp: 1 },
})
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-2',
raisedHand: { state: false, timestamp: 3 },
})

expect(store.getters.getParticipantRaisedHand(['session-id-2']))
.toStrictEqual({ state: false, timestamp: null })
})

test('clears raised hands state after leaving call', async () => {
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-2',
raisedHand: { state: true, timestamp: 1 },
})
await store.dispatch('leaveCall', {
token: TOKEN,
participantIdentifier: {
attendeeId: 1,
sessionId: 'session-id-1',
},
})

expect(store.getters.getParticipantRaisedHand(['session-id-2']))
.toStrictEqual({ state: false, timestamp: null })
})

test('get raised hands with multiple session ids only returns first found', () => {
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-2',
raisedHand: { state: true, timestamp: 1 },
})
store.dispatch('setParticipantHandRaised', {
sessionId: 'session-id-3',
raisedHand: { state: true, timestamp: 1 },
})

expect(store.getters.getParticipantRaisedHand(['session-id-1', 'session-id-2', 'session-id-3']))
.toStrictEqual({ state: true, timestamp: 1 })
})
})
})

test('resends invitations', async () => {
Expand Down
65 changes: 0 additions & 65 deletions src/stores/callView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import { defineStore } from 'pinia'
import Vue from 'vue'

import { CONVERSATION } from '../constants.js'
import BrowserStorage from '../services/BrowserStorage.js'
Expand All @@ -20,58 +19,15 @@ export const useCallViewStore = defineStore('callView', {
lastIsStripeOpen: null,
presentationStarted: false,
selectedVideoPeerId: null,
qualityWarningTooltipDismissed: false,
callEndedTimeout: null,
participantRaisedHands: {},
backgroundImageAverageColorCache: {},
}),

getters: {
callHasJustEnded: (state) => !!state.callEndedTimeout,
isQualityWarningTooltipDismissed: (state) => state.qualityWarningTooltipDismissed,
participantRaisedHandList: (state) => {
return state.participantRaisedHands
},
getParticipantRaisedHand: (state) => (sessionIds) => {
for (let i = 0; i < sessionIds.length; i++) {
if (state.participantRaisedHands[sessionIds[i]]) {
// note: only the raised states are stored, so no need to confirm
return state.participantRaisedHands[sessionIds[i]]
}
}

return { state: false, timestamp: null }
},
getCachedBackgroundImageAverageColor: (state) => (videoBackgroundId) => {
return state.backgroundImageAverageColorCache[videoBackgroundId]
},
},

actions: {
// Mutations
setQualityWarningTooltipDismissed(state, { qualityWarningTooltipDismissed }) {
state.qualityWarningTooltipDismissed = qualityWarningTooltipDismissed
},
setParticipantHandRaised(state, { sessionId, raisedHand }) {
if (!sessionId) {
throw new Error('Missing or empty sessionId argument in call to setParticipantHandRaised')
}
if (raisedHand && raisedHand.state) {
Vue.set(state.participantRaisedHands, sessionId, raisedHand)
} else {
Vue.delete(state.participantRaisedHands, sessionId)
}
},
clearParticipantHandRaised(state) {
state.participantRaisedHands = {}
},
setCachedBackgroundImageAverageColor(state, { videoBackgroundId, backgroundImageAverageColor }) {
Vue.set(state.backgroundImageAverageColorCache, videoBackgroundId, backgroundImageAverageColor)
},
clearBackgroundImageAverageColorCache(state) {
state.backgroundImageAverageColorCache = {}
},

// Actions
setForceCallView(value) {
this.forceCallView = value
Expand All @@ -97,15 +53,6 @@ export const useCallViewStore = defineStore('callView', {
isGrid = (isGrid === 'true')
}
context.dispatch('setCallViewMode', { isGrid, isStripeOpen: true })

context.commit('setQualityWarningTooltipDismissed', { qualityWarningTooltipDismissed: false })
},

leaveCall(context) {
// clear raised hands as they were specific to the call
context.commit('clearParticipantHandRaised')

context.commit('clearBackgroundImageAverageColorCache')
},

/**
Expand Down Expand Up @@ -136,14 +83,6 @@ export const useCallViewStore = defineStore('callView', {
}
},

setParticipantHandRaised(context, { sessionId, raisedHand }) {
context.commit('setParticipantHandRaised', { sessionId, raisedHand })
},

setCachedBackgroundImageAverageColor(context, { videoBackgroundId, backgroundImageAverageColor }) {
context.commit('setCachedBackgroundImageAverageColor', { videoBackgroundId, backgroundImageAverageColor })
},

/**
* Starts presentation mode.
*
Expand Down Expand Up @@ -194,10 +133,6 @@ export const useCallViewStore = defineStore('callView', {
this.presentationStarted = false
},

dismissQualityWarningTooltip(context) {
context.commit('setQualityWarningTooltipDismissed', { qualityWarningTooltipDismissed: true })
},

setIsEmptyCallView(value) {
this.isEmptyCallView = value
},
Expand Down

0 comments on commit 6158a88

Please sign in to comment.