Kaldari has uploaded a new change for review. https://gerrit.wikimedia.org/r/107633
Change subject: Story 1604: Remember mobile thanks ...................................................................... Story 1604: Remember mobile thanks After someone thanks a user, have it remember the revision in a cookie. If the user has already been thanked, make the button greyed out and display the text "Thanked" instead of "Thank". Bug: 59828 Change-Id: Ifab78fe62910c9c3f2a927a6a4bbe28fb953b160 --- M Thanks.php M modules/ext.thanks.mobilediff.js 2 files changed, 61 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks refs/changes/33/107633/1 diff --git a/Thanks.php b/Thanks.php index 4d703e9..9bc81b6 100644 --- a/Thanks.php +++ b/Thanks.php @@ -87,6 +87,7 @@ 'mediawiki.api', 'user.tokens', 'jquery.ui.dialog', + 'jquery.cookie', ), 'localBasePath' => $dir . '/modules', 'remoteExtPath' => 'Thanks/modules', @@ -94,6 +95,7 @@ $wgResourceModules['ext.thanks.mobilediff'] = array( 'dependencies' => array( 'mobile.mobilediff.scripts', + 'jquery.cookie', ), 'scripts' => array( 'ext.thanks.mobilediff.js', diff --git a/modules/ext.thanks.mobilediff.js b/modules/ext.thanks.mobilediff.js index f8add6a..b0142c9 100644 --- a/modules/ext.thanks.mobilediff.js +++ b/modules/ext.thanks.mobilediff.js @@ -3,17 +3,48 @@ popup = M.require( 'toast' ), schema = M.require( 'loggingSchemas/MobileWebClickTracking' ); - function thankUser( name, revision, gender ) { + // Keep track of which revisions the user has already thanked for + var thanked = { + maxHistory: 100, + load: function() { + var cookie = $.cookie( 'thanks-thanked' ); + if ( cookie === null ) { + return []; + } + return unescape( cookie ).split( ',' ); + }, + push: function( rev ) { + var saved = this.load(); + saved.push( rev ); + // Prevent cookie from growing forever + if ( saved.length > this.maxHistory ) { + saved = saved.slice( saved.length - this.maxHistory ); + } + $.cookie( 'thanks-thanked', escape( saved.join( ',' ) ) ); + }, + contains: function( rev ) { + if ( $.inArray( rev.toString(), this.load() ) !== -1 ) { + return true; + } else { + return false; + } + } + }; + + function thankUser( name, rev, gender ) { var d = $.Deferred(); api.getToken( 'edit' ).done( function( token ) { api.get( { 'action' : 'thank', - 'rev' : revision, + 'rev' : rev, 'source' : 'mobilediff', 'token' : token } ) .done( function() { + // Show pop-up notification that sending thanks was successful popup.show( mw.msg( 'thanks-thanked-notice', name, gender ) ); + // Remember that user has been thanked for this edit + thanked.push( rev ); d.resolve(); } ) .fail( function( errorCode ) { @@ -41,25 +72,34 @@ * @param gender String The gender of the user who made the edit */ function createThankLink( name, rev, gender ) { - var thankImg = mw.config.get( 'wgExtensionAssetsPath' ) + '/Thanks/WhiteSmiley.png'; + var thankImg = mw.config.get( 'wgExtensionAssetsPath' ) + '/Thanks/WhiteSmiley.png', + thankImgTag = '<img width="25" height="20" src="' + thankImg + '" class="mw-mf-action-button-icon"/>', + $thankBtn; // Don't make thank button for self if ( name !== mw.config.get( 'wgUserName' ) ) { - return $( '<button class="mw-mf-action-button">' ) - .html( '<img width="25" height="20" src="' + thankImg + '" class="mw-mf-action-button-icon"/>' + - mw.message( 'thanks-button-thank', mw.user ).escaped() - ) - .on( 'click', function() { - var $thankLink = $( this ); - schema.log( 'diff-thank', name ); - if ( !$thankLink.hasClass( 'thanked' ) ) { - thankUser( name, rev, gender ).done( function() { - $thankLink.addClass( 'thanked' ).attr( 'disabled', true ); - $thankLink.html( '<img width="25" height="20" src="' + thankImg + '" class="mw-mf-action-button-icon"/>' + - mw.message( 'thanks-button-thanked', mw.user ).escaped() - ); - } ); - } - } ); + // See if user has already been thanked for this edit + if ( thanked.contains( rev ) ) { + $thankBtn = $( '<button class="mw-mf-action-button thanked">' ) + .attr( 'disabled', true ) + .html( thankImgTag + mw.message( 'thanks-button-thanked', mw.user ).escaped() + ); + } else { + $thankBtn = $( '<button class="mw-mf-action-button">' ) + .html( thankImgTag + mw.message( 'thanks-button-thank', mw.user ).escaped() + ) + .on( 'click', function() { + var $this = $( this ); + schema.log( 'diff-thank', name ); + if ( !$this.hasClass( 'thanked' ) ) { + thankUser( name, rev, gender ).done( function() { + $this.addClass( 'thanked' ).attr( 'disabled', true ) + .html( thankImgTag + mw.message( 'thanks-button-thanked', mw.user ).escaped() + ); + } ); + } + } ); + } + return $thankBtn; } } -- To view, visit https://gerrit.wikimedia.org/r/107633 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifab78fe62910c9c3f2a927a6a4bbe28fb953b160 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Thanks Gerrit-Branch: master Gerrit-Owner: Kaldari <rkald...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits