New topics notifications: Only highlight comments in new threads

Bug: T333476
Change-Id: I3f29c4b5a9be916d25415db18f50bd8efe6532af
This commit is contained in:
Ed Sanders 2023-03-30 17:04:36 +01:00 committed by Esanders
parent fd45c64491
commit e66327746a
2 changed files with 18 additions and 2 deletions

View file

@ -80,7 +80,10 @@ trait DiscussionToolsEventTrait {
$bundledEvents = $this->getBundledEvents(); $bundledEvents = $this->getBundledEvents();
$oldestEvent = end( $bundledEvents ); $oldestEvent = end( $bundledEvents );
$params = [ 'dtnewcommentssince' => $oldestEvent->getExtraParam( 'comment-id' ) ]; $params = [ 'dtnewcommentssince' => $oldestEvent->getExtraParam( 'comment-id' ) ];
if ( $this->event->getExtraParam( 'subscribed-comment-name' ) ) { if ( $this->event->getType() === 'dt-added-topic' ) {
// New topics notifications: Tell client to only highlight topics **started** since this one
$params[ 'dtsincethread' ] = 1;
} elseif ( $this->event->getExtraParam( 'subscribed-comment-name' ) ) {
// Topic notifications: Tell client to restrict highlights to this thread // Topic notifications: Tell client to restrict highlights to this thread
$params[ 'dtinthread' ] = 1; $params[ 'dtinthread' ] = 1;
} }

View file

@ -204,7 +204,8 @@ function highlightTargetComment( threadItemSet, noScroll ) {
url.searchParams.get( 'dtnewcomments' ) && url.searchParams.get( 'dtnewcomments' ).split( '|' ), url.searchParams.get( 'dtnewcomments' ) && url.searchParams.get( 'dtnewcomments' ).split( '|' ),
{ {
newCommentsSinceId: url.searchParams.get( 'dtnewcommentssince' ), newCommentsSinceId: url.searchParams.get( 'dtnewcommentssince' ),
inThread: url.searchParams.get( 'dtinthread' ) inThread: url.searchParams.get( 'dtinthread' ),
sinceThread: url.searchParams.get( 'dtsincethread' )
} }
); );
} }
@ -293,6 +294,8 @@ function highlightPublishedComment( threadItemSet, threadItemId ) {
* @param {Object} [options] Extra options * @param {Object} [options] Extra options
* @param {string} [options.newCommentsSinceId] Highlight all comments after the comment with this ID * @param {string} [options.newCommentsSinceId] Highlight all comments after the comment with this ID
* @param {boolean} [options.inThread] When using newCommentsSinceId, only highlight comments in the same thread * @param {boolean} [options.inThread] When using newCommentsSinceId, only highlight comments in the same thread
* @param {boolean} [options.sinceThread] When using newCommentsSinceId, only highlight comments in threads
* created since that comment was posted.
*/ */
function highlightNewComments( threadItemSet, noScroll, newCommentIds, options ) { function highlightNewComments( threadItemSet, noScroll, newCommentIds, options ) {
if ( highlightedTarget ) { if ( highlightedTarget ) {
@ -322,6 +325,15 @@ function highlightNewComments( threadItemSet, noScroll, newCommentIds, options )
threadItem instanceof CommentItem && threadItem instanceof CommentItem &&
threadItem.timestamp >= sinceTimestamp threadItem.timestamp >= sinceTimestamp
) { ) {
if ( options.sinceThread ) {
// Check that we are in a thread that is newer than `sinceTimestamp`.
// Thread age is determined by looking at getOldestReply.
var itemHeading = threadItem.getSubscribableHeading() || threadItem.getHeading();
var oldestReply = itemHeading.getOldestReply();
if ( !( oldestReply && oldestReply.timestamp >= sinceTimestamp ) ) {
return;
}
}
newCommentIds.push( threadItem.id ); newCommentIds.push( threadItem.id );
} }
} ); } );
@ -397,6 +409,7 @@ function clearHighlightTargetComment( threadItemSet ) {
url.searchParams.delete( 'dtnewcomments' ); url.searchParams.delete( 'dtnewcomments' );
url.searchParams.delete( 'dtnewcommentssince' ); url.searchParams.delete( 'dtnewcommentssince' );
url.searchParams.delete( 'dtinthread' ); url.searchParams.delete( 'dtinthread' );
url.searchParams.delete( 'dtsincethread' );
history.pushState( null, '', url ); history.pushState( null, '', url );
highlightTargetComment( threadItemSet ); highlightTargetComment( threadItemSet );
} else if ( highlightedTarget ) { } else if ( highlightedTarget ) {