Path: blob/master/src/applications/conpherence/controller/ConpherenceViewController.php
12256 views
<?php12final class ConpherenceViewController extends3ConpherenceController {45const OLDER_FETCH_LIMIT = 5;67public function shouldAllowPublic() {8return true;9}1011public function handleRequest(AphrontRequest $request) {12$user = $request->getUser();1314$conpherence_id = $request->getURIData('id');15if (!$conpherence_id) {16return new Aphront404Response();17}18$query = id(new ConpherenceThreadQuery())19->setViewer($user)20->withIDs(array($conpherence_id))21->needProfileImage(true)22->needTransactions(true)23->setTransactionLimit($this->getMainQueryLimit());2425$before_transaction_id = $request->getInt('oldest_transaction_id');26$after_transaction_id = $request->getInt('newest_transaction_id');27$old_message_id = $request->getURIData('messageID');28if ($before_transaction_id && ($old_message_id || $after_transaction_id)) {29throw new Aphront400Response();30}31if ($old_message_id && $after_transaction_id) {32throw new Aphront400Response();33}3435$marker_type = 'older';36if ($before_transaction_id) {37$query38->setBeforeTransactionID($before_transaction_id);39}40if ($old_message_id) {41$marker_type = 'olderandnewer';42$query43->setAfterTransactionID($old_message_id - 1);44}45if ($after_transaction_id) {46$marker_type = 'newer';47$query48->setAfterTransactionID($after_transaction_id);49}5051$conpherence = $query->executeOne();52if (!$conpherence) {53return new Aphront404Response();54}55$this->setConpherence($conpherence);5657$participant = $conpherence->getParticipantIfExists($user->getPHID());58$theme = ConpherenceRoomSettings::COLOR_LIGHT;5960if ($participant) {61$settings = $participant->getSettings();62$theme = idx($settings, 'theme', ConpherenceRoomSettings::COLOR_LIGHT);63if (!$participant->isUpToDate($conpherence)) {64$write_guard = AphrontWriteGuard::beginScopedUnguardedWrites();65$participant->markUpToDate($conpherence);66$user->clearCacheData(PhabricatorUserMessageCountCacheType::KEY_COUNT);67unset($write_guard);68}69}7071$data = ConpherenceTransactionRenderer::renderTransactions(72$user,73$conpherence,74$marker_type);75$messages = ConpherenceTransactionRenderer::renderMessagePaneContent(76$data['transactions'],77$data['oldest_transaction_id'],78$data['newest_transaction_id']);79if ($before_transaction_id || $after_transaction_id) {80$header = null;81$form = null;82$content = array('transactions' => $messages);83} else {84$header = $this->buildHeaderPaneContent($conpherence);85$search = $this->buildSearchForm();86$form = $this->renderFormContent();87$content = array(88'header' => $header,89'search' => $search,90'transactions' => $messages,91'form' => $form,92);93}9495$d_data = $conpherence->getDisplayData($user);96$content['title'] = $title = $d_data['title'];9798if ($request->isAjax()) {99$dropdown_query = id(new AphlictDropdownDataQuery())100->setViewer($user);101$dropdown_query->execute();102$content['threadID'] = $conpherence->getID();103$content['threadPHID'] = $conpherence->getPHID();104$content['latestTransactionID'] = $data['latest_transaction_id'];105$content['canEdit'] = PhabricatorPolicyFilter::hasCapability(106$user,107$conpherence,108PhabricatorPolicyCapability::CAN_EDIT);109$content['aphlictDropdownData'] = array(110$dropdown_query->getNotificationData(),111$dropdown_query->getConpherenceData(),112);113return id(new AphrontAjaxResponse())->setContent($content);114}115116$layout = id(new ConpherenceLayoutView())117->setUser($user)118->setBaseURI($this->getApplicationURI())119->setThread($conpherence)120->setHeader($header)121->setSearch($search)122->setMessages($messages)123->setReplyForm($form)124->setTheme($theme)125->setLatestTransactionID($data['latest_transaction_id'])126->setRole('thread');127128$participating = $conpherence->getParticipantIfExists($user->getPHID());129130if (!$user->isLoggedIn()) {131$layout->addClass('conpherence-no-pontificate');132}133134return $this->newPage()135->setTitle($title)136->setPageObjectPHIDs(array($conpherence->getPHID()))137->appendChild($layout);138}139140private function renderFormContent() {141142$conpherence = $this->getConpherence();143$user = $this->getRequest()->getUser();144145$participating = $conpherence->getParticipantIfExists($user->getPHID());146$draft = PhabricatorDraft::newFromUserAndKey(147$user,148$conpherence->getPHID());149$update_uri = $this->getApplicationURI('update/'.$conpherence->getID().'/');150151if ($user->isLoggedIn()) {152$this->initBehavior('conpherence-pontificate');153if ($participating) {154$action = ConpherenceUpdateActions::MESSAGE;155$status = new PhabricatorNotificationStatusView();156} else {157$action = ConpherenceUpdateActions::JOIN_ROOM;158$status = pht('Sending a message will also join the room.');159}160161$form = id(new AphrontFormView())162->setUser($user)163->setAction($update_uri)164->addSigil('conpherence-pontificate')165->setWorkflow(true)166->addHiddenInput('action', $action)167->appendChild(168id(new PhabricatorRemarkupControl())169->setUser($user)170->setName('text')171->setSendOnEnter(true)172->setValue($draft->getDraft()));173174$status_view = phutil_tag(175'div',176array(177'class' => 'conpherence-room-status',178'id' => 'conpherence-room-status',179),180$status);181182$view = phutil_tag_div(183'pontificate-container', array($form, $status_view));184185return $view;186187} else {188// user not logged in so give them a login button.189$login_href = id(new PhutilURI('/auth/start/'))190->replaceQueryParam('next', '/'.$conpherence->getMonogram());191return id(new PHUIFormLayoutView())192->addClass('login-to-participate')193->appendInstructions(pht('Log in to join this room and participate.'))194->appendChild(195id(new PHUIButtonView())196->setTag('a')197->setText(pht('Log In to Participate'))198->setHref((string)$login_href));199}200}201202private function getMainQueryLimit() {203$request = $this->getRequest();204$base_limit = ConpherenceThreadQuery::TRANSACTION_LIMIT;205if ($request->getURIData('messageID')) {206$base_limit = $base_limit - self::OLDER_FETCH_LIMIT;207}208return $base_limit;209}210}211212213