Skip to content

Commit

Permalink
improve html/css, begin switching to discussiontoolsedit API
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae committed Apr 16, 2024
1 parent 816ed73 commit a30ad5b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 49 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;
}
}
}
53 changes: 7 additions & 46 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,64 +788,25 @@
notifyUser: function ( user, options ) {
var userTalkPage = new AFCH.Page( new mw.Title( user, 3 ).getPrefixedText() ); // 3 = user talk namespace

/*
var promise = userTalkPage.exists().then( function ( exists ) {
userTalkPage.edit( {
contents: ( exists ? '' : '{{Talk header}}' ) + '\n\n' + options.message,
AFCH.api.postWithToken( 'csrf', {
action: 'discussiontoolsedit',
page: userTalkPage.rawTitle,
summary:
wikitext: ( exists ? '' : '{{Talk header}}' ) + '\n\n' + options.message,
summary: options.summary || 'Notifying user',
mode: 'appendtext',
statusText: 'Notifying',
hide: options.hide,
followRedirects: true
} ).then( AFCH.actions.subscribeToBottomSection( user ) );
} );
*/

return promise;
},

subscribeToBottomSection: function ( submitter ) {
if ( !AFCH.prefs.autoSubscribe ) {
return;
}

// Figure out the DiscussionTools ID of the section we want to subscribe to
var talkPage = 'User talk:' + submitter;
AFCH.api.get( {
action: 'discussiontoolspageinfo',
format: 'json',
page: talkPage,
formatversion: 2
} ).then( function ( json ) {
debugger;

var transcludedFrom = json.discussiontoolspageinfo.transcludedfrom;
transcludedFrom = Object.keys( transcludedFrom );
var commentName = '';
// Iterate from the bottom up, until a string beginning with "h-" is found. This is our user talk section that we just created.
for ( var i = transcludedFrom.length; i > 0; i-- ) {
var value = transcludedFrom[ i - 1 ];
if ( value.indexOf( 'h-' ) === 0 ) {
commentName = value;
break;
}
}

debugger;

// Subscribe to that DiscussionTools section ID
AFCH.api.post( {
action: 'discussiontoolssubscribe',
format: 'json',
formatversion: 2,
page: talkPage,
commentname: commentName,
subscribe: true
} ).then( function ( json ) {
debugger;
console.log( json );
} );
} );
},

/**
* Logs a CSD nomination
*
Expand Down
5 changes: 2 additions & 3 deletions src/templates/tpl-preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
<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 <input type="checkbox" id="autoSubscribe" class="afch-input" {{#autoSubscribe}}checked{{/autoSubscribe}} />
</label>
<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>
Expand Down

0 comments on commit a30ad5b

Please sign in to comment.