CollabTarget: remember current name, briefly

Change-Id: I2804f21c00b9224217d340948ca3c437f1b8b1a4
This commit is contained in:
David Lynch 2018-05-16 17:59:27 +02:00
parent 4f53736399
commit aab3c106df

View file

@ -111,7 +111,7 @@ ve.init.mw.CollabTarget.prototype.attachToolbar = function () {
* @inheritdoc * @inheritdoc
*/ */
ve.init.mw.CollabTarget.prototype.setSurface = function ( surface ) { ve.init.mw.CollabTarget.prototype.setSurface = function ( surface ) {
var synchronizer, surfaceView; var synchronizer, surfaceView, defaultName;
if ( surface !== this.surface ) { if ( surface !== this.surface ) {
this.$editableContent.after( surface.$element ); this.$editableContent.after( surface.$element );
@ -123,12 +123,22 @@ ve.init.mw.CollabTarget.prototype.setSurface = function ( surface ) {
this.title.toString(), this.title.toString(),
{ server: this.rebaserUrl } { server: this.rebaserUrl }
); );
synchronizer.on( 'authorNameChange', function ( authorId ) {
var newName = synchronizer.authorNames[ authorId ];
if ( authorId === synchronizer.getAuthorId() ) {
mw.storage.session.set( 've-collab-username', newName );
}
} );
// TODO: server could communicate with MW (via oauth?) to know the // TODO: server could communicate with MW (via oauth?) to know the
// current-user's name. Disable changing name if logged in? // current-user's name. Disable changing name if logged in?
// Communicate an I-am-a-valid-user flag to other clients? // Communicate an I-am-a-valid-user flag to other clients?
if ( !mw.user.isAnon() ) { defaultName = mw.storage.session.get( 've-collab-username' );
synchronizer.changeName( mw.user.getName() ); if ( !defaultName && !mw.user.isAnon() ) {
defaultName = mw.user.getName();
}
if ( defaultName ) {
synchronizer.changeName( defaultName );
} }
surfaceView.setSynchronizer( synchronizer ); surfaceView.setSynchronizer( synchronizer );