@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Conpherence -- finish off the "show older" functionality

Summary: Fixes T2956. Ref T2399.

Test Plan: set message limit to 2 and verified "show older" showed up, and that clicking it again and again and again showed the right stuff, ultimately not showing a "show older" UI anymore.

Reviewers: epriestley, chad

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2399, T2956

Differential Revision: https://secure.phabricator.com/D5721

+123 -45
+11 -2
src/applications/conpherence/controller/ConpherenceController.php
··· 141 141 142 142 $user = $this->getRequest()->getUser(); 143 143 $transactions = $conpherence->getTransactions(); 144 + $oldest_transaction_id = 0; 145 + $too_many = ConpherenceThreadQuery::TRANSACTION_LIMIT + 1; 146 + if (count($transactions) == $too_many) { 147 + $last_transaction = end($transactions); 148 + unset($transactions[$last_transaction->getID()]); 149 + } 150 + $transactions = array_reverse($transactions); 151 + $oldest_transaction = reset($transactions); 152 + $oldest_transaction_id = $oldest_transaction->getID(); 144 153 $handles = $conpherence->getHandles(); 145 154 $rendered_transactions = array(); 146 155 $engine = id(new PhabricatorMarkupEngine()) ··· 166 175 ->render(); 167 176 } 168 177 $latest_transaction_id = $transaction->getID(); 169 - $rendered_transactions = phutil_implode_html(' ', $rendered_transactions); 170 178 171 179 return array( 172 180 'transactions' => $rendered_transactions, 173 - 'latest_transaction_id' => $latest_transaction_id 181 + 'latest_transaction_id' => $latest_transaction_id, 182 + 'oldest_transaction_id' => $oldest_transaction_id 174 183 ); 175 184 176 185 }
+1 -1
src/applications/conpherence/controller/ConpherenceUpdateController.php
··· 345 345 $user = $this->getRequest()->getUser(); 346 346 $conpherence = id(new ConpherenceThreadQuery()) 347 347 ->setViewer($user) 348 - ->setAfterMessageID($latest_transaction_id) 348 + ->setAfterTransactionID($latest_transaction_id) 349 349 ->needHeaderPics($need_header_pics) 350 350 ->needWidgetData($need_widget_data) 351 351 ->needTransactions($need_transactions)
+56 -29
src/applications/conpherence/controller/ConpherenceViewController.php
··· 37 37 if (!$conpherence_id) { 38 38 return new Aphront404Response(); 39 39 } 40 - $conpherence = id(new ConpherenceThreadQuery()) 40 + $query = id(new ConpherenceThreadQuery()) 41 41 ->setViewer($user) 42 42 ->withIDs(array($conpherence_id)) 43 43 ->needHeaderPics(true) 44 + ->needParticipantCache(true) 44 45 ->needTransactions(true) 45 - ->executeOne(); 46 + ->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT); 47 + $before_transaction_id = $request->getInt('oldest_transaction_id'); 48 + if ($before_transaction_id) { 49 + $query 50 + ->setBeforeTransactionID($before_transaction_id); 51 + } 52 + $conpherence = $query->executeOne(); 46 53 $this->setConpherence($conpherence); 47 54 48 55 $participant = $conpherence->getParticipant($user->getPHID()); ··· 52 59 $participant->markUpToDate($conpherence, $latest_transaction); 53 60 unset($write_guard); 54 61 55 - $header = $this->renderHeaderPaneContent(); 56 - $messages = $this->renderMessagePaneContent(); 57 - $content = $header + $messages; 62 + $data = $this->renderConpherenceTransactions($conpherence); 63 + $messages = $this->renderMessagePaneContent( 64 + $data['transactions'], 65 + $data['oldest_transaction_id']); 66 + if ($before_transaction_id) { 67 + $header = null; 68 + $form = null; 69 + $content = array('messages' => $messages); 70 + } else { 71 + $header = $this->renderHeaderPaneContent(); 72 + $form = $this->renderFormContent($data['latest_transaction_id']); 73 + $content = array( 74 + 'header' => $header, 75 + 'messages' => $messages, 76 + 'form' => $form 77 + ); 78 + } 58 79 59 80 if ($request->isAjax()) { 60 81 return id(new AphrontAjaxResponse())->setContent($content); ··· 64 85 ->setBaseURI($this->getApplicationURI()) 65 86 ->setThread($conpherence) 66 87 ->setHeader($header) 67 - ->setMessages($messages['messages']) 68 - ->setReplyForm($messages['form']) 88 + ->setMessages($messages) 89 + ->setReplyForm($form) 69 90 ->setRole('thread'); 70 91 71 92 return $this->buildApplicationPage( ··· 80 101 require_celerity_resource('conpherence-header-pane-css'); 81 102 $conpherence = $this->getConpherence(); 82 103 $header = $this->buildHeaderPaneContent($conpherence); 83 - return array('header' => hsprintf('%s', $header)); 104 + return hsprintf('%s', $header); 84 105 } 85 106 86 107 87 - private function renderMessagePaneContent() { 108 + private function renderMessagePaneContent( 109 + array $transactions, 110 + $oldest_transaction_id) { 111 + 88 112 require_celerity_resource('conpherence-message-pane-css'); 89 - $user = $this->getRequest()->getUser(); 90 - $conpherence = $this->getConpherence(); 113 + 114 + $scrollbutton = ''; 115 + if ($oldest_transaction_id) { 116 + $scrollbutton = javelin_tag( 117 + 'a', 118 + array( 119 + 'href' => '#', 120 + 'mustcapture' => true, 121 + 'sigil' => 'show-older-messages', 122 + 'class' => 'conpherence-show-older-messages', 123 + 'meta' => array( 124 + 'oldest_transaction_id' => $oldest_transaction_id 125 + ) 126 + ), 127 + pht('Show Older Messages')); 128 + } 129 + 130 + return hsprintf('%s%s', $scrollbutton, $transactions); 131 + } 91 132 92 - $data = $this->renderConpherenceTransactions($conpherence); 93 - $latest_transaction_id = $data['latest_transaction_id']; 94 - $transactions = $data['transactions']; 133 + private function renderFormContent($latest_transaction_id) { 95 134 135 + $conpherence = $this->getConpherence(); 136 + $user = $this->getRequest()->getUser(); 96 137 $update_uri = $this->getApplicationURI('update/'.$conpherence->getID().'/'); 97 138 98 139 Javelin::initBehavior('conpherence-pontificate'); ··· 127 168 '')) 128 169 ->render(); 129 170 130 - $scrollbutton = javelin_tag( 131 - 'a', 132 - array( 133 - 'href' => '#', 134 - 'mustcapture' => true, 135 - 'sigil' => 'show-older-messages', 136 - 'class' => 'conpherence-show-older-messages', 137 - ), 138 - pht('Show Older Messages')); 139 - 140 - return array( 141 - 'messages' => hsprintf('%s%s', $scrollbutton, $transactions), 142 - 'form' => $form 143 - ); 144 - 171 + return $form; 145 172 } 146 173 147 174 }
+35 -8
src/applications/conpherence/query/ConpherenceThreadQuery.php
··· 6 6 final class ConpherenceThreadQuery 7 7 extends PhabricatorCursorPagedPolicyAwareQuery { 8 8 9 + const TRANSACTION_LIMIT = 2; 10 + 9 11 private $phids; 10 12 private $ids; 11 13 private $needWidgetData; ··· 14 16 private $needTransactions; 15 17 private $needParticipantCache; 16 18 private $needFilePHIDs; 17 - private $afterMessageID; 19 + private $afterTransactionID; 20 + private $beforeTransactionID; 21 + private $transactionLimit; 18 22 19 23 public function needFilePHIDs($need_file_phids) { 20 24 $this->needFilePHIDs = $need_file_phids; ··· 56 60 return $this; 57 61 } 58 62 59 - // TODO: This is pretty hacky!!!!~~ 60 - public function setAfterMessageID($id) { 61 - $this->afterMessageID = $id; 63 + public function setAfterTransactionID($id) { 64 + $this->afterTransactionID = $id; 65 + return $this; 66 + } 67 + 68 + public function setBeforeTransactionID($id) { 69 + $this->beforeTransactionID = $id; 70 + return $this; 71 + } 72 + 73 + public function setTransactionLimit($transaction_limit) { 74 + $this->transactionLimit = $transaction_limit; 62 75 return $this; 76 + } 77 + 78 + public function getTransactionLimit() { 79 + return $this->transactionLimit; 63 80 } 64 81 65 82 protected function loadPage() { ··· 164 181 } 165 182 166 183 private function loadTransactionsAndHandles(array $conpherences) { 167 - $transactions = id(new ConpherenceTransactionQuery()) 184 + $query = id(new ConpherenceTransactionQuery()) 168 185 ->setViewer($this->getViewer()) 169 186 ->withObjectPHIDs(array_keys($conpherences)) 170 - ->needHandles(true) 171 - ->setAfterID($this->afterMessageID) 172 - ->execute(); 187 + ->needHandles(true); 173 188 189 + // We have to flip these for the underyling query class. The semantics of 190 + // paging are tricky business. 191 + if ($this->afterTransactionID) { 192 + $query->setBeforeID($this->afterTransactionID); 193 + } else if ($this->beforeTransactionID) { 194 + $query->setAfterID($this->beforeTransactionID); 195 + } 196 + if ($this->getTransactionLimit()) { 197 + // fetch an extra for "show older" scenarios 198 + $query->setLimit($this->getTransactionLimit() + 1); 199 + } 200 + $transactions = $query->execute(); 174 201 $transactions = mgroup($transactions, 'getObjectPHID'); 175 202 foreach ($conpherences as $phid => $conpherence) { 176 203 $current_transactions = $transactions[$phid];
+5
src/applications/conpherence/query/ConpherenceTransactionQuery.php
··· 10 10 return new ConpherenceTransaction(); 11 11 } 12 12 13 + protected function getReversePaging() { 14 + return false; 15 + } 16 + 17 + 13 18 }
+8
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
··· 35 35 return $this; 36 36 } 37 37 38 + final protected function getAfterID() { 39 + return $this->afterID; 40 + } 41 + 38 42 final public function setBeforeID($object_id) { 39 43 $this->beforeID = $object_id; 40 44 return $this; 45 + } 46 + 47 + final protected function getBeforeID() { 48 + return $this->beforeID; 41 49 } 42 50 43 51 final protected function buildLimitClause(AphrontDatabaseConnection $conn_r) {
+7 -5
webroot/rsrc/js/application/conpherence/behavior-menu.js
··· 235 235 236 236 JX.Stratcom.listen('click', 'show-older-messages', function(e) { 237 237 e.kill(); 238 - var last_offset = e.getNodeData('show-older-messages').offset; 239 - var conf_id = e.getNodeData('show-older-messages').ID; 238 + var data = e.getNodeData('show-older-messages'); 239 + var oldest_transaction_id = data.oldest_transaction_id; 240 + var conf_id = thread.selected; 240 241 JX.DOM.remove(e.getNode('show-older-messages')); 241 242 var root = JX.DOM.find(document, 'div', 'conpherence-layout'); 242 243 var messages_root = JX.DOM.find(root, 'div', 'conpherence-messages'); 243 244 new JX.Request(config.base_uri + conf_id + '/', function(r) { 244 245 var messages = JX.$H(r.messages); 245 - JX.DOM.prependContent(messages_root, 246 - JX.$H(messages)); 247 - }).setData({ offset: last_offset+1 }).send(); 246 + JX.DOM.prependContent( 247 + messages_root, 248 + JX.$H(messages)); 249 + }).setData({ oldest_transaction_id : oldest_transaction_id }).send(); 248 250 }); 249 251 250 252