3 final class FeedQueryConduitAPIMethod
extends FeedConduitAPIMethod
{
5 public function getAPIMethodName() {
9 public function getMethodStatus() {
10 return self
::METHOD_STATUS_UNSTABLE
;
13 public function getMethodDescription() {
14 return pht('Query the feed for stories');
17 private function getDefaultLimit() {
21 protected function defineParamTypes() {
23 'filterPHIDs' => 'optional list <phid>',
24 'limit' => 'optional int (default '.$this->getDefaultLimit().')',
25 'after' => 'optional int',
26 'before' => 'optional int',
27 'view' => 'optional string (data, html, html-summary, text)',
31 private function getSupportedViewTypes() {
33 'html' => pht('Full HTML presentation of story'),
34 'data' => pht('Dictionary with various data of the story'),
35 'html-summary' => pht('Story contains only the title of the story'),
36 'text' => pht('Simple one-line plain text representation of story'),
40 protected function defineErrorTypes() {
42 $view_types = array_keys($this->getSupportedViewTypes());
43 $view_types = implode(', ', $view_types);
48 'Unsupported view type, possibles are: %s',
53 protected function defineReturnType() {
54 return 'nonempty dict';
57 protected function execute(ConduitAPIRequest
$request) {
59 $user = $request->getUser();
61 $view_type = $request->getValue('view');
66 $query = id(new PhabricatorFeedQuery())
69 $filter_phids = $request->getValue('filterPHIDs');
71 $query->withFilterPHIDs($filter_phids);
74 $limit = $request->getValue('limit');
76 $limit = $this->getDefaultLimit();
79 $pager = id(new AphrontCursorPagerView())
80 ->setPageSize($limit);
82 $after = $request->getValue('after');
84 $pager->setAfterID($after);
87 $before = $request->getValue('before');
88 if (strlen($before)) {
89 $pager->setBeforeID($before);
92 $stories = $query->executeWithCursorPager($pager);
95 foreach ($stories as $story) {
97 $story_data = $story->getStoryData();
102 $view = $story->renderView();
103 } catch (Exception
$ex) {
104 // When stories fail to render, just fail that story.
109 $view->setEpoch($story->getEpoch());
110 $view->setUser($user);
112 switch ($view_type) {
114 $data = $view->render();
117 $data = $view->render();
121 'class' => $story_data->getStoryType(),
122 'epoch' => $story_data->getEpoch(),
123 'authorPHID' => $story_data->getAuthorPHID(),
124 'chronologicalKey' => $story_data->getChronologicalKey(),
125 'data' => $story_data->getStoryData(),
130 'class' => $story_data->getStoryType(),
131 'epoch' => $story_data->getEpoch(),
132 'authorPHID' => $story_data->getAuthorPHID(),
133 'chronologicalKey' => $story_data->getChronologicalKey(),
134 'objectPHID' => $story->getPrimaryObjectPHID(),
135 'text' => $story->renderText(),
139 throw new ConduitException('ERR-UNKNOWN-TYPE');
142 $results[$story_data->getPHID()] = $data;