Skip to content

Commit

Permalink
auto subscribe to user talk messages (#337)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
NovemLinguae authored Apr 23, 2024
1 parent 3339f99 commit 80b9461
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
10 changes: 10 additions & 0 deletions src/less/general.less
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ div.gradient-button, .gradient-button {
.afch-preferences {
label.afch-label {
font-size: 1em;
padding: 0;
}

div + div {
Expand All @@ -150,4 +151,13 @@ div.gradient-button, .gradient-button {
.details {
padding-bottom: 10px;
}

> div {
margin: 5px;

> label,
> [input="checkbox"] {
display: inline;
}
}
}
51 changes: 35 additions & 16 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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';
Expand All @@ -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;
}

Expand All @@ -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 ) );
Expand Down Expand Up @@ -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
Expand All @@ -796,7 +813,8 @@
mode: 'appendtext',
statusText: 'Notifying',
hide: options.hide,
followRedirects: true
followRedirects: true,
subscribe: AFCH.prefs.autoSubscribe
} )
.done( function () {
deferred.resolve();
Expand Down Expand Up @@ -1228,7 +1246,8 @@
logCsd: true,
launchLinkPosition: 'p-cactions',
logAfc: false,
noWatch: false
noWatch: false,
autoSubscribe: false
};

/**
Expand Down
5 changes: 5 additions & 0 deletions src/templates/tpl-preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<label for="noWatch" class="afch-label">Do not add pages to watchlist</label>
<input type="checkbox" id="noWatch" class="afch-input" {{#noWatch}}checked{{/noWatch}} />
</div>
<div id="autoSubscribeWrapper">
<label for="autoSubscribe" class="afch-label"><a href="https://www.mediawiki.org/wiki/Help:DiscussionTools#Topic_subscriptions" target="_blank">Receive a notification</a> when a draft author replies to a user talk message you left them</label>
<input type="checkbox" id="autoSubscribe" class="afch-input" {{#autoSubscribe}}checked{{/autoSubscribe}} />
</div>
<!-- When adding new preferences, don't forget to update core.js prefDefaults -->
</div>
<!-- /preferences -->

Expand Down

0 comments on commit 80b9461

Please sign in to comment.