diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 4ea5cbaa1c..85b13652c0 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -127,7 +127,7 @@ celerity_register_resource_map(array( ), 'differential-revision-comment-list-css' => array( - 'uri' => '/res/a1c117db/rsrc/css/application/differential/revision-comment-list.css', + 'uri' => '/res/afbc5f6f/rsrc/css/application/differential/revision-comment-list.css', 'type' => 'css', 'requires' => array( @@ -293,6 +293,16 @@ celerity_register_resource_map(array( ), 'disk' => '/rsrc/js/application/differential/behavior-populate.js', ), + 'javelin-behavior-differential-show-all-comments' => + array( + 'uri' => '/res/625fea99/rsrc/js/application/differential/behavior-show-all-comments.js', + 'type' => 'js', + 'requires' => + array( + 0 => 'javelin-lib-dev', + ), + 'disk' => '/rsrc/js/application/differential/behavior-show-all-comments.js', + ), 'javelin-behavior-differential-show-more' => array( 'uri' => '/res/ea998002/rsrc/js/application/differential/behavior-show-more.js', @@ -400,7 +410,7 @@ celerity_register_resource_map(array( 'uri' => '/res/pkg/20cc4391/core.pkg.css', 'type' => 'css', ), - '33e57258' => + 'f7362a6c' => array ( 'name' => 'differential.pkg.css', 'symbols' => @@ -414,7 +424,7 @@ celerity_register_resource_map(array( 6 => 'differential-revision-add-comment-css', 7 => 'differential-revision-comment-list-css', ), - 'uri' => '/res/pkg/33e57258/differential.pkg.css', + 'uri' => '/res/pkg/f7362a6c/differential.pkg.css', 'type' => 'css', ), '30d594cf' => @@ -447,14 +457,14 @@ celerity_register_resource_map(array( 'phabricator-directory-css' => '20cc4391', 'phabricator-remarkup-css' => '20cc4391', 'syntax-highlighting-css' => '20cc4391', - 'differential-core-view-css' => '33e57258', - 'differential-changeset-view-css' => '33e57258', - 'differential-revision-detail-css' => '33e57258', - 'differential-revision-history-css' => '33e57258', - 'differential-table-of-contents-css' => '33e57258', - 'differential-revision-comment-css' => '33e57258', - 'differential-revision-add-comment-css' => '33e57258', - 'differential-revision-comment-list-css' => '33e57258', + 'differential-core-view-css' => 'f7362a6c', + 'differential-changeset-view-css' => 'f7362a6c', + 'differential-revision-detail-css' => 'f7362a6c', + 'differential-revision-history-css' => 'f7362a6c', + 'differential-table-of-contents-css' => 'f7362a6c', + 'differential-revision-comment-css' => 'f7362a6c', + 'differential-revision-add-comment-css' => 'f7362a6c', + 'differential-revision-comment-list-css' => 'f7362a6c', 'javelin-behavior-differential-feedback-preview' => '30d594cf', 'javelin-behavior-differential-edit-inline-comments' => '30d594cf', 'javelin-behavior-differential-populate' => '30d594cf', diff --git a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php index ca96ea78a7..41c90bced0 100644 --- a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php @@ -82,6 +82,7 @@ class DifferentialRevisionViewController extends DifferentialController { $comment_view->setHandles($handles); $comment_view->setInlineComments($inlines); $comment_view->setChangesets($changesets); + $comment_view->setUser($request->getUser()); $diff_history = new DifferentialRevisionUpdateHistoryView(); $diff_history->setDiffs($diffs); diff --git a/src/applications/differential/view/revisioncommentlist/DifferentialRevisionCommentListView.php b/src/applications/differential/view/revisioncommentlist/DifferentialRevisionCommentListView.php index 76edc7e89a..6c167e362e 100644 --- a/src/applications/differential/view/revisioncommentlist/DifferentialRevisionCommentListView.php +++ b/src/applications/differential/view/revisioncommentlist/DifferentialRevisionCommentListView.php @@ -22,6 +22,7 @@ final class DifferentialRevisionCommentListView extends AphrontView { private $handles; private $inlines; private $changesets; + private $user; public function setComments(array $comments) { $this->comments = $comments; @@ -43,6 +44,11 @@ final class DifferentialRevisionCommentListView extends AphrontView { return $this; } + public function setUser(PhabricatorUser $user) { + $this->user = $user; + return $this; + } + public function render() { require_celerity_resource('differential-revision-comment-list-css'); @@ -53,7 +59,7 @@ final class DifferentialRevisionCommentListView extends AphrontView { $inlines = mgroup($this->inlines, 'getCommentID'); - $comments = array(); + $html = array(); foreach ($this->comments as $comment) { $view = new DifferentialRevisionCommentView(); $view->setComment($comment); @@ -62,12 +68,94 @@ final class DifferentialRevisionCommentListView extends AphrontView { $view->setInlineComments(idx($inlines, $comment->getID(), array())); $view->setChangesets($this->changesets); - $comments[] = $view->render(); + $html[] = $view->render(); + } + + $objs = array_reverse(array_values($this->comments)); + $html = array_reverse(array_values($html)); + $user = $this->user; + + $last_comment = null; + // Find the most recent comment by the viewer. + foreach ($objs as $position => $comment) { + if ($user && ($comment->getAuthorPHID() == $user->getPHID())) { + if ($last_comment === null) { + $last_comment = $position; + } else if ($last_comment == $position - 1) { + // If the viewer made several comments in a row, show them all. This + // is a spaz rule for epriestley. + $last_comment = $position; + } + } + } + + $header = array(); + $hidden = array(); + if ($last_comment !== null) { + foreach ($objs as $position => $comment) { + if (!$comment->getID()) { + // These are synthetic comments with summary/test plan information. + $header[] = $html[$position]; + unset($html[$position]); + continue; + } + if ($position <= $last_comment) { + // Always show comments after the viewer's last comment. + continue; + } + if ($position < 3) { + // Always show the 3 most recent comments. + continue; + } + $hidden[] = $position; + } + } + + if (count($hidden) <= 3) { + // Don't hide if there's not much to hide. + $hidden = array(); + } + + $header = array_reverse($header); + + + $hidden = array_select_keys($html, $hidden); + $visible = array_diff_key($html, $hidden); + + $hidden = array_reverse($hidden); + $visible = array_reverse($visible); + + if ($hidden) { + Javelin::initBehavior( + 'differential-show-all-comments', + array( + 'markup' => implode("\n", $hidden), + )); + $hidden = javelin_render_tag( + 'div', + array( + 'sigil' => "differential-all-comments-container", + ), + '