Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conpherence/controller/ConpherenceListController.php
12256 views
1
<?php
2
3
final class ConpherenceListController extends ConpherenceController {
4
5
const SELECTED_MODE = 'selected';
6
const UNSELECTED_MODE = 'unselected';
7
8
/**
9
* Two main modes of operation...
10
*
11
* 1 - /conpherence/ - UNSELECTED_MODE
12
* 2 - /conpherence/<id>/ - SELECTED_MODE
13
*
14
* UNSELECTED_MODE is not an Ajax request while the other two are Ajax
15
* requests.
16
*/
17
private function determineMode() {
18
$request = $this->getRequest();
19
20
$mode = self::UNSELECTED_MODE;
21
if ($request->isAjax()) {
22
$mode = self::SELECTED_MODE;
23
}
24
25
return $mode;
26
}
27
28
public function shouldAllowPublic() {
29
return true;
30
}
31
32
public function handleRequest(AphrontRequest $request) {
33
$user = $request->getUser();
34
$title = pht('Conpherence');
35
$conpherence = null;
36
37
$limit = ConpherenceThreadListView::SEE_ALL_LIMIT + 1;
38
$all_participation = array();
39
40
$mode = $this->determineMode();
41
switch ($mode) {
42
case self::SELECTED_MODE:
43
$conpherence_id = $request->getURIData('id');
44
$conpherence = id(new ConpherenceThreadQuery())
45
->setViewer($user)
46
->withIDs(array($conpherence_id))
47
->executeOne();
48
if (!$conpherence) {
49
return new Aphront404Response();
50
}
51
if ($conpherence->getTitle()) {
52
$title = $conpherence->getTitle();
53
}
54
$cursor = $conpherence->getParticipantIfExists($user->getPHID());
55
$data = $this->loadDefaultParticipation($limit);
56
$all_participation = $data['all_participation'];
57
if (!$cursor) {
58
$menu_participation = id(new ConpherenceParticipant())
59
->makeEphemeral()
60
->setConpherencePHID($conpherence->getPHID())
61
->setParticipantPHID($user->getPHID());
62
} else {
63
$menu_participation = $cursor;
64
}
65
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.
70
$count = 0;
71
$found = false;
72
foreach ($all_participation as $phid => $curr_participation) {
73
if ($conpherence->getPHID() == $phid) {
74
$found = true;
75
break;
76
}
77
$count++;
78
if ($count > ConpherenceThreadListView::SEE_ALL_LIMIT) {
79
break;
80
}
81
}
82
if (!$found) {
83
$all_participation =
84
array($conpherence->getPHID() => $menu_participation) +
85
$all_participation;
86
}
87
break;
88
case self::UNSELECTED_MODE:
89
default:
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())
95
->setViewer($user)
96
->withPHIDs(array($conpherence_id))
97
->needProfileImage(true)
98
->executeOne();
99
}
100
// If $conpherence is null, NUX state will render
101
break;
102
}
103
104
$threads = $this->loadConpherenceThreadData($all_participation);
105
106
$thread_view = id(new ConpherenceThreadListView())
107
->setUser($user)
108
->setBaseURI($this->getApplicationURI())
109
->setThreads($threads);
110
111
switch ($mode) {
112
case self::SELECTED_MODE:
113
$response = id(new AphrontAjaxResponse())->setContent($thread_view);
114
break;
115
case self::UNSELECTED_MODE:
116
default:
117
$layout = id(new ConpherenceLayoutView())
118
->setUser($user)
119
->setBaseURI($this->getApplicationURI())
120
->setThreadView($thread_view)
121
->setRole('list');
122
if ($conpherence) {
123
$layout->setThread($conpherence);
124
} else {
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();
130
}
131
$policy_objects = id(new PhabricatorPolicyQuery())
132
->setViewer($user)
133
->setObject($conpherence)
134
->execute();
135
$layout->setHeader($this->buildHeaderPaneContent(
136
$conpherence,
137
$policy_objects));
138
$response = $this->newPage()
139
->setTitle($title)
140
->appendChild($layout);
141
break;
142
}
143
144
return $response;
145
146
}
147
148
private function loadDefaultParticipation($limit) {
149
$viewer = $this->getRequest()->getUser();
150
151
$all_participation = id(new ConpherenceParticipantQuery())
152
->withParticipantPHIDs(array($viewer->getPHID()))
153
->setLimit($limit)
154
->execute();
155
$all_participation = mpull($all_participation, null, 'getConpherencePHID');
156
157
return array(
158
'all_participation' => $all_participation,
159
);
160
}
161
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())
168
->setViewer($user)
169
->withPHIDs($conpherence_phids)
170
->needProfileImage(true)
171
->execute();
172
173
// this will re-sort by participation data
174
$conpherences = array_select_keys($conpherences, $conpherence_phids);
175
}
176
177
return $conpherences;
178
}
179
180
}
181
182