Merge "Simplify handling of sections in bundled notification links"

This commit is contained in:
jenkins-bot 2022-01-24 23:21:54 +00:00 committed by Gerrit Code Review
commit 9892008135
2 changed files with 9 additions and 10 deletions

View file

@ -18,6 +18,7 @@ use WikiMap;
* *
* @property \EchoEvent $event * @property \EchoEvent $event
* @property \Language $language * @property \Language $language
* @property \EchoPresentationModelSection $section
*/ */
trait DiscussionToolsEventTrait { trait DiscussionToolsEventTrait {
@ -51,7 +52,6 @@ trait DiscussionToolsEventTrait {
if ( !$this->userCan( RevisionRecord::DELETED_TEXT ) ) { if ( !$this->userCan( RevisionRecord::DELETED_TEXT ) ) {
return null; return null;
} }
$title = $this->event->getTitle();
if ( !$this->isBundled() ) { if ( !$this->isBundled() ) {
// For a single-comment notification, make a pretty(ish) direct link to the comment. // For a single-comment notification, make a pretty(ish) direct link to the comment.
// The browser scrolls and we highlight it client-side. // The browser scrolls and we highlight it client-side.
@ -59,6 +59,7 @@ trait DiscussionToolsEventTrait {
if ( !$commentId ) { if ( !$commentId ) {
return null; return null;
} }
$title = $this->event->getTitle();
return $title->createFragmentTarget( $commentId )->getFullURL(); return $title->createFragmentTarget( $commentId )->getFullURL();
} else { } else {
// For a multi-comment notification, we can't make a direct link, because we don't know // For a multi-comment notification, we can't make a direct link, because we don't know
@ -72,23 +73,21 @@ trait DiscussionToolsEventTrait {
// * Mention notifications are *never* bundled. // * Mention notifications are *never* bundled.
// Code below tries to avoid assumptions in case this behavior changes. // Code below tries to avoid assumptions in case this behavior changes.
$sectionTitles = [ $this->event->getExtraParam( 'section-title' ) ];
$commentIds = [ $this->event->getExtraParam( 'comment-id' ) ]; $commentIds = [ $this->event->getExtraParam( 'comment-id' ) ];
foreach ( $this->getBundledEvents() as $event ) { foreach ( $this->getBundledEvents() as $event ) {
$sectionTitles[] = $event->getExtraParam( 'section-title' );
$commentIds[] = $event->getExtraParam( 'comment-id' ); $commentIds[] = $event->getExtraParam( 'comment-id' );
} }
$commentIds = array_values( array_filter( $commentIds ) ); $commentIds = array_values( array_filter( $commentIds ) );
$sectionTitles = array_values( array_unique( array_filter( $sectionTitles ) ) );
if ( !$commentIds ) { if ( !$commentIds ) {
return null; return null;
} }
$params = [ 'dtnewcomments' => implode( '|', $commentIds ) ]; $params = [ 'dtnewcomments' => implode( '|', $commentIds ) ];
if ( count( $sectionTitles ) === 1 ) { // This may or may not have a fragment identifier, depending on whether it was recorded for
return $title->createFragmentTarget( $sectionTitles[0] )->getFullURL( $params ); // the first one of the bundled events. It's usually not needed because we handle scrolling
} else { // client-side, but we can keep it for no-JS users, and to reduce the jump when scrolling.
return $title->getFullURL( $params ); $titleWithOptionalSection = $this->section->getTitleWithSection();
} return $titleWithOptionalSection->getFullURL( $params );
} }
} }

View file

@ -25,7 +25,7 @@ class SubscribedNewCommentPresentationModel extends EchoEventPresentationModel {
/** /**
* @var EchoPresentationModelSection * @var EchoPresentationModelSection
*/ */
private $section; protected $section;
/** /**
* @inheritDoc * @inheritDoc