diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index cb18b1eb1a..45b255a9f1 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -124,6 +124,7 @@ phutil_register_library_map(array( 'ConduitAPI_diffusion_getcommits_Method' => 'applications/conduit/method/diffusion/getcommits', 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/conduit/method/diffusion/getrecentcommitsbypath', 'ConduitAPI_feed_publish_Method' => 'applications/conduit/method/feed/publish', + 'ConduitAPI_feed_query_Method' => 'applications/conduit/method/feed/query', 'ConduitAPI_file_download_Method' => 'applications/conduit/method/file/download', 'ConduitAPI_file_info_Method' => 'applications/conduit/method/file/info', 'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/upload', @@ -929,6 +930,7 @@ phutil_register_library_map(array( 'ConduitAPI_diffusion_getcommits_Method' => 'ConduitAPIMethod', 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPIMethod', 'ConduitAPI_feed_publish_Method' => 'ConduitAPIMethod', + 'ConduitAPI_feed_query_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_download_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_info_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod', diff --git a/src/applications/conduit/method/feed/query/ConduitAPI_feed_query_Method.php b/src/applications/conduit/method/feed/query/ConduitAPI_feed_query_Method.php new file mode 100644 index 0000000000..62a60b56da --- /dev/null +++ b/src/applications/conduit/method/feed/query/ConduitAPI_feed_query_Method.php @@ -0,0 +1,139 @@ + 'optional list ', + 'limit' => 'optional int (default '.$this->getDefaultLimit().')', + 'after' => 'optional int', + 'view' => 'optional string (data, html, html-summary)', + ); + } + + private function getSupportedViewTypes() { + return array( + 'html' => 'Full HTML presentation of story', + 'data' => 'Dictionary with various data of the story', + 'html-summary' => 'Story contains only the title of the story', + ); + } + + public function defineErrorTypes() { + + $view_types = array_keys($this->getSupportedViewTypes()); + $view_types = implode(', ', $view_types); + + return array( + 'ERR-UNKNOWN-TYPE' => + 'Unsupported view type, possibles are: ' . $view_types + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + protected function execute(ConduitAPIRequest $request) { + + $results = array(); + $user = $request->getUser(); + + $view_type = $request->getValue('view'); + if (!$view_type) { + $view_type = 'data'; + } + + $limit = $request->getValue('limit'); + if (!$limit) { + $limit = $this->getDefaultLimit(); + } + $filter_phids = $request->getValue('filter_phids'); + if (!$filter_phids) { + $filter_phids = array(); + } + $after = $request->getValue('after'); + + $query = id(new PhabricatorFeedQuery()) + ->setLimit($limit) + ->setFilterPHIDs($filter_phids) + ->setAfter($after); + $stories = $query->execute(); + + if ($stories) { + $handle_phids = array_mergev(mpull($stories, 'getRequiredHandlePHIDs')); + $object_phids = array_mergev(mpull($stories, 'getRequiredObjectPHIDs')); + $handles = id(new PhabricatorObjectHandleData($handle_phids)) + ->loadHandles(); + $objects = id(new PhabricatorObjectHandleData($object_phids)) + ->loadObjects(); + + foreach ($stories as $story) { + + $story->setHandles($handles); + $story->setObjects($objects); + + $story_data = $story->getStoryData(); + + $data = null; + + $view = $story->renderView(); + $view->setEpoch($story->getEpoch()); + $view->setViewer($user); + + switch ($view_type) { + case 'html': + $data = $view->render(); + break; + case 'html-summary': + $view->setOneLineStory(true); + $data = $view->render(); + break; + case 'data': + $data = array( + 'class' => $story_data->getStoryType(), + 'epoch' => $story_data->getEpoch(), + 'authorPHID' => $story_data->getAuthorPHID(), + 'chronologicalKey' => $story_data->getChronologicalKey(), + 'data' => $story_data->getStoryData(), + ); + break; + default: + throw new ConduitException('ERR-UNKNOWN-TYPE'); + } + + $results[$story_data->getPHID()] = $data; + } + } + + return $results; + } + +} diff --git a/src/applications/conduit/method/feed/query/__init__.php b/src/applications/conduit/method/feed/query/__init__.php new file mode 100644 index 0000000000..30cafb401e --- /dev/null +++ b/src/applications/conduit/method/feed/query/__init__.php @@ -0,0 +1,17 @@ +objects; } - final protected function getStoryData() { + final public function getStoryData() { return $this->data; }