3 final class ConpherenceListController
extends ConpherenceController
{
5 const SELECTED_MODE
= 'selected';
6 const UNSELECTED_MODE
= 'unselected';
9 * Two main modes of operation...
11 * 1 - /conpherence/ - UNSELECTED_MODE
12 * 2 - /conpherence/<id>/ - SELECTED_MODE
14 * UNSELECTED_MODE is not an Ajax request while the other two are Ajax
17 private function determineMode() {
18 $request = $this->getRequest();
20 $mode = self
::UNSELECTED_MODE
;
21 if ($request->isAjax()) {
22 $mode = self
::SELECTED_MODE
;
28 public function shouldAllowPublic() {
32 public function handleRequest(AphrontRequest
$request) {
33 $user = $request->getUser();
34 $title = pht('Conpherence');
37 $limit = ConpherenceThreadListView
::SEE_ALL_LIMIT +
1;
38 $all_participation = array();
40 $mode = $this->determineMode();
42 case self
::SELECTED_MODE
:
43 $conpherence_id = $request->getURIData('id');
44 $conpherence = id(new ConpherenceThreadQuery())
46 ->withIDs(array($conpherence_id))
49 return new Aphront404Response();
51 if ($conpherence->getTitle()) {
52 $title = $conpherence->getTitle();
54 $cursor = $conpherence->getParticipantIfExists($user->getPHID());
55 $data = $this->loadDefaultParticipation($limit);
56 $all_participation = $data['all_participation'];
58 $menu_participation = id(new ConpherenceParticipant())
60 ->setConpherencePHID($conpherence->getPHID())
61 ->setParticipantPHID($user->getPHID());
63 $menu_participation = $cursor;
66 // check to see if the loaded conpherence is going to show up
67 // within the SEE_ALL_LIMIT amount of conpherences.
68 // If its not there, then we just pre-pend it as the "first"
69 // conpherence so folks have a navigation item in the menu.
72 foreach ($all_participation as $phid => $curr_participation) {
73 if ($conpherence->getPHID() == $phid) {
78 if ($count > ConpherenceThreadListView
::SEE_ALL_LIMIT
) {
84 array($conpherence->getPHID() => $menu_participation) +
88 case self
::UNSELECTED_MODE
:
90 $data = $this->loadDefaultParticipation($limit);
91 $all_participation = $data['all_participation'];
92 if ($all_participation) {
93 $conpherence_id = head($all_participation)->getConpherencePHID();
94 $conpherence = id(new ConpherenceThreadQuery())
96 ->withPHIDs(array($conpherence_id))
97 ->needProfileImage(true)
100 // If $conpherence is null, NUX state will render
104 $threads = $this->loadConpherenceThreadData($all_participation);
106 $thread_view = id(new ConpherenceThreadListView())
108 ->setBaseURI($this->getApplicationURI())
109 ->setThreads($threads);
112 case self
::SELECTED_MODE
:
113 $response = id(new AphrontAjaxResponse())->setContent($thread_view);
115 case self
::UNSELECTED_MODE
:
117 $layout = id(new ConpherenceLayoutView())
119 ->setBaseURI($this->getApplicationURI())
120 ->setThreadView($thread_view)
123 $layout->setThread($conpherence);
125 // make a dummy conpherence so we can render something
126 $conpherence = ConpherenceThread
::initializeNewRoom($user);
127 $conpherence->attachHandles(array());
128 $conpherence->attachTransactions(array());
129 $conpherence->makeEphemeral();
131 $policy_objects = id(new PhabricatorPolicyQuery())
133 ->setObject($conpherence)
135 $layout->setHeader($this->buildHeaderPaneContent(
138 $response = $this->newPage()
140 ->appendChild($layout);
148 private function loadDefaultParticipation($limit) {
149 $viewer = $this->getRequest()->getUser();
151 $all_participation = id(new ConpherenceParticipantQuery())
152 ->withParticipantPHIDs(array($viewer->getPHID()))
155 $all_participation = mpull($all_participation, null, 'getConpherencePHID');
158 'all_participation' => $all_participation,
162 private function loadConpherenceThreadData($participation) {
163 $user = $this->getRequest()->getUser();
164 $conpherence_phids = array_keys($participation);
165 $conpherences = array();
166 if ($conpherence_phids) {
167 $conpherences = id(new ConpherenceThreadQuery())
169 ->withPHIDs($conpherence_phids)
170 ->needProfileImage(true)
173 // this will re-sort by participation data
174 $conpherences = array_select_keys($conpherences, $conpherence_phids);
177 return $conpherences;