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