Merge "Wait for API response before updating suggestion list"

This commit is contained in:
jenkins-bot 2020-07-02 16:38:49 +00:00 committed by Gerrit Code Review
commit 92481deeac

View file

@ -60,18 +60,19 @@ MWUsernameCompletionAction.prototype.insertAndOpen = function () {
}; };
MWUsernameCompletionAction.prototype.getSuggestions = function ( input ) { MWUsernameCompletionAction.prototype.getSuggestions = function ( input ) {
var capitalizedInput = input.length > 0 && input[ 0 ].toUpperCase() + input.slice( 1 ), var apiPromise,
capitalizedInput = input.length > 0 && input[ 0 ].toUpperCase() + input.slice( 1 ),
action = this; action = this;
this.api.abort(); // Abort all unfinished API requests this.api.abort(); // Abort all unfinished API requests
if ( capitalizedInput && !this.searchedPrefixes[ capitalizedInput ] ) { if ( capitalizedInput && !this.searchedPrefixes[ capitalizedInput ] ) {
this.api.get( { apiPromise = this.api.get( {
action: 'query', action: 'query',
list: 'allusers', list: 'allusers',
// Prefix of list=allusers is case sensitive, and users are stored in the DB capitalized, so: // Prefix of list=allusers is case sensitive, and users are stored in the DB capitalized, so:
auprefix: capitalizedInput, auprefix: capitalizedInput,
aulimit: this.limit aulimit: this.limit
} ).done( function ( response ) { } ).then( function ( response ) {
var suggestions = response.query.allusers.map( function ( user ) { var suggestions = response.query.allusers.map( function ( user ) {
return user.name; return user.name;
} ).filter( function ( username ) { } ).filter( function ( username ) {
@ -85,23 +86,25 @@ MWUsernameCompletionAction.prototype.getSuggestions = function ( input ) {
action.searchedPrefixes[ capitalizedInput ] = true; action.searchedPrefixes[ capitalizedInput ] = true;
} ); } );
} else {
apiPromise = ve.createDeferred().resolve().promise();
} }
return ve.createDeferred().resolve( return apiPromise.then( function () {
// By concatenating on-thread authors and remote-fetched authors, both // By concatenating on-thread authors and remote-fetched authors, both
// sorted alphabetically, we'll get our suggestion popup sorted so all // sorted alphabetically, we'll get our suggestion popup sorted so all
// on-thread matches come first. // on-thread matches come first.
this.filterSuggestionsForInput( return action.filterSuggestionsForInput(
this.localUsers action.localUsers
// Show no remote users if no input provided // Show no remote users if no input provided
.concat( capitalizedInput ? this.remoteUsers : [] ), .concat( capitalizedInput ? action.remoteUsers : [] ),
// TODO: Consider showing IP users // TODO: Consider showing IP users
// * Change link to Special:Contributions/<ip> (localised) // * Change link to Special:Contributions/<ip> (localised)
// * Let users know that mentioning an IP will not create a notification? // * Let users know that mentioning an IP will not create a notification?
// .concat( this.ipUsers ) // .concat( this.ipUsers )
input input
) );
).promise(); } );
}; };
MWUsernameCompletionAction.prototype.insertCompletion = function ( word, range ) { MWUsernameCompletionAction.prototype.insertCompletion = function ( word, range ) {