Fix showing temp user popup after page reload

Bug: T344879
Change-Id: I1bb86468c27d4fbbd55ebcdc81ec841fbfeeb952
This commit is contained in:
Bartosz Dziewoński 2023-08-24 17:36:44 +02:00 committed by Bartosz Dziewoński
parent 44f652aa82
commit c0f5a95504
3 changed files with 11 additions and 1 deletions

View file

@ -465,6 +465,7 @@ CommentController.prototype.save = function ( pageName ) {
data.returnto = pageName; data.returnto = pageName;
var params = new URLSearchParams(); var params = new URLSearchParams();
params.set( 'dtrepliedto', commentController.getThreadItem().id ); params.set( 'dtrepliedto', commentController.getThreadItem().id );
params.set( 'dttempusercreated', '1' );
data.returntoquery = params.toString(); data.returntoquery = params.toString();
} }

View file

@ -288,6 +288,7 @@ function getReplyWidgetModules( visual ) {
* @param {jQuery} $container Page container * @param {jQuery} $container Page container
* @param {Object<string,Mixed>} [state] Page state data object * @param {Object<string,Mixed>} [state] Page state data object
* @param {string} [state.repliedTo] The comment ID that was just replied to * @param {string} [state.repliedTo] The comment ID that was just replied to
* @param {boolean} [state.tempUserCreated] Whether a temp user was just created
*/ */
function init( $container, state ) { function init( $container, state ) {
var var
@ -516,10 +517,12 @@ function init( $container, state ) {
if ( state.repliedTo === utils.NEW_TOPIC_COMMENT_ID ) { if ( state.repliedTo === utils.NEW_TOPIC_COMMENT_ID ) {
mw.hook( 'postEdit' ).fire( { mw.hook( 'postEdit' ).fire( {
tempUserCreated: state.tempUserCreated,
message: mw.msg( 'discussiontools-postedit-confirmation-topicadded', mw.user ) message: mw.msg( 'discussiontools-postedit-confirmation-topicadded', mw.user )
} ); } );
} else { } else {
mw.hook( 'postEdit' ).fire( { mw.hook( 'postEdit' ).fire( {
tempUserCreated: state.tempUserCreated,
message: mw.msg( 'discussiontools-postedit-confirmation-published', mw.user ) message: mw.msg( 'discussiontools-postedit-confirmation-published', mw.user )
} ); } );
} }
@ -686,7 +689,10 @@ function update( data, threadItem, pageName, replyWidget ) {
replyWidget.unbindBeforeUnloadHandler(); replyWidget.unbindBeforeUnloadHandler();
replyWidget.clearStorage(); replyWidget.clearStorage();
replyWidget.setPending( true ); replyWidget.setPending( true );
window.location = data.tempusercreatedredirect || mw.util.getUrl( pageName, { dtrepliedto: threadItem.id } ); window.location = data.tempusercreatedredirect || mw.util.getUrl( pageName, {
dtrepliedto: threadItem.id,
dttempusercreated: '1'
} );
logSaveSuccess(); logSaveSuccess();
return; return;
} }
@ -696,6 +702,7 @@ function update( data, threadItem, pageName, replyWidget ) {
// Highlight the new reply after re-initializing // Highlight the new reply after re-initializing
mw.dt.initState.repliedTo = threadItem.id; mw.dt.initState.repliedTo = threadItem.id;
mw.dt.initState.tempUserCreated = data.tempusercreated;
// Update page state // Update page state
var pageUpdated = $.Deferred(); var pageUpdated = $.Deferred();

View file

@ -22,8 +22,10 @@ if ( url.searchParams.get( 'dtrepliedto' ) ) {
// If we had to reload the page to highlight the new comment, extract that data from the URL and // If we had to reload the page to highlight the new comment, extract that data from the URL and
// clean it up. // clean it up.
mw.dt.initState.repliedTo = url.searchParams.get( 'dtrepliedto' ); mw.dt.initState.repliedTo = url.searchParams.get( 'dtrepliedto' );
mw.dt.initState.tempUserCreated = url.searchParams.has( 'dttempusercreated' );
if ( window.history.replaceState ) { if ( window.history.replaceState ) {
url.searchParams.delete( 'dtrepliedto' ); url.searchParams.delete( 'dtrepliedto' );
url.searchParams.delete( 'dttempusercreated' );
window.history.replaceState( {}, '', url ); window.history.replaceState( {}, '', url );
} }
} }