@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 196 lines 6.8 kB view raw
1<?php 2 3final class ConpherenceTransactionRenderer extends Phobject { 4 5 public static function renderTransactions( 6 PhabricatorUser $user, 7 ConpherenceThread $conpherence, 8 $marker_type = 'older') { 9 10 $transactions = $conpherence->getTransactions(); 11 12 $oldest_transaction_id = 0; 13 $newest_transaction_id = 0; 14 $too_many = ConpherenceThreadQuery::TRANSACTION_LIMIT + 1; 15 if (count($transactions) == $too_many) { 16 if ($marker_type == 'olderandnewer') { 17 $last_transaction = end($transactions); 18 $first_transaction = reset($transactions); 19 unset($transactions[$last_transaction->getID()]); 20 unset($transactions[$first_transaction->getID()]); 21 $oldest_transaction_id = $last_transaction->getID(); 22 $newest_transaction_id = $first_transaction->getID(); 23 } else if ($marker_type == 'newer') { 24 $first_transaction = reset($transactions); 25 unset($transactions[$first_transaction->getID()]); 26 $newest_transaction_id = $first_transaction->getID(); 27 } else if ($marker_type == 'older') { 28 $last_transaction = end($transactions); 29 unset($transactions[$last_transaction->getID()]); 30 $oldest_transaction = end($transactions); 31 $oldest_transaction_id = $oldest_transaction->getID(); 32 } 33 // we need **at least** the newer marker in this mode even if 34 // we didn't get a full set of transactions 35 } else if ($marker_type == 'olderandnewer') { 36 $first_transaction = reset($transactions); 37 unset($transactions[$first_transaction->getID()]); 38 $newest_transaction_id = $first_transaction->getID(); 39 } 40 41 $transactions = array_reverse($transactions); 42 $handles = $conpherence->getHandles(); 43 $rendered_transactions = array(); 44 $engine = id(new PhabricatorMarkupEngine()) 45 ->setViewer($user) 46 ->setContextObject($conpherence); 47 foreach ($transactions as $key => $transaction) { 48 if ($transaction->shouldHide()) { 49 unset($transactions[$key]); 50 continue; 51 } 52 if ($transaction->getComment()) { 53 $engine->addObject( 54 $transaction->getComment(), 55 PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); 56 } 57 } 58 $engine->process(); 59 // we're going to insert a dummy date marker transaction for breaks 60 // between days. some setup required! 61 $previous_transaction = null; 62 $date_marker_transaction = id(new ConpherenceTransaction()) 63 ->setTransactionType( 64 ConpherenceThreadDateMarkerTransaction::TRANSACTIONTYPE) 65 ->makeEphemeral(); 66 $date_marker_transaction_view = id(new ConpherenceTransactionView()) 67 ->setViewer($user) 68 ->setConpherenceTransaction($date_marker_transaction) 69 ->setConpherenceThread($conpherence) 70 ->setHandles($handles) 71 ->setMarkupEngine($engine); 72 73 $transaction_view_template = id(new ConpherenceTransactionView()) 74 ->setViewer($user) 75 ->setConpherenceThread($conpherence) 76 ->setHandles($handles) 77 ->setMarkupEngine($engine); 78 79 foreach ($transactions as $transaction) { 80 $collapsed = false; 81 if ($previous_transaction) { 82 $previous_day = phabricator_format_local_time( 83 $previous_transaction->getDateCreated(), 84 $user, 85 'Ymd'); 86 $current_day = phabricator_format_local_time( 87 $transaction->getDateCreated(), 88 $user, 89 'Ymd'); 90 91 // See if same user / time 92 $previous_author = $previous_transaction->getAuthorPHID(); 93 $current_author = $transaction->getAuthorPHID(); 94 $previous_time = $previous_transaction->getDateCreated(); 95 $current_time = $transaction->getDateCreated(); 96 $previous_type = $previous_transaction->getTransactionType(); 97 $current_type = $transaction->getTransactionType(); 98 if (($previous_author == $current_author) && 99 ($previous_type == $current_type)) { 100 // Group messages within the last x seconds 101 if (($current_time - $previous_time) < 120) { 102 $collapsed = true; 103 } 104 } 105 106 // date marker transaction time! 107 if ($previous_day != $current_day) { 108 $date_marker_transaction->setDateCreated( 109 $transaction->getDateCreated()); 110 $date_marker_transaction->setID($previous_transaction->getID()); 111 $rendered_transactions[] = $date_marker_transaction_view->render(); 112 } 113 } 114 $transaction_view = id(clone $transaction_view_template) 115 ->setConpherenceTransaction($transaction); 116 if ($collapsed) { 117 $transaction_view->addClass('conpherence-transaction-collapsed'); 118 } 119 120 $rendered_transactions[] = $transaction_view->render(); 121 $previous_transaction = $transaction; 122 } 123 $latest_transaction_id = $transaction->getID(); 124 125 return array( 126 'transactions' => $rendered_transactions, 127 'latest_transaction' => $transaction, 128 'latest_transaction_id' => $latest_transaction_id, 129 'oldest_transaction_id' => $oldest_transaction_id, 130 'newest_transaction_id' => $newest_transaction_id, 131 ); 132 } 133 134 public static function renderMessagePaneContent( 135 array $transactions, 136 $oldest_transaction_id, 137 $newest_transaction_id) { 138 139 $oldscrollbutton = ''; 140 if ($oldest_transaction_id) { 141 $oldscrollbutton = javelin_tag( 142 'a', 143 array( 144 'href' => '#', 145 'mustcapture' => true, 146 'sigil' => 'show-older-messages', 147 'class' => 'conpherence-show-more-messages', 148 'meta' => array( 149 'oldest_transaction_id' => $oldest_transaction_id, 150 ), 151 ), 152 pht('Show Older Messages')); 153 $oldscrollbutton = javelin_tag( 154 'div', 155 array( 156 'sigil' => 'conpherence-transaction-view', 157 'meta' => array( 158 'id' => $oldest_transaction_id - 0.5, 159 ), 160 ), 161 $oldscrollbutton); 162 } 163 164 $newscrollbutton = ''; 165 if ($newest_transaction_id) { 166 $newscrollbutton = javelin_tag( 167 'a', 168 array( 169 'href' => '#', 170 'mustcapture' => true, 171 'sigil' => 'show-newer-messages', 172 'class' => 'conpherence-show-more-messages', 173 'meta' => array( 174 'newest_transaction_id' => $newest_transaction_id, 175 ), 176 ), 177 pht('Show Newer Messages')); 178 $newscrollbutton = javelin_tag( 179 'div', 180 array( 181 'sigil' => 'conpherence-transaction-view', 182 'meta' => array( 183 'id' => $newest_transaction_id + 0.5, 184 ), 185 ), 186 $newscrollbutton); 187 } 188 189 return hsprintf( 190 '%s%s%s', 191 $oldscrollbutton, 192 $transactions, 193 $newscrollbutton); 194 } 195 196}