From c0f5a9550495e4f0cd0a2dc350ecf9958936cbdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 24 Aug 2023 17:36:44 +0200 Subject: [PATCH] Fix showing temp user popup after page reload Bug: T344879 Change-Id: I1bb86468c27d4fbbd55ebcdc81ec841fbfeeb952 --- modules/CommentController.js | 1 + modules/controller.js | 9 ++++++++- modules/dt.init.js | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/CommentController.js b/modules/CommentController.js index 7de18a3bd..314ce54ec 100644 --- a/modules/CommentController.js +++ b/modules/CommentController.js @@ -465,6 +465,7 @@ CommentController.prototype.save = function ( pageName ) { data.returnto = pageName; var params = new URLSearchParams(); params.set( 'dtrepliedto', commentController.getThreadItem().id ); + params.set( 'dttempusercreated', '1' ); data.returntoquery = params.toString(); } diff --git a/modules/controller.js b/modules/controller.js index 419199aed..329d2a585 100644 --- a/modules/controller.js +++ b/modules/controller.js @@ -288,6 +288,7 @@ function getReplyWidgetModules( visual ) { * @param {jQuery} $container Page container * @param {Object} [state] Page state data object * @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 ) { var @@ -516,10 +517,12 @@ function init( $container, state ) { if ( state.repliedTo === utils.NEW_TOPIC_COMMENT_ID ) { mw.hook( 'postEdit' ).fire( { + tempUserCreated: state.tempUserCreated, message: mw.msg( 'discussiontools-postedit-confirmation-topicadded', mw.user ) } ); } else { mw.hook( 'postEdit' ).fire( { + tempUserCreated: state.tempUserCreated, message: mw.msg( 'discussiontools-postedit-confirmation-published', mw.user ) } ); } @@ -686,7 +689,10 @@ function update( data, threadItem, pageName, replyWidget ) { replyWidget.unbindBeforeUnloadHandler(); replyWidget.clearStorage(); 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(); return; } @@ -696,6 +702,7 @@ function update( data, threadItem, pageName, replyWidget ) { // Highlight the new reply after re-initializing mw.dt.initState.repliedTo = threadItem.id; + mw.dt.initState.tempUserCreated = data.tempusercreated; // Update page state var pageUpdated = $.Deferred(); diff --git a/modules/dt.init.js b/modules/dt.init.js index 3a41b4451..ee59b01e8 100644 --- a/modules/dt.init.js +++ b/modules/dt.init.js @@ -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 // clean it up. mw.dt.initState.repliedTo = url.searchParams.get( 'dtrepliedto' ); + mw.dt.initState.tempUserCreated = url.searchParams.has( 'dttempusercreated' ); if ( window.history.replaceState ) { url.searchParams.delete( 'dtrepliedto' ); + url.searchParams.delete( 'dttempusercreated' ); window.history.replaceState( {}, '', url ); } }