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 ),
Parser = require( './Parser.js' ),
ThreadItemSet = require( './ThreadItemSet.js' ),
CommentItem = require( './CommentItem.js' ),
CommentDetails = require( './CommentDetails.js' ),
ReplyLinksController = require( './ReplyLinksController.js' ),
logger = require( './logger.js' ),
@ -291,6 +292,20 @@ function init( $container, state ) {
}
} );
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)
commentController.replyWidgetPromise.then( function ( replyWidget ) {
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
@ -416,7 +433,9 @@ function init( $container, state ) {
} );
pageHandlersSetup = true;
}
highlighter.highlightTargetComment( pageThreads );
if ( state.firstLoad ) {
highlighter.highlightTargetComment( pageThreads );
}
}
/**

View file

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