3 final class ConpherenceViewController
extends
4 ConpherenceController
{
6 const OLDER_FETCH_LIMIT
= 5;
8 public function shouldAllowPublic() {
12 public function handleRequest(AphrontRequest
$request) {
13 $user = $request->getUser();
15 $conpherence_id = $request->getURIData('id');
16 if (!$conpherence_id) {
17 return new Aphront404Response();
19 $query = id(new ConpherenceThreadQuery())
21 ->withIDs(array($conpherence_id))
22 ->needProfileImage(true)
23 ->needTransactions(true)
24 ->setTransactionLimit($this->getMainQueryLimit());
26 $before_transaction_id = $request->getInt('oldest_transaction_id');
27 $after_transaction_id = $request->getInt('newest_transaction_id');
28 $old_message_id = $request->getURIData('messageID');
29 if ($before_transaction_id && ($old_message_id ||
$after_transaction_id)) {
30 throw new Aphront400Response();
32 if ($old_message_id && $after_transaction_id) {
33 throw new Aphront400Response();
36 $marker_type = 'older';
37 if ($before_transaction_id) {
39 ->setBeforeTransactionID($before_transaction_id);
41 if ($old_message_id) {
42 $marker_type = 'olderandnewer';
44 ->setAfterTransactionID($old_message_id - 1);
46 if ($after_transaction_id) {
47 $marker_type = 'newer';
49 ->setAfterTransactionID($after_transaction_id);
52 $conpherence = $query->executeOne();
54 return new Aphront404Response();
56 $this->setConpherence($conpherence);
58 $participant = $conpherence->getParticipantIfExists($user->getPHID());
59 $theme = ConpherenceRoomSettings
::COLOR_LIGHT
;
62 $settings = $participant->getSettings();
63 $theme = idx($settings, 'theme', ConpherenceRoomSettings
::COLOR_LIGHT
);
64 if (!$participant->isUpToDate($conpherence)) {
65 $write_guard = AphrontWriteGuard
::beginScopedUnguardedWrites();
66 $participant->markUpToDate($conpherence);
67 $user->clearCacheData(PhabricatorUserMessageCountCacheType
::KEY_COUNT
);
72 $data = ConpherenceTransactionRenderer
::renderTransactions(
76 $messages = ConpherenceTransactionRenderer
::renderMessagePaneContent(
77 $data['transactions'],
78 $data['oldest_transaction_id'],
79 $data['newest_transaction_id']);
80 if ($before_transaction_id ||
$after_transaction_id) {
83 $content = array('transactions' => $messages);
85 $header = $this->buildHeaderPaneContent($conpherence);
86 $search = $this->buildSearchForm();
87 $form = $this->renderFormContent();
91 'transactions' => $messages,
96 $d_data = $conpherence->getDisplayData($user);
97 $content['title'] = $title = $d_data['title'];
99 if ($request->isAjax()) {
100 $dropdown_query = id(new AphlictDropdownDataQuery())
102 $dropdown_query->execute();
103 $content['threadID'] = $conpherence->getID();
104 $content['threadPHID'] = $conpherence->getPHID();
105 $content['latestTransactionID'] = $data['latest_transaction_id'];
106 $content['canEdit'] = PhabricatorPolicyFilter
::hasCapability(
109 PhabricatorPolicyCapability
::CAN_EDIT
);
110 $content['aphlictDropdownData'] = array(
111 $dropdown_query->getNotificationData(),
112 $dropdown_query->getConpherenceData(),
114 return id(new AphrontAjaxResponse())->setContent($content);
117 $layout = id(new ConpherenceLayoutView())
119 ->setBaseURI($this->getApplicationURI())
120 ->setThread($conpherence)
123 ->setMessages($messages)
124 ->setReplyForm($form)
126 ->setLatestTransactionID($data['latest_transaction_id'])
129 $participating = $conpherence->getParticipantIfExists($user->getPHID());
131 if (!$user->isLoggedIn()) {
132 $layout->addClass('conpherence-no-pontificate');
135 return $this->newPage()
137 ->setPageObjectPHIDs(array($conpherence->getPHID()))
138 ->appendChild($layout);
141 private function renderFormContent() {
143 $conpherence = $this->getConpherence();
144 $user = $this->getRequest()->getUser();
146 $participating = $conpherence->getParticipantIfExists($user->getPHID());
147 $draft = PhabricatorDraft
::newFromUserAndKey(
149 $conpherence->getPHID());
150 $update_uri = $this->getApplicationURI('update/'.$conpherence->getID().'/');
152 if ($user->isLoggedIn()) {
153 $this->initBehavior('conpherence-pontificate');
154 if ($participating) {
155 $action = ConpherenceUpdateActions
::MESSAGE
;
156 $status = new PhabricatorNotificationStatusView();
158 $action = ConpherenceUpdateActions
::JOIN_ROOM
;
159 $status = pht('Sending a message will also join the room.');
162 $form = id(new AphrontFormView())
164 ->setAction($update_uri)
165 ->addSigil('conpherence-pontificate')
167 ->addHiddenInput('action', $action)
169 id(new PhabricatorRemarkupControl())
172 ->setSendOnEnter(true)
173 ->setValue($draft->getDraft()));
175 $status_view = phutil_tag(
178 'class' => 'conpherence-room-status',
179 'id' => 'conpherence-room-status',
183 $view = phutil_tag_div(
184 'pontificate-container', array($form, $status_view));
189 // user not logged in so give them a login button.
190 $login_href = id(new PhutilURI('/auth/start/'))
191 ->replaceQueryParam('next', '/'.$conpherence->getMonogram());
192 return id(new PHUIFormLayoutView())
193 ->addClass('login-to-participate')
194 ->appendInstructions(pht('Log in to join this room and participate.'))
196 id(new PHUIButtonView())
198 ->setText(pht('Log In to Participate'))
199 ->setHref((string)$login_href));
203 private function getMainQueryLimit() {
204 $request = $this->getRequest();
205 $base_limit = ConpherenceThreadQuery
::TRANSACTION_LIMIT
;
206 if ($request->getURIData('messageID')) {
207 $base_limit = $base_limit - self
::OLDER_FETCH_LIMIT
;