Skip to content

Commit

Permalink
Remove the duplicated actions in guestName store and fix naming
Browse files Browse the repository at this point in the history
Signed-off-by: DorraJaouad <dorra.jaoued7@gmail.com>
  • Loading branch information
DorraJaouad committed Sep 8, 2023
1 parent ff49828 commit 3ec33f8
Show file tree
Hide file tree
Showing 18 changed files with 208 additions and 183 deletions.
2 changes: 1 addition & 1 deletion src/components/CallView/shared/LocalVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import VideoBackground from './VideoBackground.vue'

import video from '../../../mixins/video.js'
import { useGuestNameStore } from '../../../stores/guestNameStore.js'
import { useGuestNameStore } from '../../../stores/guestName.js'
import { ConnectionState } from '../../../utils/webrtc/models/CallParticipantModel.js'

export default {
Expand Down
4 changes: 2 additions & 2 deletions src/components/CallView/shared/ReactionToaster.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import usernameToColor from '@nextcloud/vue/dist/Functions/usernameToColor.js'

import TransitionWrapper from '../../TransitionWrapper.vue'

import { useGuestNameStore } from '../../../stores/guestNameStore.js'
import { useGuestNameStore } from '../../../stores/guestName.js'

export default {
name: 'ReactionToaster',
Expand Down Expand Up @@ -154,7 +154,7 @@ export default {
id: model.attributes.peerId,
reaction,
name: isLocalModel
? this.$store.getters.getDisplayName() || this.guestNameStore.getGuestName()
? this.$store.getters.getDisplayName() || t('spreed', 'Guest')
: this.getParticipantName(model),
seed: Math.random(),
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/CallView/shared/Screen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import SHA1 from 'crypto-js/sha1.js'

import VideoBottomBar from './VideoBottomBar.vue'

import { useGuestNameStore } from '../../../stores/guestNameStore.js'
import { useGuestNameStore } from '../../../stores/guestName.js'

export default {

Expand Down
4 changes: 1 addition & 3 deletions src/components/CallView/shared/VideoVue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('VideoVue.vue', () => {
let localVue
let store
let testStoreConfig
let pinia

let callParticipantModel

Expand Down Expand Up @@ -89,8 +88,7 @@ describe('VideoVue.vue', () => {
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
pinia = createPinia()
setActivePinia(pinia)
setActivePinia(createPinia())

testStoreConfig = cloneDeep(storeConfig)
// eslint-disable-next-line import/no-named-as-default-member
Expand Down
2 changes: 1 addition & 1 deletion src/components/CallView/shared/VideoVue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ import VideoBottomBar from './VideoBottomBar.vue'
import { ATTENDEE } from '../../../constants.js'
import video from '../../../mixins/video.js'
import { EventBus } from '../../../services/EventBus.js'
import { useGuestNameStore } from '../../../stores/guestNameStore.js'
import { useGuestNameStore } from '../../../stores/guestName.js'
import { ConnectionState } from '../../../utils/webrtc/models/CallParticipantModel.js'

export default {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MediaSettings/MediaSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ import { CALL, VIRTUAL_BACKGROUND } from '../../constants.js'
import { devices } from '../../mixins/devices.js'
import isInLobby from '../../mixins/isInLobby.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { useGuestNameStore } from '../../stores/guestNameStore.js'
import { useGuestNameStore } from '../../stores/guestName.js'
import { localMediaModel } from '../../utils/webrtc/index.js'

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ describe('Message.vue', () => {
let conversationProps
let injected
let getActorTypeMock
let pinia
const getVisualLastReadMessageIdMock = jest.fn()

beforeEach(() => {
localVue = createLocalVue()
localVue.use(vOutsideEvents)
localVue.use(Vuex)
pinia = createPinia()
setActivePinia(pinia)
setActivePinia(createPinia())

conversationProps = {
token: TOKEN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ import { useIsInCall } from '../../../../composables/useIsInCall.js'
import { ATTENDEE, CONVERSATION, PARTICIPANT } from '../../../../constants.js'
import participant from '../../../../mixins/participant.js'
import { EventBus } from '../../../../services/EventBus.js'
import { useGuestNameStore } from '../../../../stores/guestNameStore.js'
import { useGuestNameStore } from '../../../../stores/guestName.js'

const isTranslationAvailable = getCapabilities()?.spreed?.config?.chat?.translations?.length > 0

Expand Down
22 changes: 11 additions & 11 deletions src/components/MessagesList/MessagesGroup/MessagesGroup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@ import MessagesSystemGroup from './MessagesSystemGroup.vue'

import { ATTENDEE } from '../../../constants.js'
import storeConfig from '../../../store/storeConfig.js'
import { useGuestNameStore } from '../../../stores/guestNameStore.js'
import { useGuestNameStore } from '../../../stores/guestName.js'

describe('MessagesGroup.vue', () => {
const TOKEN = 'XXTOKENXX'
let store
let localVue
let testStoreConfig
let getGuestNameMock
let pinia
let guestNameStore

beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
pinia = createPinia()
setActivePinia(pinia)
setActivePinia(createPinia())

const guestNameStore = useGuestNameStore()
guestNameStore = useGuestNameStore()

testStoreConfig = cloneDeep(storeConfig)
getGuestNameMock = jest.fn()
guestNameStore.getGuestName = getGuestNameMock
// eslint-disable-next-line import/no-named-as-default-member
store = new Vuex.Store(testStoreConfig)
})
Expand Down Expand Up @@ -186,7 +182,13 @@ describe('MessagesGroup.vue', () => {
})

test('renders guest display name', () => {
getGuestNameMock.mockReturnValue('guest-one-display-name')
// Arrange
guestNameStore.addGuestName({
token: TOKEN,
actorId: 'actor-1',
actorDisplayName: 'guest-one-display-name',
}, { noUpdate: false })

const wrapper = shallowMount(MessagesGroup, {
localVue,
store,
Expand Down Expand Up @@ -239,8 +241,6 @@ describe('MessagesGroup.vue', () => {
message = messagesEl.at(1)
expect(message.attributes('id')).toBe('110')
expect(message.attributes('actorid')).toBe('actor-1')

expect(getGuestNameMock).toHaveBeenCalledWith(TOKEN, 'actor-1')
})

test('renders deleted guest display name', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import AuthorAvatar from './AuthorAvatar.vue'
import Message from './Message/Message.vue'

import { ATTENDEE } from '../../../constants.js'
import { useGuestNameStore } from '../../../stores/guestNameStore.js'
import { useGuestNameStore } from '../../../stores/guestName.js'

export default {
name: 'MessagesGroup',
Expand Down
2 changes: 1 addition & 1 deletion src/components/NewMessage/NewMessageTypingIndicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import escapeHtml from 'escape-html'

import AvatarWrapper from '../AvatarWrapper/AvatarWrapper.vue'

import { useGuestNameStore } from '../../stores/guestNameStore.js'
import { useGuestNameStore } from '../../stores/guestName.js'

export default {
name: 'NewMessageTypingIndicator',
Expand Down
10 changes: 5 additions & 5 deletions src/components/SetGuestUsername.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'

import { setGuestUserName } from '../services/participantsService.js'
import { useGuestNameStore } from '../stores/guestNameStore.js'
import { useGuestNameStore } from '../stores/guestName.js'

export default {
name: 'SetGuestUsername',
Expand Down Expand Up @@ -127,11 +127,11 @@ export default {
const previousName = this.$store.getters.getDisplayName()
try {
this.$store.dispatch('setDisplayName', this.guestUserName)
this.guestNameStore.forceGuestName({
this.guestNameStore.addGuestName({
token: this.token,
actorId: this.$store.getters.getActorId(),
actorDisplayName: this.guestUserName,
})
}, { noUpdate: false })
await setGuestUserName(this.token, this.guestUserName)
if (this.guestUserName !== '') {
localStorage.setItem('nick', this.guestUserName)
Expand All @@ -141,11 +141,11 @@ export default {
this.isEditingUsername = false
} catch (exception) {
this.$store.dispatch('setDisplayName', previousName)
this.guestNameStore.forceGuestName({
this.guestNameStore.addGuestName({
token: this.token,
actorId: this.$store.getters.getActorId(),
actorDisplayName: previousName,
})
}, { noUpdate: false })
console.debug(exception)
}
},
Expand Down
6 changes: 3 additions & 3 deletions src/mixins/getParticipants.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { emit } from '@nextcloud/event-bus'
import { PARTICIPANT } from '../constants.js'
import { EventBus } from '../services/EventBus.js'
import { fetchParticipants } from '../services/participantsService.js'
import { useGuestNameStore } from '../stores/guestNameStore.js'
import { useGuestNameStore } from '../stores/guestName.js'
import CancelableRequest from '../utils/cancelableRequest.js'
import isInLobby from './isInLobby.js'

Expand Down Expand Up @@ -143,11 +143,11 @@ const getParticipants = {
})
if (participant.participantType === PARTICIPANT.TYPE.GUEST
|| participant.participantType === PARTICIPANT.TYPE.GUEST_MODERATOR) {
this.guestNameStore.forceGuestName({
this.guestNameStore.addGuestName({
token,
actorId: Hex.stringify(SHA1(participant.sessionIds[0])),
actorDisplayName: participant.displayName,
})
}, { noUpdate: false })
} else if (participant.actorType === 'users' && hasUserStatuses) {
emit('user_status:status.updated', {
status: participant.status,
Expand Down
8 changes: 4 additions & 4 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
addReactionToMessage,
removeReactionFromMessage,
} from '../services/messagesService.js'
import { useGuestNameStore } from '../stores/guestNameStore.js'
import { useGuestNameStore } from '../stores/guestName.js'
import CancelableRequest from '../utils/cancelableRequest.js'

/**
Expand Down Expand Up @@ -821,7 +821,7 @@ const actions = {
if (message.actorType === ATTENDEE.ACTOR_TYPE.GUESTS) {
// update guest display names cache
const guestNameStore = useGuestNameStore()
guestNameStore.setGuestNameIfEmpty(message)
guestNameStore.addGuestName(message, { noUpdate: true })
}
context.dispatch('processMessage', message)
newestKnownMessageId = Math.max(newestKnownMessageId, message.id)
Expand Down Expand Up @@ -912,7 +912,7 @@ const actions = {
if (message.actorType === ATTENDEE.ACTOR_TYPE.GUESTS) {
// update guest display names cache
const guestNameStore = useGuestNameStore()
guestNameStore.setGuestNameIfEmpty(message)
guestNameStore.addGuestName(message, { noUpdate: true })
}
context.dispatch('processMessage', message)
newestKnownMessageId = Math.max(newestKnownMessageId, message.id)
Expand Down Expand Up @@ -1038,7 +1038,7 @@ const actions = {
// force in case the display name has changed since
// the last fetch
const guestNameStore = useGuestNameStore()
guestNameStore.forceGuestName(message)
guestNameStore.addGuestName(message, { noUpdate: false })
}
context.dispatch('processMessage', message)
if (!lastMessage || message.id > lastMessage.id) {
Expand Down
Loading

0 comments on commit 3ec33f8

Please sign in to comment.