From 80b94615980b7dd4282741f0699d6b60ca2f0c2a Mon Sep 17 00:00:00 2001 From: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com> Date: Tue, 23 Apr 2024 01:08:35 -0700 Subject: [PATCH] auto subscribe to user talk messages (#337) * auto subscribe to user talk messages - lets the AFC reviewer set a preference to auto subscribe to talk page messages AFCH posts for them - preference defaults to off - this is for user talk messages sent via accept, decline, reject, and comment Fixes #258 * comments * create preference * fix padding, fix linter error * debug * reduce code duplication * improve html/css, begin switching to discussiontoolsedit API * auto subscribe working now, except for an "error" in the status message * fully working * fix bug * fix bug --- src/less/general.less | 10 ++++++ src/modules/core.js | 51 ++++++++++++++++++++---------- src/templates/tpl-preferences.html | 5 +++ 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/less/general.less b/src/less/general.less index dc646f75..38a7a495 100644 --- a/src/less/general.less +++ b/src/less/general.less @@ -140,6 +140,7 @@ div.gradient-button, .gradient-button { .afch-preferences { label.afch-label { font-size: 1em; + padding: 0; } div + div { @@ -150,4 +151,13 @@ div.gradient-button, .gradient-button { .details { padding-bottom: 10px; } + + > div { + margin: 5px; + + > label, + > [input="checkbox"] { + display: inline; + } + } } diff --git a/src/modules/core.js b/src/modules/core.js index 69837ef5..37573092 100644 --- a/src/modules/core.js +++ b/src/modules/core.js @@ -610,12 +610,13 @@ * @param {Object} options Object with properties ('contents' is required, others are optional): * contents: {string} the text to add to/replace the page, * summary: {string} edit summary, will have the edit summary ad at the end, - * createonly: {bool} set to true to only edit the page if it doesn't exist, + * createonly: {boolean} set to true to only edit the page if it doesn't exist, * mode: {string} 'appendtext' or 'prependtext'; default: (replace everything) - * hide: {bool} Set to true to supress logging in statusWindow + * hide: {boolean} Set to true to supress logging in statusWindow * statusText: {string} message to show in status; default: "Editing" * followRedirects: {boolean} true to follow redirects, false to ignore redirects * watchlist: {string} 'nochange', 'preferences', 'unwatch', or 'watch' + * subscribe: {boolean} when appending a talk page section, whether or not to subscribe to it * @return {jQuery.Deferred} Resolves if saved with all data */ editPage: function ( pagename, options ) { @@ -637,13 +638,26 @@ status = AFCH.consts.nullstatus; } - request = { - action: 'edit', - text: options.contents, - title: pagename, - summary: options.summary + AFCH.consts.summaryAd, - redirect: options.followRedirects - }; + if ( !options.subscribe ) { + request = { + action: 'edit', + title: pagename, + text: options.contents, + summary: options.summary + AFCH.consts.summaryAd, + redirect: options.followRedirects + }; + } else { + // Because it is easier to do subscriptions with it, use the discussiontoolsedit API instead of the edit API + request = { + action: 'discussiontoolsedit', + paction: 'addtopic', + page: pagename, + sectiontitle: '', + wikitext: options.contents.trim(), + summary: options.summary + AFCH.consts.summaryAd, + autosubscribe: 'yes' + }; + } if ( pagename.indexOf( 'Draft:' ) === 0 ) { request.nocreate = 'true'; @@ -661,7 +675,7 @@ // Depending on mode, set appendtext=text or prependtext=text, // which overrides the default text option - if ( options.mode ) { + if ( !options.subscribe && options.mode ) { request[ options.mode ] = options.contents; } @@ -674,18 +688,21 @@ AFCH.api.postWithEditToken( request ) .done( function ( data ) { var $diffLink; + var api = options.subscribe ? 'discussiontoolsedit' : 'edit'; + // The success string is capitalized by one API and not the other + var success = options.subscribe ? 'success' : 'Success'; - if ( data && data.edit && data.edit.result && data.edit.result === 'Success' ) { + if ( data && data[ api ] && data[ api ].result && data[ api ].result === success ) { deferred.resolve( data ); - if ( data.edit.hasOwnProperty( 'nochange' ) ) { + if ( data[ api ].hasOwnProperty( 'nochange' ) ) { status.update( 'No changes made to $1' ); return; } // Create a link to the diff of the edit $diffLink = AFCH.makeLinkElementToPage( - 'Special:Diff/' + data.edit.oldrevid + '/' + data.edit.newrevid, '(diff)' + 'Special:Diff/' + data[ api ].newrevid, '(diff)' ).addClass( 'text-smaller' ); status.update( 'Saved $1 ' + AFCH.jQueryToHtml( $diffLink ) ); @@ -780,7 +797,7 @@ * @param {string} user * @param {Object} data object with properties * - message: {string} - * - summary: {string} + * - summary: {string} edit summary * - hide: {bool}, default false * @param options * @return {jQuery.Deferred} Resolves with success/failure @@ -796,7 +813,8 @@ mode: 'appendtext', statusText: 'Notifying', hide: options.hide, - followRedirects: true + followRedirects: true, + subscribe: AFCH.prefs.autoSubscribe } ) .done( function () { deferred.resolve(); @@ -1228,7 +1246,8 @@ logCsd: true, launchLinkPosition: 'p-cactions', logAfc: false, - noWatch: false + noWatch: false, + autoSubscribe: false }; /** diff --git a/src/templates/tpl-preferences.html b/src/templates/tpl-preferences.html index 55c16ccf..346f2151 100644 --- a/src/templates/tpl-preferences.html +++ b/src/templates/tpl-preferences.html @@ -29,6 +29,11 @@ +
+ + +
+