From a37dc68b0adcad2fcc14eeeff82c8c4312434a38 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 13 Aug 2014 11:24:56 -0700 Subject: [PATCH] Show projects on feed stories Summary: Fixes T1922. When a story is about a primary object associated with projects, show those projects on the feed story. Test Plan: {F190171} Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T1922 Differential Revision: https://secure.phabricator.com/D10255 --- .../feed/story/PhabricatorFeedStory.php | 55 ++++++++++++++++++- src/view/phui/PHUIFeedStoryView.php | 21 ++++++- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/applications/feed/story/PhabricatorFeedStory.php b/src/applications/feed/story/PhabricatorFeedStory.php index e81031e16b..4ee8a6372f 100644 --- a/src/applications/feed/story/PhabricatorFeedStory.php +++ b/src/applications/feed/story/PhabricatorFeedStory.php @@ -16,8 +16,9 @@ abstract class PhabricatorFeedStory implements PhabricatorPolicyInterface { private $hovercard = false; private $renderingTarget = PhabricatorApplicationTransaction::TARGET_HTML; - private $handles = array(); - private $objects = array(); + private $handles = array(); + private $objects = array(); + private $projectPHIDs = array(); /* -( Loading Stories )---------------------------------------------------- */ @@ -93,6 +94,30 @@ abstract class PhabricatorFeedStory implements PhabricatorPolicyInterface { $stories[$key]->setObjects($story_objects); } + // If stories are about PhabricatorProjectInterface objects, load the + // projects the objects are a part of so we can render project tags + // on the stories. + + $project_phids = array(); + foreach ($objects as $object) { + if ($object instanceof PhabricatorProjectInterface) { + $project_phids[$object->getPHID()] = array(); + } + } + + if ($project_phids) { + $edge_query = id(new PhabricatorEdgeQuery()) + ->withSourcePHIDs(array_keys($project_phids)) + ->withEdgeTypes( + array( + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, + )); + $edge_query->execute(); + foreach ($project_phids as $phid => $ignored) { + $project_phids[$phid] = $edge_query->getDestinationPHIDs(array($phid)); + } + } + $handle_phids = array(); foreach ($stories as $key => $story) { foreach ($story->getRequiredHandlePHIDs() as $phid) { @@ -101,6 +126,14 @@ abstract class PhabricatorFeedStory implements PhabricatorPolicyInterface { if ($story->getAuthorPHID()) { $key_phids[$key][$story->getAuthorPHID()] = true; } + + $object_phid = $story->getPrimaryObjectPHID(); + $object_project_phids = idx($project_phids, $object_phid, array()); + $story->setProjectPHIDs($object_project_phids); + foreach ($object_project_phids as $dst) { + $key_phids[$key][$dst] = true; + } + $handle_phids += $key_phids[$key]; } @@ -319,10 +352,26 @@ abstract class PhabricatorFeedStory implements PhabricatorPolicyInterface { } protected function newStoryView() { - return id(new PHUIFeedStoryView()) + $view = id(new PHUIFeedStoryView()) ->setChronologicalKey($this->getChronologicalKey()) ->setEpoch($this->getEpoch()) ->setViewed($this->getHasViewed()); + + $project_phids = $this->getProjectPHIDs(); + if ($project_phids) { + $view->setTags($this->renderHandleList($project_phids)); + } + + return $view; + } + + public function setProjectPHIDs(array $phids) { + $this->projectPHIDs = $phids; + return $this; + } + + public function getProjectPHIDs() { + return $this->projectPHIDs; } diff --git a/src/view/phui/PHUIFeedStoryView.php b/src/view/phui/PHUIFeedStoryView.php index 60d71005ae..de717e25d1 100644 --- a/src/view/phui/PHUIFeedStoryView.php +++ b/src/view/phui/PHUIFeedStoryView.php @@ -15,6 +15,16 @@ final class PHUIFeedStoryView extends AphrontView { private $projects = array(); private $actions = array(); private $chronologicalKey; + private $tags; + + public function setTags($tags) { + $this->tags = $tags; + return $this; + } + + public function getTags() { + return $this->tags; + } public function setChronologicalKey($chronological_key) { $this->chronologicalKey = $chronological_key; @@ -235,6 +245,13 @@ final class PHUIFeedStoryView extends AphrontView { $body_content); } + $tags = null; + if ($this->tags) { + $tags = array( + " \xC2\xB7 ", + $this->tags); + } + $foot = phutil_tag( 'div', array( @@ -242,7 +259,9 @@ final class PHUIFeedStoryView extends AphrontView { ), array( $icon, - $foot)); + $foot, + $tags, + )); $classes = array('phui-feed-story');