Start using edit api results for watchlist UI updates

This patch starts using watchlist related values from ApiEditPage
results instead of updating the "watch link" based on whether the
checkbox was selected or not at the time of saving the article.

This change does not depend on T261030 and can be merged without it
but T261030 needs to be fixed or temporarily watched items will not
display the right tooltip when hovering the "watch link" or star icon.

Bug: T260434
Change-Id: I2c844223620d7d28f36a0cd8ae3dee4b0c8ae5bf
This commit is contained in:
Dayllan Maza 2020-08-24 16:45:04 -04:00 committed by Esanders
parent dd95e88589
commit 4fc73112ee
2 changed files with 7 additions and 3 deletions

View file

@ -451,6 +451,8 @@ class ApiVisualEditorEdit extends ApiBase {
$result['newrevid'] = intval( $saveresult['edit']['newrevid'] );
}
$result['watched'] = $saveresult['edit']['watched'] ?? false;
$result['watchlistexpiry'] = $saveresult['edit']['watchlistexpiry'] ?? null;
$result['result'] = 'success';
}
}

View file

@ -903,7 +903,7 @@ ve.init.mw.DesktopArticleTarget.prototype.onViewTabClick = function ( e ) {
* @inheritdoc
*/
ve.init.mw.DesktopArticleTarget.prototype.saveComplete = function ( data ) {
var newUrlParams, watchChecked, watch,
var newUrlParams, watch,
target = this;
// Parent method
@ -926,10 +926,12 @@ ve.init.mw.DesktopArticleTarget.prototype.saveComplete = function ( data ) {
// User logged in if module loaded.
if ( mw.loader.getState( 'mediawiki.page.watch.ajax' ) === 'ready' ) {
watch = require( 'mediawiki.page.watch.ajax' );
watchChecked = this.checkboxesByName.wpWatchthis && this.checkboxesByName.wpWatchthis.isSelected();
watch.updateWatchLink(
$( '#ca-watch a, #ca-unwatch a' ),
watchChecked ? 'unwatch' : 'watch'
data.watched ? 'unwatch' : 'watch',
'idle',
data.watchlistexpiry
);
}