From 1f58185f894e1a893848527f160cffa1d9711c0b Mon Sep 17 00:00:00 2001 From: John Watson Date: Thu, 10 Jan 2013 11:10:32 -0800 Subject: [PATCH] Add renderText to FeedStory for simple text repr of story Summary: This pushes the rendering of feed stories out of IRCDifferentialNotificationHandler and into feed.query Also fixes bug in feed.query that broke attachment of related objects to stories. Test Plan: echo '{"view": "text", "limit": 10}' | arc call-conduit feed.query Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, codeblock Differential Revision: https://secure.phabricator.com/D4390 --- .../conduit/ConduitAPI_feed_query_Method.php | 15 +++-- .../feed/story/PhabricatorFeedStoryAudit.php | 13 ++++ .../feed/story/PhabricatorFeedStoryCommit.php | 35 ++++++++++ .../PhabricatorFeedStoryDifferential.php | 15 +++++ .../story/PhabricatorFeedStoryManiphest.php | 38 +++++++++++ .../story/PhabricatorFeedStoryPhriction.php | 13 ++++ .../story/PhabricatorFeedStoryProject.php | 66 +++++++++++++++++++ .../feed/story/PhabricatorFeedStoryStatus.php | 10 +++ 8 files changed, 199 insertions(+), 6 deletions(-) diff --git a/src/applications/feed/conduit/ConduitAPI_feed_query_Method.php b/src/applications/feed/conduit/ConduitAPI_feed_query_Method.php index 191e0f68cc..f75d5fb33d 100644 --- a/src/applications/feed/conduit/ConduitAPI_feed_query_Method.php +++ b/src/applications/feed/conduit/ConduitAPI_feed_query_Method.php @@ -77,14 +77,8 @@ final class ConduitAPI_feed_query_Method extends ConduitAPIMethod { $stories = $query->execute(); if ($stories) { - $handle_phids = array_mergev(mpull($stories, 'getRequiredHandlePHIDs')); - $handles = id(new PhabricatorObjectHandleData($handle_phids)) - ->loadHandles(); - foreach ($stories as $story) { - $story->setHandles($handles); - $story_data = $story->getStoryData(); $data = null; @@ -110,6 +104,15 @@ final class ConduitAPI_feed_query_Method extends ConduitAPIMethod { 'data' => $story_data->getStoryData(), ); break; + case 'text': + $data = array( + 'class' => $story_data->getStoryType(), + 'epoch' => $story_data->getEpoch(), + 'authorPHID' => $story_data->getAuthorPHID(), + 'chronologicalKey' => $story_data->getChronologicalKey(), + 'text' => $story->renderText() + ); + break; default: throw new ConduitException('ERR-UNKNOWN-TYPE'); } diff --git a/src/applications/feed/story/PhabricatorFeedStoryAudit.php b/src/applications/feed/story/PhabricatorFeedStoryAudit.php index c1a643d5a1..9fe789b046 100644 --- a/src/applications/feed/story/PhabricatorFeedStoryAudit.php +++ b/src/applications/feed/story/PhabricatorFeedStoryAudit.php @@ -41,4 +41,17 @@ final class PhabricatorFeedStoryAudit extends PhabricatorFeedStory { return $view; } + public function renderText() { + $author_name = $this->getHandle($this->getAuthorPHID())->getLinkName(); + + $commit_path = $this->getHandle($this->getPrimaryObjectPHID())->getURI(); + $commit_uri = PhabricatorEnv::getURI($commit_path); + + $action = $this->getValue('action'); + $verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($action); + + $text = "{$author_name} {$verb} commit {$commit_uri}"; + + return $text; + } } diff --git a/src/applications/feed/story/PhabricatorFeedStoryCommit.php b/src/applications/feed/story/PhabricatorFeedStoryCommit.php index 67bc8fcdc7..0e2030cbf3 100644 --- a/src/applications/feed/story/PhabricatorFeedStoryCommit.php +++ b/src/applications/feed/story/PhabricatorFeedStoryCommit.php @@ -57,4 +57,39 @@ final class PhabricatorFeedStoryCommit extends PhabricatorFeedStory { return $view; } + public function renderText() { + $author = null; + if ($this->getAuthorPHID()) { + $author = $this->getHandle($this->getAuthorPHID())->getLinkName(); + } else { + $author = $this->getValue('authorName'); + } + + $committer = null; + if ($this->getValue('committerPHID')) { + $committer_handle = $this->getHandle($this->getValue('committerPHID')); + $committer = $committer_handle->getLinkName(); + } else if ($this->getValue('committerName')) { + $committer = $this->getValue('committerName'); + } + + $commit_handle = $this->getHandle($this->getPrimaryObjectPHID()); + $commit_uri = PhabricatorEnv::getURI($commit_handle->getURI()); + $commit_name = $commit_handle->getLinkName(); + + if (!$committer) { + $committer = $author; + $author = null; + } + + if ($author) { + $text = "{$committer} (authored by {$author})". + "committed {$commit_name} {$commit_uri}"; + } else { + $text = "{$committer} committed {$commit_name} {$commit_uri}"; + } + + return $text; + } + } diff --git a/src/applications/feed/story/PhabricatorFeedStoryDifferential.php b/src/applications/feed/story/PhabricatorFeedStoryDifferential.php index 9e001fa9b2..6382c39f8b 100644 --- a/src/applications/feed/story/PhabricatorFeedStoryDifferential.php +++ b/src/applications/feed/story/PhabricatorFeedStoryDifferential.php @@ -56,6 +56,21 @@ final class PhabricatorFeedStoryDifferential extends PhabricatorFeedStory { return $one_line; } + public function renderText() { + $author_name = $this->getHandle($this->getAuthorPHID())->getLinkName(); + + $revision_handle = $this->getHandle($this->getPrimaryObjectPHID()); + $revision_title = $revision_handle->getLinkName(); + $revision_uri = PhabricatorEnv::getURI($revision_handle->getURI()); + + $action = $this->getValue('action'); + $verb = DifferentialAction::getActionPastTenseVerb($action); + + $text = "{$author_name} {$verb} revision {$revision_title} {$revision_uri}"; + + return $text; + } + public function getNotificationAggregations() { $class = get_class($this); $phid = $this->getStoryData()->getValue('revision_phid'); diff --git a/src/applications/feed/story/PhabricatorFeedStoryManiphest.php b/src/applications/feed/story/PhabricatorFeedStoryManiphest.php index 09159d0595..c6c0348d6d 100644 --- a/src/applications/feed/story/PhabricatorFeedStoryManiphest.php +++ b/src/applications/feed/story/PhabricatorFeedStoryManiphest.php @@ -82,6 +82,44 @@ final class PhabricatorFeedStoryManiphest return $one_line; } + public function renderText() { + $actor_phid = $this->getAuthorPHID(); + $author_name = $this->getHandle($actor_phid)->getLinkName(); + + $owner_phid = $this->getValue('ownerPHID'); + $owner_name = $this->getHandle($owner_phid)->getLinkName(); + + $task_phid = $this->getPrimaryObjectPHID(); + $task_handle = $this->getHandle($task_phid); + $task_title = $task_handle->getLinkName(); + $task_uri = PhabricatorEnv::getURI($task_handle->getURI()); + + $action = $this->getValue('action'); + $verb = ManiphestAction::getActionPastTenseVerb($action); + + switch ($action) { + case ManiphestAction::ACTION_ASSIGN: + case ManiphestAction::ACTION_REASSIGN: + if ($owner_phid) { + if ($owner_phid == $actor_phid) { + $text = "{$author_name} claimed {$task_title}"; + } else { + $text = "{$author_name} {$verb} {$task_title} to {$owner_name}"; + } + } else { + $text = "{$author_name} placed {$task_title} up for grabs"; + } + break; + default: + $text = "{$author_name} {$verb} {$task_title}"; + break; + } + + $text .= " {$task_uri}"; + + return $text; + } + public function getNotificationAggregations() { $class = get_class($this); $phid = $this->getStoryData()->getValue('taskPHID'); diff --git a/src/applications/feed/story/PhabricatorFeedStoryPhriction.php b/src/applications/feed/story/PhabricatorFeedStoryPhriction.php index 205e198c70..8efe6af6d9 100644 --- a/src/applications/feed/story/PhabricatorFeedStoryPhriction.php +++ b/src/applications/feed/story/PhabricatorFeedStoryPhriction.php @@ -44,4 +44,17 @@ final class PhabricatorFeedStoryPhriction extends PhabricatorFeedStory { return $view; } + public function renderText() { + $author_name = $this->getHandle($this->getAuthorPHID())->getLinkName(); + + $document_handle = $this->getHandle($this->getPrimaryObjectPHID()); + $document_title = $document_handle->getLinkName(); + $document_uri = PhabricatorEnv::getURI($document_handle->getURI()); + + $text = "{$author_name} {$verb} the document". + "{$document_title} {$document_uri}"; + + return $text; + } + } diff --git a/src/applications/feed/story/PhabricatorFeedStoryProject.php b/src/applications/feed/story/PhabricatorFeedStoryProject.php index eecf67f3e6..c517a98496 100644 --- a/src/applications/feed/story/PhabricatorFeedStoryProject.php +++ b/src/applications/feed/story/PhabricatorFeedStoryProject.php @@ -82,4 +82,70 @@ final class PhabricatorFeedStoryProject extends PhabricatorFeedStory { return $view; } + public function renderText() { + $type = $this->getValue('type'); + $old = $this->getValue('old'); + $new = $this->getValue('new'); + + $proj_handle = $this->getHandle($this->getPrimaryObjectPHID()); + $proj_name = $proj_handle->getLinkName(); + $proj_uri = PhabricatorEnv::getURI($proj_handle->getURI()); + + $author_phid = $this->getAuthorPHID(); + $author_name = $this->getHandle($author_phid)->getLinkName(); + + switch ($type) { + case PhabricatorProjectTransactionType::TYPE_NAME: + if (strlen($old)) { + $action = 'renamed project '. + $proj_name. + ' from '. + $old. + ' to '. + $new; + } else { + $action = 'created project '. + $proj_name. + ' (as '. + $new. + ')'; + } + break; + case PhabricatorProjectTransactionType::TYPE_STATUS: + $action = 'changed project '. + $proj_name. + ' status from '. + $old. + ' to '. + $new; + break; + case PhabricatorProjectTransactionType::TYPE_MEMBERS: + $add = array_diff($new, $old); + $rem = array_diff($old, $new); + + if ((count($add) == 1) && (count($rem) == 0) && + (head($add) == $author_phid)) { + $action = 'joined project'; + } else if ((count($add) == 0) && (count($rem) == 1) && + (head($rem) == $author_phid)) { + $action = 'left project'; + } else if (empty($rem)) { + $action = 'added members to project'; + } else if (empty($add)) { + $action = 'removed members from project'; + } else { + $action = 'changed members of project'; + } + $action .= " {$proj_name}"; + break; + default: + $action = "updated project {$proj_name}"; + break; + } + + $text = "{$author_name} {$action} {$proj_uri}"; + + return $text; + } + } diff --git a/src/applications/feed/story/PhabricatorFeedStoryStatus.php b/src/applications/feed/story/PhabricatorFeedStoryStatus.php index 1cd1cd8f89..41485ea8cd 100644 --- a/src/applications/feed/story/PhabricatorFeedStoryStatus.php +++ b/src/applications/feed/story/PhabricatorFeedStoryStatus.php @@ -23,4 +23,14 @@ final class PhabricatorFeedStoryStatus extends PhabricatorFeedStory { return $view; } + public function renderText() { + $author_handle = $this->getHandle($this->getPrimaryObjectPHID()); + $author_name = $author_handle->getLinkName(); + $author_uri = PhabricatorEnv::getURI($author_handle->getURI()); + + $text = "{$author_name} updated their status {$author_url}"; + + return $text; + } + }