Highlight new comments when refreshing

Bug: T300215
Change-Id: I72655e05dccbe96f9dfa4ccca4e91b3edf133d97
This commit is contained in:
Ed Sanders 2022-02-23 22:41:47 +00:00
parent 487be9e202
commit 4f91a0b883
2 changed files with 21 additions and 1 deletions

View file

@ -9,6 +9,7 @@ var
storage = new MemoryStorage( mw.storage.session.store ), storage = new MemoryStorage( mw.storage.session.store ),
Parser = require( './Parser.js' ), Parser = require( './Parser.js' ),
ThreadItemSet = require( './ThreadItemSet.js' ), ThreadItemSet = require( './ThreadItemSet.js' ),
CommentItem = require( './CommentItem.js' ),
CommentDetails = require( './CommentDetails.js' ), CommentDetails = require( './CommentDetails.js' ),
ReplyLinksController = require( './ReplyLinksController.js' ), ReplyLinksController = require( './ReplyLinksController.js' ),
logger = require( './logger.js' ), logger = require( './logger.js' ),
@ -291,6 +292,20 @@ function init( $container, state ) {
} }
} ); } );
commentController.on( 'reloadPage', function () { commentController.on( 'reloadPage', function () {
if ( commentController.threadItem instanceof CommentItem ) {
var heading = commentController.threadItem.getSubscribableHeading() || commentController.threadItem.getHeading();
var newestTimestamp = 0;
var newestThreadItem = null;
heading.getThreadItemsBelow().forEach( function ( threadItem ) {
if ( threadItem instanceof CommentItem && threadItem.timestamp > newestTimestamp ) {
newestThreadItem = threadItem;
newestTimestamp = threadItem.timestamp;
}
} );
if ( newestThreadItem ) {
mw.dt.initState.newCommentsSinceId = newestThreadItem.id;
}
}
// Teardown active reply widget(s) // Teardown active reply widget(s)
commentController.replyWidgetPromise.then( function ( replyWidget ) { commentController.replyWidgetPromise.then( function ( replyWidget ) {
lastControllerScrollOffset = $( commentController.newListItem ).offset().top; lastControllerScrollOffset = $( commentController.newListItem ).offset().top;
@ -387,6 +402,8 @@ function init( $container, state ) {
} ); } );
} }
} }
} else if ( state.newCommentsSinceId ) {
highlighter.highlightNewComments( pageThreads, true, [], state.newCommentsSinceId, true );
} }
// Check topic subscription states if the user has automatic subscriptions enabled // Check topic subscription states if the user has automatic subscriptions enabled
@ -416,8 +433,10 @@ function init( $container, state ) {
} ); } );
pageHandlersSetup = true; pageHandlersSetup = true;
} }
if ( state.firstLoad ) {
highlighter.highlightTargetComment( pageThreads ); highlighter.highlightTargetComment( pageThreads );
} }
}
/** /**
* Update the contents of the page with the data from an action=parse API response. * Update the contents of the page with the data from an action=parse API response.

View file

@ -294,6 +294,7 @@ module.exports = {
highlight: highlight, highlight: highlight,
highlightTargetComment: highlightTargetComment, highlightTargetComment: highlightTargetComment,
highlightPublishedComment: highlightPublishedComment, highlightPublishedComment: highlightPublishedComment,
highlightNewComments: highlightNewComments,
clearHighlightTargetComment: clearHighlightTargetComment, clearHighlightTargetComment: clearHighlightTargetComment,
getLastHighlightedPublishedComment: getLastHighlightedPublishedComment getLastHighlightedPublishedComment: getLastHighlightedPublishedComment
}; };