From 647317e8f658c82b6f6c3a592f211a93538a3614 Mon Sep 17 00:00:00 2001 From: nzinfo Date: Thu, 2 Jan 2025 00:54:00 +0800 Subject: [PATCH 1/3] fix --- packages/collaboration/src/collaboratorspanel.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/collaboration/src/collaboratorspanel.tsx b/packages/collaboration/src/collaboratorspanel.tsx index 92dc78bb..90186436 100644 --- a/packages/collaboration/src/collaboratorspanel.tsx +++ b/packages/collaboration/src/collaboratorspanel.tsx @@ -98,14 +98,19 @@ export class CollaboratorsPanel extends Panel { private _onAwarenessChanged = () => { const state = this._awareness.getStates() as any; const collaborators: ICollaboratorAwareness[] = []; - + const collaborators_keys: Set = new Set(); state.forEach((value: Partial, key: any) => { if ( this._currentUser.isReady && value.user && value.user.username !== this._currentUser.identity!.username ) { - collaborators.push(value as ICollaboratorAwareness); + const uniqueKey = `${value.user.username}-${value.current || 'no-current'}`; + + if (!collaborators_keys.has(uniqueKey)) { + collaborators.push(value as ICollaboratorAwareness); + collaborators_keys.add(uniqueKey); + } } }); this._collaboratorsChanged.emit(collaborators); @@ -132,9 +137,11 @@ export function CollaboratorsBody(props: { return (
- {collaborators.map((collaborator, i) => { + {collaborators.map((collaborator) => { + const uniqueKey = `${collaborator.user.username}-${collaborator.current || 'no-current'}`; return ( Date: Wed, 8 Jan 2025 17:02:12 +0800 Subject: [PATCH 2/3] change set -> map --- packages/collaboration/src/collaboratorspanel.tsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/collaboration/src/collaboratorspanel.tsx b/packages/collaboration/src/collaboratorspanel.tsx index 90186436..2d69c67d 100644 --- a/packages/collaboration/src/collaboratorspanel.tsx +++ b/packages/collaboration/src/collaboratorspanel.tsx @@ -97,8 +97,8 @@ export class CollaboratorsPanel extends Panel { */ private _onAwarenessChanged = () => { const state = this._awareness.getStates() as any; - const collaborators: ICollaboratorAwareness[] = []; - const collaborators_keys: Set = new Set(); + const collaboratorsMap = new Map(); + state.forEach((value: Partial, key: any) => { if ( this._currentUser.isReady && @@ -106,14 +106,13 @@ export class CollaboratorsPanel extends Panel { value.user.username !== this._currentUser.identity!.username ) { const uniqueKey = `${value.user.username}-${value.current || 'no-current'}`; - - if (!collaborators_keys.has(uniqueKey)) { - collaborators.push(value as ICollaboratorAwareness); - collaborators_keys.add(uniqueKey); + if (!collaboratorsMap.has(uniqueKey)) { + collaboratorsMap.set(uniqueKey, value as ICollaboratorAwareness); } } }); - this._collaboratorsChanged.emit(collaborators); + // Convert map to array to maintain the same emit interface + this._collaboratorsChanged.emit(Array.from(collaboratorsMap.values())); }; private _currentUser: User.IManager; private _awareness: Awareness; From 51bf4a08d2cdd330bb3b1fb9a19c829fe2e7796c Mon Sep 17 00:00:00 2001 From: nzinfo Date: Wed, 8 Jan 2025 23:39:52 +0800 Subject: [PATCH 3/3] make pre-commit hook happy --- packages/collaboration/src/collaboratorspanel.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/collaboration/src/collaboratorspanel.tsx b/packages/collaboration/src/collaboratorspanel.tsx index 2d69c67d..a3746178 100644 --- a/packages/collaboration/src/collaboratorspanel.tsx +++ b/packages/collaboration/src/collaboratorspanel.tsx @@ -105,7 +105,9 @@ export class CollaboratorsPanel extends Panel { value.user && value.user.username !== this._currentUser.identity!.username ) { - const uniqueKey = `${value.user.username}-${value.current || 'no-current'}`; + const uniqueKey = `${value.user.username}-${ + value.current || 'no-current' + }`; if (!collaboratorsMap.has(uniqueKey)) { collaboratorsMap.set(uniqueKey, value as ICollaboratorAwareness); } @@ -136,8 +138,10 @@ export function CollaboratorsBody(props: { return (
- {collaborators.map((collaborator) => { - const uniqueKey = `${collaborator.user.username}-${collaborator.current || 'no-current'}`; + {collaborators.map(collaborator => { + const uniqueKey = `${collaborator.user.username}-${ + collaborator.current || 'no-current' + }`; return (