@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 211 lines 6.8 kB view raw
1<?php 2 3final class ConpherenceViewController extends 4 ConpherenceController { 5 6 const OLDER_FETCH_LIMIT = 5; 7 8 public function shouldAllowPublic() { 9 return true; 10 } 11 12 public function handleRequest(AphrontRequest $request) { 13 $user = $request->getUser(); 14 15 $conpherence_id = $request->getURIData('id'); 16 if (!$conpherence_id) { 17 return new Aphront404Response(); 18 } 19 $query = id(new ConpherenceThreadQuery()) 20 ->setViewer($user) 21 ->withIDs(array($conpherence_id)) 22 ->needProfileImage(true) 23 ->needTransactions(true) 24 ->setTransactionLimit($this->getMainQueryLimit()); 25 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 return new Aphront400Response(); 31 } 32 if ($old_message_id && $after_transaction_id) { 33 return new Aphront400Response(); 34 } 35 36 $marker_type = 'older'; 37 if ($before_transaction_id) { 38 $query 39 ->setBeforeTransactionID($before_transaction_id); 40 } 41 if ($old_message_id) { 42 $marker_type = 'olderandnewer'; 43 $query 44 ->setAfterTransactionID($old_message_id - 1); 45 } 46 if ($after_transaction_id) { 47 $marker_type = 'newer'; 48 $query 49 ->setAfterTransactionID($after_transaction_id); 50 } 51 52 $conpherence = $query->executeOne(); 53 if (!$conpherence) { 54 return new Aphront404Response(); 55 } 56 $this->setConpherence($conpherence); 57 58 $participant = $conpherence->getParticipantIfExists($user->getPHID()); 59 $theme = ConpherenceRoomSettings::COLOR_LIGHT; 60 61 if ($participant) { 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); 68 unset($write_guard); 69 } 70 } 71 72 $data = ConpherenceTransactionRenderer::renderTransactions( 73 $user, 74 $conpherence, 75 $marker_type); 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) { 81 $header = null; 82 $form = null; 83 $content = array('transactions' => $messages); 84 } else { 85 $header = $this->buildHeaderPaneContent($conpherence); 86 $search = $this->buildSearchForm(); 87 $form = $this->renderFormContent(); 88 $content = array( 89 'header' => $header, 90 'search' => $search, 91 'transactions' => $messages, 92 'form' => $form, 93 ); 94 } 95 96 $d_data = $conpherence->getDisplayData($user); 97 $content['title'] = $title = $d_data['title']; 98 99 if ($request->isAjax()) { 100 $dropdown_query = id(new AphlictDropdownDataQuery()) 101 ->setViewer($user); 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( 107 $user, 108 $conpherence, 109 PhabricatorPolicyCapability::CAN_EDIT); 110 $content['aphlictDropdownData'] = array( 111 $dropdown_query->getNotificationData(), 112 $dropdown_query->getConpherenceData(), 113 ); 114 return id(new AphrontAjaxResponse())->setContent($content); 115 } 116 117 $layout = id(new ConpherenceLayoutView()) 118 ->setViewer($user) 119 ->setBaseURI($this->getApplicationURI()) 120 ->setThread($conpherence) 121 ->setHeader($header) 122 ->setSearch($search) 123 ->setMessages($messages) 124 ->setReplyForm($form) 125 ->setTheme($theme) 126 ->setLatestTransactionID($data['latest_transaction_id']) 127 ->setRole('thread'); 128 129 $participating = $conpherence->getParticipantIfExists($user->getPHID()); 130 131 if (!$user->isLoggedIn()) { 132 $layout->addClass('conpherence-no-pontificate'); 133 } 134 135 return $this->newPage() 136 ->setTitle($title) 137 ->setPageObjectPHIDs(array($conpherence->getPHID())) 138 ->appendChild($layout); 139 } 140 141 private function renderFormContent() { 142 143 $conpherence = $this->getConpherence(); 144 $user = $this->getRequest()->getUser(); 145 146 $participating = $conpherence->getParticipantIfExists($user->getPHID()); 147 $draft = PhabricatorDraft::newFromUserAndKey( 148 $user, 149 $conpherence->getPHID()); 150 $update_uri = $this->getApplicationURI('update/'.$conpherence->getID().'/'); 151 152 if ($user->isLoggedIn()) { 153 $this->initBehavior('conpherence-pontificate'); 154 if ($participating) { 155 $action = ConpherenceUpdateActions::MESSAGE; 156 $status = new PhabricatorNotificationStatusView(); 157 } else { 158 $action = ConpherenceUpdateActions::JOIN_ROOM; 159 $status = pht('Sending a message will also join the room.'); 160 } 161 162 $form = id(new AphrontFormView()) 163 ->setViewer($user) 164 ->setAction($update_uri) 165 ->addSigil('conpherence-pontificate') 166 ->setWorkflow(true) 167 ->addHiddenInput('action', $action) 168 ->appendChild( 169 id(new PhabricatorRemarkupControl()) 170 ->setViewer($user) 171 ->setName('text') 172 ->setSendOnEnter(true) 173 ->setValue($draft->getDraft())); 174 175 $status_view = phutil_tag( 176 'div', 177 array( 178 'class' => 'conpherence-room-status', 179 'id' => 'conpherence-room-status', 180 ), 181 $status); 182 183 $view = phutil_tag_div( 184 'pontificate-container', array($form, $status_view)); 185 186 return $view; 187 188 } else { 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.')) 195 ->appendChild( 196 id(new PHUIButtonView()) 197 ->setTag('a') 198 ->setText(pht('Log In to Participate')) 199 ->setHref((string)$login_href)); 200 } 201 } 202 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; 208 } 209 return $base_limit; 210 } 211}