|
| 1 | +<?php |
| 2 | + |
| 3 | +final class ConpherenceTransactionRenderer { |
| 4 | + |
| 5 | + public static function renderTransactions( |
| 6 | + PhabricatorUser $user, |
| 7 | + ConpherenceThread $conpherence, |
| 8 | + $full_display = true) { |
| 9 | + |
| 10 | + $transactions = $conpherence->getTransactions(); |
| 11 | + $oldest_transaction_id = 0; |
| 12 | + $too_many = ConpherenceThreadQuery::TRANSACTION_LIMIT + 1; |
| 13 | + if (count($transactions) == $too_many) { |
| 14 | + $last_transaction = end($transactions); |
| 15 | + unset($transactions[$last_transaction->getID()]); |
| 16 | + $oldest_transaction = end($transactions); |
| 17 | + $oldest_transaction_id = $oldest_transaction->getID(); |
| 18 | + } |
| 19 | + $transactions = array_reverse($transactions); |
| 20 | + $handles = $conpherence->getHandles(); |
| 21 | + $rendered_transactions = array(); |
| 22 | + $engine = id(new PhabricatorMarkupEngine()) |
| 23 | + ->setViewer($user) |
| 24 | + ->setContextObject($conpherence); |
| 25 | + foreach ($transactions as $key => $transaction) { |
| 26 | + if ($transaction->shouldHide()) { |
| 27 | + unset($transactions[$key]); |
| 28 | + continue; |
| 29 | + } |
| 30 | + if ($transaction->getComment()) { |
| 31 | + $engine->addObject( |
| 32 | + $transaction->getComment(), |
| 33 | + PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); |
| 34 | + } |
| 35 | + } |
| 36 | + $engine->process(); |
| 37 | + // we're going to insert a dummy date marker transaction for breaks |
| 38 | + // between days. some setup required! |
| 39 | + $previous_transaction = null; |
| 40 | + $date_marker_transaction = id(new ConpherenceTransaction()) |
| 41 | + ->setTransactionType(ConpherenceTransactionType::TYPE_DATE_MARKER) |
| 42 | + ->makeEphemeral(); |
| 43 | + $date_marker_transaction_view = id(new ConpherenceTransactionView()) |
| 44 | + ->setUser($user) |
| 45 | + ->setConpherenceTransaction($date_marker_transaction) |
| 46 | + ->setConpherenceThread($conpherence) |
| 47 | + ->setHandles($handles) |
| 48 | + ->setMarkupEngine($engine); |
| 49 | + |
| 50 | + $transaction_view_template = id(new ConpherenceTransactionView()) |
| 51 | + ->setUser($user) |
| 52 | + ->setConpherenceThread($conpherence) |
| 53 | + ->setHandles($handles) |
| 54 | + ->setMarkupEngine($engine); |
| 55 | + |
| 56 | + foreach ($transactions as $transaction) { |
| 57 | + if ($previous_transaction) { |
| 58 | + $previous_day = phabricator_format_local_time( |
| 59 | + $previous_transaction->getDateCreated(), |
| 60 | + $user, |
| 61 | + 'Ymd'); |
| 62 | + $current_day = phabricator_format_local_time( |
| 63 | + $transaction->getDateCreated(), |
| 64 | + $user, |
| 65 | + 'Ymd'); |
| 66 | + // date marker transaction time! |
| 67 | + if ($previous_day != $current_day) { |
| 68 | + $date_marker_transaction->setDateCreated( |
| 69 | + $transaction->getDateCreated()); |
| 70 | + $rendered_transactions[] = $date_marker_transaction_view->render(); |
| 71 | + } |
| 72 | + } |
| 73 | + $transaction_view = id(clone $transaction_view_template) |
| 74 | + ->setConpherenceTransaction($transaction); |
| 75 | + if ($full_display) { |
| 76 | + $transaction_view |
| 77 | + ->setAnchor( |
| 78 | + $transaction->getID(), |
| 79 | + phabricator_time($transaction->getDateCreated(), $user)); |
| 80 | + $transaction_view->setContentSource($transaction->getContentSource()); |
| 81 | + $transaction_view->setShowImages(true); |
| 82 | + } else { |
| 83 | + $transaction_view |
| 84 | + ->setEpoch( |
| 85 | + $transaction->getDateCreated(), |
| 86 | + '/'.$conpherence->getMonogram().'#'.$transaction->getID()) |
| 87 | + ->setTimeOnly(true); |
| 88 | + $transaction_view->setShowImages(false); |
| 89 | + } |
| 90 | + |
| 91 | + $rendered_transactions[] = $transaction_view->render(); |
| 92 | + $previous_transaction = $transaction; |
| 93 | + } |
| 94 | + $latest_transaction_id = $transaction->getID(); |
| 95 | + |
| 96 | + return array( |
| 97 | + 'transactions' => $rendered_transactions, |
| 98 | + 'latest_transaction' => $transaction, |
| 99 | + 'latest_transaction_id' => $latest_transaction_id, |
| 100 | + 'oldest_transaction_id' => $oldest_transaction_id, |
| 101 | + ); |
| 102 | + } |
| 103 | + |
| 104 | + public static function renderMessagePaneContent( |
| 105 | + array $transactions, |
| 106 | + $oldest_transaction_id) { |
| 107 | + |
| 108 | + $scrollbutton = ''; |
| 109 | + if ($oldest_transaction_id) { |
| 110 | + $scrollbutton = javelin_tag( |
| 111 | + 'a', |
| 112 | + array( |
| 113 | + 'href' => '#', |
| 114 | + 'mustcapture' => true, |
| 115 | + 'sigil' => 'show-older-messages', |
| 116 | + 'class' => 'conpherence-show-older-messages', |
| 117 | + 'meta' => array( |
| 118 | + 'oldest_transaction_id' => $oldest_transaction_id, |
| 119 | + ), |
| 120 | + ), |
| 121 | + pht('Show Older Messages')); |
| 122 | + } |
| 123 | + |
| 124 | + return hsprintf('%s%s', $scrollbutton, $transactions); |
| 125 | + } |
| 126 | + |
| 127 | +} |
0 commit comments