diff --git a/client/src/app/gateways/repositories/meeting_user/meeting-user-repository.service.ts b/client/src/app/gateways/repositories/meeting_user/meeting-user-repository.service.ts index a4b1f290c0..4498ec3608 100644 --- a/client/src/app/gateways/repositories/meeting_user/meeting-user-repository.service.ts +++ b/client/src/app/gateways/repositories/meeting_user/meeting-user-repository.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@angular/core'; +import { Id } from 'src/app/domain/definitions/key-types'; import { MeetingUser } from 'src/app/domain/models/meeting-users/meeting-user'; import { toDecimal } from 'src/app/infrastructure/utils'; import { ViewMeetingUser } from 'src/app/site/pages/meetings/view-models/view-meeting-user'; @@ -17,6 +18,8 @@ export type MeetingUserPatchFn = export class MeetingUserRepositoryService extends BaseMeetingRelatedRepository { public override readonly resetOnMeetingChange = false; + private meetingUserIdMap: Map> = new Map(); + public constructor(repositoryServiceCollector: RepositoryMeetingServiceCollectorService) { super(repositoryServiceCollector, MeetingUser); } @@ -66,4 +69,40 @@ export class MeetingUserRepositoryService extends BaseMeetingRelatedRepository viewUser.user?.getTitle() ?? `Unknown`; public getVerboseName = (plural = false): string => this.translate.instant(plural ? `Participants` : `Participant`); + + public getMeetingUserId(userId: Id, meetingId: Id): Id | null { + if (this.meetingUserIdMap.has(userId) && this.meetingUserIdMap.get(userId).has(meetingId)) { + return this.meetingUserIdMap.get(userId).get(meetingId); + } + + return null; + } + + public override deleteModels(ids: Id[]): void { + ids.forEach(id => { + const user = this.viewModelStore[id]; + if (user && user.user_id && user.meeting_id) { + const meetingUserId = this.meetingUserIdMap.get(user.user_id)?.get(user.meeting_id); + if (meetingUserId === user.id) { + this.meetingUserIdMap.get(user.user_id).delete(user.meeting_id); + } + } + }); + super.deleteModels(ids); + } + + protected override clearViewModelStore(): void { + super.clearViewModelStore(); + this.meetingUserIdMap = new Map(); + } + + protected override onCreateViewModel(meetingUser: ViewMeetingUser): void { + if (meetingUser.user_id && meetingUser.meeting_id) { + if (!this.meetingUserIdMap.has(meetingUser.user_id)) { + this.meetingUserIdMap.set(meetingUser.user_id, new Map()); + } + + this.meetingUserIdMap.get(meetingUser.user_id).set(meetingUser.meeting_id, meetingUser.id); + } + } } diff --git a/client/src/app/gateways/repositories/users/user-repository.service.ts b/client/src/app/gateways/repositories/users/user-repository.service.ts index 6aec725f71..d056099961 100644 --- a/client/src/app/gateways/repositories/users/user-repository.service.ts +++ b/client/src/app/gateways/repositories/users/user-repository.service.ts @@ -338,37 +338,17 @@ export class UserRepositoryService extends BaseRepository { protected override createViewModel(model: User): ViewUser { const viewModel = super.createViewModel(model); - const meetingUserIdMap = new Map(); - const getMeetingUserId = (meetingId: Id) => { - if (!meetingUserIdMap.has(meetingId)) { - const meetingUsers = this.relationManager.handleRelation( - viewModel.getModel(), - this.relationsByKey[`meeting_users`] - ); - - if (meetingUsers?.length) { - for (const meetingUser of meetingUsers) { - meetingUserIdMap.set(meetingUser.meeting_id, meetingUser.id); - } - } else { - for (const meetingUser of this.meetingUserRepo.getViewModelList()) { - if (meetingUser.user_id === model.id) { - meetingUserIdMap.set(meetingUser.meeting_id, meetingUser.id); - return meetingUser.id; - } - } - } - } - - return meetingUserIdMap.get(meetingId); - }; - - viewModel.getName = () => this.getName(viewModel); - viewModel.getShortName = () => this.getShortName(viewModel); - viewModel.getFullName = (structureLevel?: ViewStructureLevel) => this.getFullName(viewModel, structureLevel); - viewModel.getMeetingUser = (meetingId: Id) => this.getMeetingUser(getMeetingUserId, meetingId); - viewModel.getLevelAndNumber = () => this.getLevelAndNumber(viewModel); - viewModel.getEnsuredActiveMeetingId = () => this.activeMeetingIdService.meetingId; + viewModel.getName = (): string => this.getName(viewModel); + viewModel.getShortName = (): string => this.getShortName(viewModel); + viewModel.getFullName = (structureLevel?: ViewStructureLevel): string => + this.getFullName(viewModel, structureLevel); + viewModel.getMeetingUser = (meetingId: Id): ViewMeetingUser => + this.getMeetingUser( + (meetingId: Id): Id => this.meetingUserRepo.getMeetingUserId(model.id, meetingId), + meetingId + ); + viewModel.getLevelAndNumber = (): string => this.getLevelAndNumber(viewModel); + viewModel.getEnsuredActiveMeetingId = (): Id => this.activeMeetingIdService.meetingId; return viewModel; }