Skip to content

Commit

Permalink
Fix duplicate collaborator entries in collaboration panel (#422)
Browse files Browse the repository at this point in the history
* fix

* change set -> map

* make pre-commit hook happy
  • Loading branch information
nzinfo authored Jan 9, 2025
1 parent 06de054 commit c956eea
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/collaboration/src/collaboratorspanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,24 @@ export class CollaboratorsPanel extends Panel {
*/
private _onAwarenessChanged = () => {
const state = this._awareness.getStates() as any;
const collaborators: ICollaboratorAwareness[] = [];
const collaboratorsMap = new Map<string, ICollaboratorAwareness>();

state.forEach((value: Partial<ICollaboratorAwareness>, key: any) => {
if (
this._currentUser.isReady &&
value.user &&
value.user.username !== this._currentUser.identity!.username

Check warning on line 106 in packages/collaboration/src/collaboratorspanel.tsx

View workflow job for this annotation

GitHub Actions / Run pre-commit hook

Forbidden non-null assertion
) {
collaborators.push(value as ICollaboratorAwareness);
const uniqueKey = `${value.user.username}-${
value.current || 'no-current'
}`;
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;
Expand All @@ -132,9 +138,13 @@ export function CollaboratorsBody(props: {

return (
<div className={COLLABORATORS_LIST_CLASS}>
{collaborators.map((collaborator, i) => {
{collaborators.map(collaborator => {
const uniqueKey = `${collaborator.user.username}-${
collaborator.current || 'no-current'
}`;
return (
<Collaborator
key={uniqueKey}
collaborator={collaborator}
fileopener={props.fileopener}
docRegistry={props.docRegistry}
Expand Down

0 comments on commit c956eea

Please sign in to comment.