mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-11-15 10:59:42 +00:00
Merge "Simplify promise by using .then()"
This commit is contained in:
commit
7356c813a6
|
@ -8,32 +8,27 @@
|
|||
* @return {Promise} The thank operation's status.
|
||||
*/
|
||||
function thankUser( name, revision, recipientGender ) {
|
||||
var d = $.Deferred();
|
||||
( new mw.Api() ).postWithToken( 'csrf', {
|
||||
return ( new mw.Api() ).postWithToken( 'csrf', {
|
||||
action: 'thank',
|
||||
rev: revision,
|
||||
source: 'mobilediff'
|
||||
} ).done( function () {
|
||||
} ).then( function () {
|
||||
mw.notify( mw.msg( 'thanks-thanked-notice', name, recipientGender, mw.user ) );
|
||||
d.resolve();
|
||||
} )
|
||||
.fail( function ( errorCode ) {
|
||||
// FIXME: What is "popup" and where is it defined?
|
||||
/* eslint-disable no-undef */
|
||||
switch ( errorCode ) {
|
||||
case 'invalidrevision':
|
||||
popup.show( mw.msg( 'thanks-error-invalidrevision' ) );
|
||||
break;
|
||||
case 'ratelimited':
|
||||
popup.show( mw.msg( 'thanks-error-ratelimited', recipientGender ) );
|
||||
break;
|
||||
default:
|
||||
popup.show( mw.msg( 'thanks-error-undefined', errorCode ) );
|
||||
}
|
||||
/* eslint-enable no-undef */
|
||||
d.reject();
|
||||
} );
|
||||
return d;
|
||||
}, function ( errorCode ) {
|
||||
// FIXME: What is "popup" and where is it defined?
|
||||
/* eslint-disable no-undef */
|
||||
switch ( errorCode ) {
|
||||
case 'invalidrevision':
|
||||
popup.show( mw.msg( 'thanks-error-invalidrevision' ) );
|
||||
break;
|
||||
case 'ratelimited':
|
||||
popup.show( mw.msg( 'thanks-error-ratelimited', recipientGender ) );
|
||||
break;
|
||||
default:
|
||||
popup.show( mw.msg( 'thanks-error-undefined', errorCode ) );
|
||||
}
|
||||
/* eslint-enable no-undef */
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue