mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
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
This commit is contained in:
parent
dceb161150
commit
1f58185f89
8 changed files with 199 additions and 6 deletions
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue