diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 514e1ec9bc..5fe04a05b1 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -120,6 +120,7 @@ phutil_register_library_map(array( 'ConduitAPI_conduit_query_Method' => 'applications/conduit/method/ConduitAPI_conduit_query_Method.php', 'ConduitAPI_conpherence_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_Method.php', 'ConduitAPI_conpherence_createthread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php', + 'ConduitAPI_conpherence_querythread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_querythread_Method.php', 'ConduitAPI_daemon_launched_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_launched_Method.php', 'ConduitAPI_daemon_log_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_log_Method.php', 'ConduitAPI_daemon_setstatus_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_setstatus_Method.php', @@ -1952,6 +1953,7 @@ phutil_register_library_map(array( 'ConduitAPI_conduit_query_Method' => 'ConduitAPIMethod', 'ConduitAPI_conpherence_Method' => 'ConduitAPIMethod', 'ConduitAPI_conpherence_createthread_Method' => 'ConduitAPI_conpherence_Method', + 'ConduitAPI_conpherence_querythread_Method' => 'ConduitAPI_conpherence_Method', 'ConduitAPI_daemon_launched_Method' => 'ConduitAPIMethod', 'ConduitAPI_daemon_log_Method' => 'ConduitAPIMethod', 'ConduitAPI_daemon_setstatus_Method' => 'ConduitAPIMethod', diff --git a/src/applications/conpherence/conduit/ConduitAPI_conpherence_Method.php b/src/applications/conpherence/conduit/ConduitAPI_conpherence_Method.php index a3bcbee36d..600841629e 100644 --- a/src/applications/conpherence/conduit/ConduitAPI_conpherence_Method.php +++ b/src/applications/conpherence/conduit/ConduitAPI_conpherence_Method.php @@ -11,4 +11,10 @@ abstract class ConduitAPI_conpherence_Method 'PhabricatorApplicationConpherence'); } + final protected function getConpherenceURI(ConpherenceThread $conpherence) { + $id = $conpherence->getID(); + return PhabricatorEnv::getProductionURI( + $this->getApplication()->getApplicationURI($id)); + } + } diff --git a/src/applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php b/src/applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php index b431e4839d..dc152d1eba 100644 --- a/src/applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php +++ b/src/applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php @@ -6,8 +6,8 @@ final class ConduitAPI_conpherence_createthread_Method extends ConduitAPI_conpherence_Method { - public function getMethodDescription() { + return pht('Create a new conpherence thread.'); } public function defineParamTypes() { @@ -24,8 +24,10 @@ final class ConduitAPI_conpherence_createthread_Method public function defineErrorTypes() { return array( - 'ERR_EMPTY_PARTICIPANT_PHIDS' => 'You must specify participant phids.', - 'ERR_EMPTY_MESSAGE' => 'You must specify a message.' + 'ERR_EMPTY_PARTICIPANT_PHIDS' => pht( + 'You must specify participant phids.'), + 'ERR_EMPTY_MESSAGE' => pht( + 'You must specify a message.') ); } @@ -55,11 +57,9 @@ final class ConduitAPI_conpherence_createthread_Method } } - $id = $conpherence->getID(); - $uri = $this->getApplication()->getApplicationURI($id); return array( - 'conpherenceID' => $id, + 'conpherenceID' => $conpherence->getID(), 'conpherencePHID' => $conpherence->getPHID(), - 'conpherenceURI' => $uri); + 'conpherenceURI' => $this->getConpherenceURI($conpherence)); } } diff --git a/src/applications/conpherence/conduit/ConduitAPI_conpherence_querythread_Method.php b/src/applications/conpherence/conduit/ConduitAPI_conpherence_querythread_Method.php new file mode 100644 index 0000000000..be04ce07d6 --- /dev/null +++ b/src/applications/conpherence/conduit/ConduitAPI_conpherence_querythread_Method.php @@ -0,0 +1,85 @@ + 'optional array', + 'phids' => 'optional array', + 'limit' => 'optional int', + 'offset' => 'optional int' + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array(); + } + + protected function execute(ConduitAPIRequest $request) { + $user = $request->getUser(); + $ids = $request->getValue('ids', array()); + $phids = $request->getValue('phids', array()); + $limit = $request->getValue('limit'); + $offset = $request->getValue('offset'); + + $query = id(new ConpherenceThreadQuery()) + ->setViewer($user) + ->needParticipantCache(true) + ->needFilePHIDs(true); + + if ($ids) { + $conpherences = $query + ->withIDs($ids) + ->setLimit($limit) + ->setOffset($offset) + ->execute(); + } else if ($phids) { + $conpherences = $query + ->withPHIDs($phids) + ->setLimit($limit) + ->setOffset($offset) + ->execute(); + } else { + $participation = id(new ConpherenceParticipantQuery()) + ->withParticipantPHIDs(array($user->getPHID())) + ->setLimit($limit) + ->setOffset($offset) + ->execute(); + $conpherence_phids = array_keys($participation); + $query->withPHIDs($conpherence_phids); + $conpherences = $query->execute(); + $conpherences = array_select_keys($conpherences, $conpherence_phids); + } + + $data = array(); + foreach ($conpherences as $conpherence) { + $id = $conpherence->getID(); + $data[$id] = array( + 'conpherenceID' => $id, + 'conpherencePHID' => $conpherence->getPHID(), + 'conpherenceTitle' => $conpherence->getTitle(), + 'messageCount' => $conpherence->getMessageCount(), + 'recentParticipantPHIDs' => $conpherence->getRecentParticipantPHIDs(), + 'filePHIDs' => $conpherence->getFilePHIDs(), + 'conpherenceURI' => $this->getConpherenceURI($conpherence)); + } + return $data; + } +}