Skip to content

Commit ed74f1b

Browse files
committed
ve.collab: fix remote selection logic
Bug: T387989 Change-Id: Idecd50734eb6713d0f4f79c0d483eb1c928a2177
1 parent ec8e8cf commit ed74f1b

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

collab/ve.collab.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,14 @@ ve.collab.initPeerClient = function ( serverId, isMain, userName ) {
131131
ve.collab.connectModelSynchronizer = function () {
132132
const ceSurface = ve.init.target.surface.view;
133133
ceSurface.model.synchronizer.connect( ceSurface, {
134-
authorSelect: 'onSynchronizerAuthorUpdate',
135-
authorChange: 'onSynchronizerAuthorUpdate',
136-
authorDisconnect: 'onSynchronizerAuthorDisconnect',
137134
wrongDoc: 'onSynchronizerWrongDoc',
138135
pause: 'onSynchronizerPause'
139136
} );
137+
ceSurface.model.synchronizer.connect( ceSurface.getSelectionManager(), {
138+
authorSelect: 'onSynchronizerAuthorUpdate',
139+
authorChange: 'onSynchronizerAuthorUpdate',
140+
authorDisconnect: 'onSynchronizerAuthorDisconnect'
141+
} );
140142
};
141143

142144
ve.collab.join = function () {

rebaser/src/dm/ve.dm.ProtocolServer.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -180,28 +180,19 @@ ve.dm.ProtocolServer.prototype.onSubmitChange = function ( context, data ) {
180180
* Apply and broadcast an author change
181181
*
182182
* @param {Object} context The connection context
183-
* @param {string} newData The new author data
183+
* @param {Object} newData The new author data
184184
*/
185185
ve.dm.ProtocolServer.prototype.onChangeAuthor = function ( context, newData ) {
186-
this.rebaseServer.updateDocState( context.docName, context.authorId, null, {
187-
name: newData.name,
188-
color: newData.color
189-
} );
186+
this.rebaseServer.updateDocState( context.docName, context.authorId, null, newData );
190187
context.broadcast( 'authorChange', {
191188
authorId: context.authorId,
192-
authorData: {
193-
name: newData.name,
194-
color: newData.color
195-
}
189+
authorData: newData
196190
} );
197191
this.logger.logServerEvent( {
198192
type: 'authorChange',
199193
doc: context.docName,
200194
authorId: context.authorId,
201-
authorData: {
202-
name: newData.name,
203-
color: newData.color
204-
}
195+
authorData: newData
205196
} );
206197
};
207198

src/dm/ve.dm.SurfaceSynchronizer.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,15 @@ ve.dm.SurfaceSynchronizer.prototype.getAuthorData = function ( authorId ) {
375375
};
376376

377377
ve.dm.SurfaceSynchronizer.prototype.onAuthorChange = function ( data ) {
378-
this.authors[ data.authorId ] = data.authorData;
378+
let authorData = this.authors[ data.authorId ];
379+
if ( authorData === undefined ) {
380+
authorData = Object.create( null );
381+
this.authors[ data.authorId ] = authorData;
382+
}
383+
Object.keys( data.authorData ).forEach( ( key ) => {
384+
authorData[ key ] = data.authorData[ key ];
385+
} );
379386
this.emit( 'authorChange', data.authorId );
380-
381387
if ( data.authorId === this.getAuthorId() ) {
382388
ve.init.platform.sessionStorage.setObject( 've-collab-author', data.authorData );
383389
}

src/ui/tools/ve.ui.AuthorListPopupTool.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ ve.ui.AuthorListPopupTool.prototype.onSynchronizerAuthorUpdate = function ( auth
170170
}
171171
}
172172
}
173-
this.oldName = this.synchronizer.getAuthorData( authorId ).name;
173+
const authorData = this.synchronizer.getAuthorData( authorId );
174+
this.oldName = authorData ? authorData.name : '';
174175
};
175176

176177
/**

src/ui/widgets/ve.ui.AuthorItemWidget.js

+3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ ve.ui.AuthorItemWidget.prototype.setAuthorId = function ( authorId ) {
122122
*/
123123
ve.ui.AuthorItemWidget.prototype.update = function () {
124124
const authorData = this.synchronizer.getAuthorData( this.authorId );
125+
if ( !authorData ) {
126+
return;
127+
}
125128
this.name = authorData.name;
126129
this.color = authorData.color;
127130
this.$color.css( 'background-color', '#' + this.color );

0 commit comments

Comments
 (0)