Skip to content

Commit c956eea

Browse files
authored
Fix duplicate collaborator entries in collaboration panel (#422)
* fix * change set -> map * make pre-commit hook happy
1 parent 06de054 commit c956eea

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

packages/collaboration/src/collaboratorspanel.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,24 @@ export class CollaboratorsPanel extends Panel {
9797
*/
9898
private _onAwarenessChanged = () => {
9999
const state = this._awareness.getStates() as any;
100-
const collaborators: ICollaboratorAwareness[] = [];
100+
const collaboratorsMap = new Map<string, ICollaboratorAwareness>();
101101

102102
state.forEach((value: Partial<ICollaboratorAwareness>, key: any) => {
103103
if (
104104
this._currentUser.isReady &&
105105
value.user &&
106106
value.user.username !== this._currentUser.identity!.username
107107
) {
108-
collaborators.push(value as ICollaboratorAwareness);
108+
const uniqueKey = `${value.user.username}-${
109+
value.current || 'no-current'
110+
}`;
111+
if (!collaboratorsMap.has(uniqueKey)) {
112+
collaboratorsMap.set(uniqueKey, value as ICollaboratorAwareness);
113+
}
109114
}
110115
});
111-
this._collaboratorsChanged.emit(collaborators);
116+
// Convert map to array to maintain the same emit interface
117+
this._collaboratorsChanged.emit(Array.from(collaboratorsMap.values()));
112118
};
113119
private _currentUser: User.IManager;
114120
private _awareness: Awareness;
@@ -132,9 +138,13 @@ export function CollaboratorsBody(props: {
132138

133139
return (
134140
<div className={COLLABORATORS_LIST_CLASS}>
135-
{collaborators.map((collaborator, i) => {
141+
{collaborators.map(collaborator => {
142+
const uniqueKey = `${collaborator.user.username}-${
143+
collaborator.current || 'no-current'
144+
}`;
136145
return (
137146
<Collaborator
147+
key={uniqueKey}
138148
collaborator={collaborator}
139149
fileopener={props.fileopener}
140150
docRegistry={props.docRegistry}

0 commit comments

Comments
 (0)