@@ -97,18 +97,24 @@ export class CollaboratorsPanel extends Panel {
97
97
*/
98
98
private _onAwarenessChanged = ( ) => {
99
99
const state = this . _awareness . getStates ( ) as any ;
100
- const collaborators : ICollaboratorAwareness [ ] = [ ] ;
100
+ const collaboratorsMap = new Map < string , ICollaboratorAwareness > ( ) ;
101
101
102
102
state . forEach ( ( value : Partial < ICollaboratorAwareness > , key : any ) => {
103
103
if (
104
104
this . _currentUser . isReady &&
105
105
value . user &&
106
106
value . user . username !== this . _currentUser . identity ! . username
107
107
) {
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
+ }
109
114
}
110
115
} ) ;
111
- this . _collaboratorsChanged . emit ( collaborators ) ;
116
+ // Convert map to array to maintain the same emit interface
117
+ this . _collaboratorsChanged . emit ( Array . from ( collaboratorsMap . values ( ) ) ) ;
112
118
} ;
113
119
private _currentUser : User . IManager ;
114
120
private _awareness : Awareness ;
@@ -132,9 +138,13 @@ export function CollaboratorsBody(props: {
132
138
133
139
return (
134
140
< 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
+ } `;
136
145
return (
137
146
< Collaborator
147
+ key = { uniqueKey }
138
148
collaborator = { collaborator }
139
149
fileopener = { props . fileopener }
140
150
docRegistry = { props . docRegistry }
0 commit comments