public function handleRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $conpherence_id = $request->getURIData('id');
     if (!$conpherence_id) {
         return new Aphront404Response();
     }
     $query = id(new ConpherenceThreadQuery())->setViewer($user)->withIDs(array($conpherence_id))->needProfileImage(true)->needParticipantCache(true)->needTransactions(true)->setTransactionLimit($this->getMainQueryLimit());
     $before_transaction_id = $request->getInt('oldest_transaction_id');
     $after_transaction_id = $request->getInt('newest_transaction_id');
     $old_message_id = $request->getURIData('messageID');
     if ($before_transaction_id && ($old_message_id || $after_transaction_id)) {
         throw new Aphront400Response();
     }
     if ($old_message_id && $after_transaction_id) {
         throw new Aphront400Response();
     }
     $marker_type = 'older';
     if ($before_transaction_id) {
         $query->setBeforeTransactionID($before_transaction_id);
     }
     if ($old_message_id) {
         $marker_type = 'olderandnewer';
         $query->setAfterTransactionID($old_message_id - 1);
     }
     if ($after_transaction_id) {
         $marker_type = 'newer';
         $query->setAfterTransactionID($after_transaction_id);
     }
     $conpherence = $query->executeOne();
     if (!$conpherence) {
         return new Aphront404Response();
     }
     $this->setConpherence($conpherence);
     $transactions = $this->getNeededTransactions($conpherence, $old_message_id);
     $latest_transaction = head($transactions);
     $participant = $conpherence->getParticipantIfExists($user->getPHID());
     if ($participant) {
         if (!$participant->isUpToDate($conpherence)) {
             $write_guard = AphrontWriteGuard::beginScopedUnguardedWrites();
             $participant->markUpToDate($conpherence, $latest_transaction);
             $user->clearCacheData(PhabricatorUserMessageCountCacheType::KEY_COUNT);
             unset($write_guard);
         }
     }
     $data = ConpherenceTransactionRenderer::renderTransactions($user, $conpherence, $marker_type);
     $messages = ConpherenceTransactionRenderer::renderMessagePaneContent($data['transactions'], $data['oldest_transaction_id'], $data['newest_transaction_id']);
     if ($before_transaction_id || $after_transaction_id) {
         $header = null;
         $form = null;
         $content = array('transactions' => $messages);
     } else {
         $policy_objects = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($conpherence)->execute();
         $header = $this->buildHeaderPaneContent($conpherence, $policy_objects);
         $search = $this->buildSearchForm();
         $form = $this->renderFormContent();
         $content = array('header' => $header, 'search' => $search, 'transactions' => $messages, 'form' => $form);
     }
     $d_data = $conpherence->getDisplayData($user);
     $content['title'] = $title = $d_data['title'];
     if ($request->isAjax()) {
         $dropdown_query = id(new AphlictDropdownDataQuery())->setViewer($user);
         $dropdown_query->execute();
         $content['threadID'] = $conpherence->getID();
         $content['threadPHID'] = $conpherence->getPHID();
         $content['latestTransactionID'] = $data['latest_transaction_id'];
         $content['canEdit'] = PhabricatorPolicyFilter::hasCapability($user, $conpherence, PhabricatorPolicyCapability::CAN_EDIT);
         $content['aphlictDropdownData'] = array($dropdown_query->getNotificationData(), $dropdown_query->getConpherenceData());
         return id(new AphrontAjaxResponse())->setContent($content);
     }
     $can_join = PhabricatorPolicyFilter::hasCapability($user, $conpherence, PhabricatorPolicyCapability::CAN_JOIN);
     $layout = id(new ConpherenceLayoutView())->setUser($user)->setBaseURI($this->getApplicationURI())->setThread($conpherence)->setHeader($header)->setSearch($search)->setMessages($messages)->setReplyForm($form)->setLatestTransactionID($data['latest_transaction_id'])->setRole('thread');
     $participating = $conpherence->getParticipantIfExists($user->getPHID());
     if (!$user->isLoggedIn()) {
         $layout->addClass('conpherence-no-pontificate');
     }
     return $this->newPage()->setTitle($title)->setPageObjectPHIDs(array($conpherence->getPHID()))->appendChild($layout);
 }
 private function loadAndRenderUpdates($action, $conpherence_id, $latest_transaction_id)
 {
     $minimal_display = $this->getRequest()->getExists('minimal_display');
     $need_widget_data = false;
     $need_transactions = false;
     $need_participant_cache = true;
     switch ($action) {
         case ConpherenceUpdateActions::METADATA:
         case ConpherenceUpdateActions::LOAD:
             $need_transactions = true;
             break;
         case ConpherenceUpdateActions::MESSAGE:
         case ConpherenceUpdateActions::ADD_PERSON:
             $need_transactions = true;
             $need_widget_data = !$minimal_display;
             break;
         case ConpherenceUpdateActions::REMOVE_PERSON:
         case ConpherenceUpdateActions::NOTIFICATIONS:
         default:
             break;
     }
     $user = $this->getRequest()->getUser();
     $conpherence = id(new ConpherenceThreadQuery())->setViewer($user)->setAfterTransactionID($latest_transaction_id)->needCropPics(true)->needParticipantCache($need_participant_cache)->needWidgetData($need_widget_data)->needTransactions($need_transactions)->withIDs(array($conpherence_id))->executeOne();
     $non_update = false;
     if ($need_transactions && $conpherence->getTransactions()) {
         $data = ConpherenceTransactionRenderer::renderTransactions($user, $conpherence, !$minimal_display);
         $participant_obj = $conpherence->getParticipant($user->getPHID());
         $participant_obj->markUpToDate($conpherence, $data['latest_transaction']);
     } else {
         if ($need_transactions) {
             $non_update = true;
             $data = array();
         } else {
             $data = array();
         }
     }
     $rendered_transactions = idx($data, 'transactions');
     $new_latest_transaction_id = idx($data, 'latest_transaction_id');
     $widget_uri = $this->getApplicationURI('update/' . $conpherence->getID() . '/');
     $nav_item = null;
     $header = null;
     $people_widget = null;
     $file_widget = null;
     if (!$minimal_display) {
         switch ($action) {
             case ConpherenceUpdateActions::METADATA:
                 $policy_objects = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($conpherence)->execute();
                 $header = $this->buildHeaderPaneContent($conpherence, $policy_objects);
                 $header = hsprintf('%s', $header);
                 $nav_item = id(new ConpherenceThreadListView())->setUser($user)->setBaseURI($this->getApplicationURI())->renderSingleThread($conpherence, $policy_objects);
                 $nav_item = hsprintf('%s', $nav_item);
                 break;
             case ConpherenceUpdateActions::MESSAGE:
                 $file_widget = id(new ConpherenceFileWidgetView())->setUser($this->getRequest()->getUser())->setConpherence($conpherence)->setUpdateURI($widget_uri);
                 $file_widget = hsprintf('%s', $file_widget->render());
                 break;
             case ConpherenceUpdateActions::ADD_PERSON:
                 $people_widget = id(new ConpherencePeopleWidgetView())->setUser($user)->setConpherence($conpherence)->setUpdateURI($widget_uri);
                 $people_widget = hsprintf('%s', $people_widget->render());
                 break;
             case ConpherenceUpdateActions::REMOVE_PERSON:
             case ConpherenceUpdateActions::NOTIFICATIONS:
             default:
                 break;
         }
     }
     $data = $conpherence->getDisplayData($user);
     $dropdown_query = id(new AphlictDropdownDataQuery())->setViewer($user);
     $dropdown_query->execute();
     $content = array('non_update' => $non_update, 'transactions' => hsprintf('%s', $rendered_transactions), 'conpherence_title' => (string) $data['title'], 'latest_transaction_id' => $new_latest_transaction_id, 'nav_item' => $nav_item, 'conpherence_phid' => $conpherence->getPHID(), 'header' => $header, 'file_widget' => $file_widget, 'people_widget' => $people_widget, 'aphlictDropdownData' => array($dropdown_query->getNotificationData(), $dropdown_query->getConpherenceData()));
     return $content;
 }
 private function buildTransactions()
 {
     $conpherence = $this->getSelectedConpherence();
     if (!$conpherence) {
         if (!$this->getVisible() || $this->getInitialLoad()) {
             return pht('Loading...');
         }
         return array(phutil_tag('div', array('class' => 'mmb'), pht('You are not in any rooms yet.')), javelin_tag('a', array('href' => '/conpherence/new/', 'class' => 'button grey', 'sigil' => 'workflow'), pht('Create a Room')));
     }
     $data = ConpherenceTransactionRenderer::renderTransactions($this->getUser(), $conpherence, $full_display = false);
     $messages = ConpherenceTransactionRenderer::renderMessagePaneContent($data['transactions'], $data['oldest_transaction_id'], $data['newest_transaction_id']);
     return $messages;
 }
 private function buildTransactions()
 {
     $conpherence = $this->getSelectedConpherence();
     if (!$conpherence) {
         if (!$this->getVisible() || $this->getInitialLoad()) {
             return pht('Loading...');
         }
         $view = array(phutil_tag('div', array('class' => 'column-no-rooms-text'), pht('You have not joined any rooms yet.')), javelin_tag('a', array('href' => '/conpherence/search/', 'class' => 'button grey'), pht('Find Rooms')));
         return phutil_tag_div('column-no-rooms', $view);
     }
     $data = ConpherenceTransactionRenderer::renderTransactions($this->getUser(), $conpherence);
     $messages = ConpherenceTransactionRenderer::renderMessagePaneContent($data['transactions'], $data['oldest_transaction_id'], $data['newest_transaction_id']);
     return $messages;
 }