[MediaWiki-commits] [Gerrit] Make watchlist topic title link to topic with with unread po... - change (mediawiki...Flow)
jenkins-bot has submitted this change and it was merged. Change subject: Make watchlist topic title link to topic with with unread posts highlighted .. Make watchlist topic title link to topic with with unread posts highlighted Change-Id: Icbd1f38196f9fbcb72f17cfc28752b3cf5783137 --- M includes/Formatter/RecentChanges.php M modules/engine/components/board/flow-board.js 2 files changed, 55 insertions(+), 11 deletions(-) Approvals: EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/Formatter/RecentChanges.php b/includes/Formatter/RecentChanges.php index 6f7f4ba..1c73d9d 100644 --- a/includes/Formatter/RecentChanges.php +++ b/includes/Formatter/RecentChanges.php @@ -3,7 +3,9 @@ namespace Flow\Formatter; use Flow\Exception\FlowException; +use Flow\Model\Anchor; use Flow\Model\PostRevision; +use Flow\Model\UUID; use Flow\Parsoid\Utils; use ChangesList; use IContextSource; @@ -68,4 +70,46 @@ ) . ( Utils::htmlToPlaintext( $description ) ? $separator . $description : '' ); } + + /** +* This overrides the default title link to include highlights for the posts +* that have not yet been seen. +* +* @param array $data +* @param FormatterRow $row +* @param IContextSource $ctx +* @return string +*/ + protected function getTitleLink( array $data, FormatterRow $row, IContextSource $ctx ) { + if ( !$row instanceof RecentChangesRow ) { + // actually, this should be typehint, but can't because this needs + // to match the parent's more generic typehint + return parent::getTitleLink( $data, $row, $ctx ); + } + + $watched = $row->recentChange->getAttribute( 'wl_notificationtimestamp' ); + if ( is_bool( $watched ) ) { + // RC & watchlist share most code; the latter is unaware of when + // something was watched though, so we'll ignore that here + return parent::getTitleLink( $data, $row, $ctx ); + } + + if ( $watched === null ) { + // there is no data for unread posts - they've all been seen + return parent::getTitleLink( $data, $row, $ctx ); + } + + // get comparison UUID corresponding to this last watched timestamp + $uuid = UUID::getComparisonUUID( $watched ); + + // add highlight details to anchor + /** @var Anchor $anchor */ + $anchor = clone $data['links']['topic']; + $anchor->query['fromnotif'] = '1'; + $anchor->fragment = '#flow-post-' . $uuid->getAlphadecimal(); + $data['links']['topic'] = $anchor; + + // now pass it on to parent with the new, updated, link ;) + return parent::getTitleLink( $data, $row, $ctx ); + } } diff --git a/modules/engine/components/board/flow-board.js b/modules/engine/components/board/flow-board.js index a23efc3..35cc3be 100644 --- a/modules/engine/components/board/flow-board.js +++ b/modules/engine/components/board/flow-board.js @@ -18,7 +18,8 @@ * @constructor */ function FlowBoardComponent( $container ) { - var uri = new mw.Uri( window.location.href ); + var uri = new mw.Uri( window.location.href ), + uid = String( window.location.hash.match( /[0-9a-z]{16,19}$/i ) || '' ); // Default API submodule for FlowBoard URLs is to fetch a topiclist this.API.setDefaultSubmodule( 'view-topiclist' ); @@ -30,11 +31,11 @@ } // Handle URL parameters - if ( window.location.hash ) { + if ( uid ) { if ( uri.query.fromnotif ) { - _flowHighlightPost( $container, window.location.hash, 'newer' ); + _flowHighlightPost( $container, uid, 'newer' ); } else { - _flowHighlightPost( $container, window.location.hash ); + _flowHighlightPost( $container, uid ); } } @@ -126,14 +127,13 @@ /** * Helper receives -* @param {jQuery} -* @param {string} -* @param {string} +* @param {jQuery} $container +* @param {string} uid +* @param {string} option * @return {jQuery} */ - function _flowHighlightPost( $container, targetSelector, option ) { - var $target = $container.find( targetSelector ), - uid = $target.data( 'flow-id' ); + function _flowHighlightP
[MediaWiki-commits] [Gerrit] Make watchlist topic title link to topic with with unread po... - change (mediawiki...Flow)
Matthias Mullie has uploaded a new change for review. https://gerrit.wikimedia.org/r/167218 Change subject: Make watchlist topic title link to topic with with unread posts highlighted .. Make watchlist topic title link to topic with with unread posts highlighted Change-Id: Icbd1f38196f9fbcb72f17cfc28752b3cf5783137 --- M includes/Formatter/RecentChanges.php M includes/Formatter/RecentChangesQuery.php 2 files changed, 124 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/18/167218/1 diff --git a/includes/Formatter/RecentChanges.php b/includes/Formatter/RecentChanges.php index 65dde9b..aca3a55 100644 --- a/includes/Formatter/RecentChanges.php +++ b/includes/Formatter/RecentChanges.php @@ -2,7 +2,9 @@ namespace Flow\Formatter; +use Flow\Model\Anchor; use Flow\Model\PostRevision; +use Flow\Model\UUID; use Flow\Parsoid\Utils; use ChangesList; use IContextSource; @@ -62,4 +64,104 @@ ) . ( Utils::htmlToPlaintext( $description ) ? $separator . $description : '' ); } + + /** +* This overrides the default title link to include highlights for the posts +* that have not yet been seen. +* +* @param array $data +* @param FormatterRow $row +* @param IContextSource $ctx +* @return string +*/ + protected function getTitleLink( array $data, FormatterRow $row, IContextSource $ctx ) { + if ( !$row instanceof RecentChangesRow ) { + // actually, this should be typehint, but can't because this needs + // to match the parent's more generic typehint + return parent::getTitleLink( $data, $row, $ctx ); + } + + $watched = $row->recentChange->watched; + if ( is_bool( $watched ) ) { + // RC & watchlist share most code; the latter is unaware of when + // something was watched though, so we'll ignore that here + return parent::getTitleLink( $data, $row, $ctx ); + } + + if ( $watched === null ) { + // there is no data for unread posts - they've all been seen + return parent::getTitleLink( $data, $row, $ctx ); + } + + // filter down the changeData array to only the first unread post + $unread = $this->firstUnreadPost( $row->changeData, $watched ); + if ( !$unread ) { + // there are no unread posts + return parent::getTitleLink( $data, $row, $ctx ); + } + + // get data from existing link to topic so we can build a new anchor + $topic = $data['links']['topic']; + $title = $topic->resolveTitle(); + $topic = $topic->toArray(); + + // figure out if the entry is a post or topic, for highlight fragment + $type = $unread['workflow'] == $unread['post'] ? 'topic' : 'post'; + + // finally, build that new link already! + $data['links']['topic'] = new Anchor( + $topic['title'], + $title, + array( 'fromnotif' => '1' ), + '#flow-' . $type . '-' . $unread['post'] + ); + + // now pass it on to parent with the new, updated, link ;) + return parent::getTitleLink( $data, $row, $ctx ); + } + + /** +* This method will accept an array of multiple $changeData and return only +* the oldest one, that is still more recent that $watched (or null, if +* there is no such entry) +* +* @param array $changeData Array of multiple changeData stored for RC +* @param string $watched Timestamp in any format accepted by wfTimestamp +* @return array|null +*/ + protected function firstUnreadPost( $changeData, $watched ) { + $watched = wfTimestamp( TS_MW, $watched ); + + $filterUnread = function ( $carry, $changeData ) use ( $watched ) { + // we can only highlight posts, so ignore all others + if ( !isset( $changeData['post'] ) ) { + return $carry; + } + + // ignore posts older than last watch time + $postUuid = UUID::create( $changeData['post'] ); + $postTimestamp = $postUuid->getTimestamp(); + if ( $postTimestamp <= $watched ) { + return $carry; + } + + // if this is the first unread we encounter, save that one +