From 3274b0c9df2ecc6eef8c4db94c8954eee3bfcaa2 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Tue, 3 Mar 2020 13:25:14 +0000 Subject: [PATCH] Move edit conflict retry code to controller Change-Id: Id14e93624d1828253402c04c97193fd686f67d9f --- modules/controller.js | 27 ++++++++++++++++++++++++++- modules/dt.ui.ReplyWidget.js | 24 ------------------------ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/modules/controller.js b/modules/controller.js index 1445dd165..7d91ba3a1 100644 --- a/modules/controller.js +++ b/modules/controller.js @@ -143,7 +143,32 @@ function postReply( widget, parsoidData ) { // This appears redundant currently, but as editing / new-topics get added, we'll expand it dttags: [ 'discussiontools', 'discussiontools-reply', 'discussiontools-' + widget.mode ].join( ',' ) } - ); + ).catch( function ( code, data ) { + // Handle edit conflicts. Load the latest revision of the page, then try again. If the parent + // comment has been deleted from the page, or if retry also fails for some other reason, the + // error is handled as normal below. + if ( code === 'editconflict' ) { + return widget.api.get( { + action: 'query', + prop: 'revisions', + rvprop: 'ids', + rvlimit: 1, + titles: mw.config.get( 'wgRelevantPageName' ), + formatversion: 2 + } ).then( function ( resp ) { + var latestRevId = resp.query.pages[ 0 ].revisions[ 0 ].revid; + mw.config.set( { + wgCurRevisionId: latestRevId, + wgRevisionId: latestRevId + } ); + // eslint-disable-next-line no-use-before-define + return getParsoidCommentData( widget.comment.id ).then( function ( parsoidData ) { + return postReply( widget, parsoidData ); + } ); + } ); + } + return $.Deferred().reject( code, data ).promise(); + } ); } function highlight( comment ) { diff --git a/modules/dt.ui.ReplyWidget.js b/modules/dt.ui.ReplyWidget.js index 1ca47f2ac..5c1ce24df 100644 --- a/modules/dt.ui.ReplyWidget.js +++ b/modules/dt.ui.ReplyWidget.js @@ -283,30 +283,6 @@ ReplyWidget.prototype.onReplyClick = function () { logger( { action: 'saveAttempt' } ); return controller.postReply( widget, parsoidData ); - } ).catch( function ( code, data ) { - // Handle edit conflicts. Load the latest revision of the page, then try again. If the parent - // comment has been deleted from the page, or if retry also fails for some other reason, the - // error is handled as normal below. - if ( code === 'editconflict' ) { - return widget.api.get( { - action: 'query', - prop: 'revisions', - rvprop: 'ids', - rvlimit: 1, - titles: mw.config.get( 'wgRelevantPageName' ), - formatversion: 2 - } ).then( function ( resp ) { - var latestRevId = resp.query.pages[ 0 ].revisions[ 0 ].revid; - mw.config.set( { - wgCurRevisionId: latestRevId, - wgRevisionId: latestRevId - } ); - return controller.getParsoidCommentData( widget.comment.id ).then( function ( parsoidData ) { - return controller.postReply( widget, parsoidData ); - } ); - } ); - } - return $.Deferred().reject( code, data ).promise(); } ).then( function ( data ) { // eslint-disable-next-line no-jquery/no-global-selector var $container = $( '#mw-content-text' );