From 890cec73b605b947ad265abeeb562c2a8e13efc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 28 Aug 2024 18:42:12 +0200 Subject: [PATCH] Pause polling for new replies while saving Also fix stopPoll() not really stopping the polling if a request was in progress while it was called. Bug: T333576 Change-Id: Ie8f6f006c6fd23971e53586e6219992db23f48fc --- modules/CommentController.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/CommentController.js b/modules/CommentController.js index a7d59171c..7683c7e4d 100644 --- a/modules/CommentController.js +++ b/modules/CommentController.js @@ -232,6 +232,7 @@ CommentController.prototype.startPoll = function ( nextDelay ) { const threadItemId = this.threadItem.id; const subscribableHeadingId = this.threadItem.getSubscribableHeading().id; + let aborted = false; this.pollApiRequest = controller.getApi().get( { action: 'discussiontoolscompare', @@ -266,11 +267,15 @@ CommentController.prototype.startPoll = function ( nextDelay ) { this.oldId = result.torevid; nextDelay = 5000; - }, () => { - // Wait longer next time in case of error - nextDelay = nextDelay * 1.5; + }, ( code, data ) => { + if ( code === 'http' && data.textStatus === 'abort' ) { + aborted = true; + } else { + // Wait longer next time in case of error + nextDelay = nextDelay * 1.5; + } } ).always( () => { - if ( this.isTornDown ) { + if ( this.isTornDown || aborted ) { return; } // Stop polling after too many errors @@ -498,6 +503,8 @@ CommentController.prototype.onReplySubmit = function ( extraParams ) { * @param {Object} data Error data */ CommentController.prototype.saveFail = function ( code, data ) { + this.startPoll(); + const captchaData = OO.getProp( data, 'discussiontoolsedit', 'edit', 'captcha' ); if ( captchaData ) { @@ -550,6 +557,8 @@ CommentController.prototype.saveFail = function ( code, data ) { * @return {jQuery.Promise} Promise which resolves when the save is complete */ CommentController.prototype.save = function ( pageName, extraParams ) { + this.stopPoll(); + const replyWidget = this.replyWidget, threadItem = this.getThreadItem();