Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / conpherence / controller / ConpherenceColumnViewController.php
blob3bd0c6b111d4f4927c843c8242a0b755026b62a6
1 <?php
3 final class ConpherenceColumnViewController extends
4 ConpherenceController {
6 public function handleRequest(AphrontRequest $request) {
7 $user = $request->getUser();
9 $latest_conpherences = array();
10 $latest_participant = id(new ConpherenceParticipantQuery())
11 ->withParticipantPHIDs(array($user->getPHID()))
12 ->setLimit(8)
13 ->execute();
14 if ($latest_participant) {
15 $conpherence_phids = mpull($latest_participant, 'getConpherencePHID');
16 $latest_conpherences = id(new ConpherenceThreadQuery())
17 ->setViewer($user)
18 ->withPHIDs($conpherence_phids)
19 ->needProfileImage(true)
20 ->execute();
21 $latest_conpherences = mpull($latest_conpherences, null, 'getPHID');
22 $latest_conpherences = array_select_keys(
23 $latest_conpherences,
24 $conpherence_phids);
27 $conpherence = null;
28 $should_404 = false;
29 if ($request->getInt('id')) {
30 $conpherence = id(new ConpherenceThreadQuery())
31 ->setViewer($user)
32 ->withIDs(array($request->getInt('id')))
33 ->needProfileImage(true)
34 ->needTransactions(true)
35 ->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT)
36 ->executeOne();
37 $should_404 = true;
38 } else if ($latest_participant) {
39 $participant = head($latest_participant);
40 $conpherence = id(new ConpherenceThreadQuery())
41 ->setViewer($user)
42 ->withPHIDs(array($participant->getConpherencePHID()))
43 ->needProfileImage(true)
44 ->needTransactions(true)
45 ->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT)
46 ->executeOne();
47 $should_404 = true;
50 $durable_column = id(new ConpherenceDurableColumnView())
51 ->setUser($user)
52 ->setVisible(true);
53 if (!$conpherence) {
54 if ($should_404) {
55 return new Aphront404Response();
58 $conpherence_id = null;
59 $conpherence_phid = null;
60 $latest_transaction_id = null;
61 $can_edit = false;
63 } else {
64 $this->setConpherence($conpherence);
66 $participant = $conpherence->getParticipant($user->getPHID());
67 $transactions = $conpherence->getTransactions();
68 $latest_transaction = head($transactions);
69 $write_guard = AphrontWriteGuard::beginScopedUnguardedWrites();
70 $participant->markUpToDate($conpherence);
71 unset($write_guard);
73 $draft = PhabricatorDraft::newFromUserAndKey(
74 $user,
75 $conpherence->getPHID());
77 $durable_column
78 ->setDraft($draft)
79 ->setSelectedConpherence($conpherence)
80 ->setConpherences($latest_conpherences);
81 $conpherence_id = $conpherence->getID();
82 $conpherence_phid = $conpherence->getPHID();
83 $latest_transaction_id = $latest_transaction->getID();
84 $can_edit = PhabricatorPolicyFilter::hasCapability(
85 $user,
86 $conpherence,
87 PhabricatorPolicyCapability::CAN_EDIT);
90 $dropdown_query = id(new AphlictDropdownDataQuery())
91 ->setViewer($user);
92 $dropdown_query->execute();
93 $response = array(
94 'content' => hsprintf('%s', $durable_column),
95 'threadID' => $conpherence_id,
96 'threadPHID' => $conpherence_phid,
97 'latestTransactionID' => $latest_transaction_id,
98 'canEdit' => $can_edit,
99 'aphlictDropdownData' => array(
100 $dropdown_query->getNotificationData(),
101 $dropdown_query->getConpherenceData(),
105 return id(new AphrontAjaxResponse())->setContent($response);