Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / conpherence / conduit / ConpherenceQueryThreadConduitAPIMethod.php
blob0d177e502cb04068a6ef260eada9968fac5ae03e
1 <?php
3 final class ConpherenceQueryThreadConduitAPIMethod
4 extends ConpherenceConduitAPIMethod {
6 public function getAPIMethodName() {
7 return 'conpherence.querythread';
10 public function getMethodDescription() {
11 return pht(
12 'Query for Conpherence threads for the logged in user. You can query '.
13 'by IDs or PHIDs for specific Conpherence threads. Otherwise, specify '.
14 'limit and offset to query the most recently updated Conpherences for '.
15 'the logged in user.');
18 protected function defineParamTypes() {
19 return array(
20 'ids' => 'optional array<int>',
21 'phids' => 'optional array<phids>',
22 'limit' => 'optional int',
23 'offset' => 'optional int',
27 protected function defineReturnType() {
28 return 'nonempty dict';
31 protected function execute(ConduitAPIRequest $request) {
32 $user = $request->getUser();
33 $ids = $request->getValue('ids', array());
34 $phids = $request->getValue('phids', array());
35 $limit = $request->getValue('limit');
36 $offset = $request->getValue('offset');
38 $query = id(new ConpherenceThreadQuery())
39 ->setViewer($user);
41 if ($ids) {
42 $conpherences = $query
43 ->withIDs($ids)
44 ->setLimit($limit)
45 ->setOffset($offset)
46 ->execute();
47 } else if ($phids) {
48 $conpherences = $query
49 ->withPHIDs($phids)
50 ->setLimit($limit)
51 ->setOffset($offset)
52 ->execute();
53 } else {
54 $participation = id(new ConpherenceParticipantQuery())
55 ->withParticipantPHIDs(array($user->getPHID()))
56 ->setLimit($limit)
57 ->setOffset($offset)
58 ->execute();
59 $conpherence_phids = mpull($participation, 'getConpherencePHID');
60 $query->withPHIDs($conpherence_phids);
61 $conpherences = $query->execute();
62 $conpherences = array_select_keys($conpherences, $conpherence_phids);
65 $data = array();
66 foreach ($conpherences as $conpherence) {
67 $id = $conpherence->getID();
68 $data[$id] = array(
69 'conpherenceID' => $id,
70 'conpherencePHID' => $conpherence->getPHID(),
71 'conpherenceTitle' => $conpherence->getTitle(),
72 'messageCount' => $conpherence->getMessageCount(),
73 'conpherenceURI' => $this->getConpherenceURI($conpherence),
76 return $data;