3 final class ConpherenceTransactionRenderer
extends Phobject
{
5 public static function renderTransactions(
7 ConpherenceThread
$conpherence,
8 $marker_type = 'older') {
10 $transactions = $conpherence->getTransactions();
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();
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();
41 $transactions = array_reverse($transactions);
42 $handles = $conpherence->getHandles();
43 $rendered_transactions = array();
44 $engine = id(new PhabricatorMarkupEngine())
46 ->setContextObject($conpherence);
47 foreach ($transactions as $key => $transaction) {
48 if ($transaction->shouldHide()) {
49 unset($transactions[$key]);
52 if ($transaction->getComment()) {
54 $transaction->getComment(),
55 PhabricatorApplicationTransactionComment
::MARKUP_FIELD_COMMENT
);
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())
64 ConpherenceThreadDateMarkerTransaction
::TRANSACTIONTYPE
)
66 $date_marker_transaction_view = id(new ConpherenceTransactionView())
68 ->setConpherenceTransaction($date_marker_transaction)
69 ->setConpherenceThread($conpherence)
70 ->setHandles($handles)
71 ->setMarkupEngine($engine);
73 $transaction_view_template = id(new ConpherenceTransactionView())
75 ->setConpherenceThread($conpherence)
76 ->setHandles($handles)
77 ->setMarkupEngine($engine);
79 foreach ($transactions as $transaction) {
81 if ($previous_transaction) {
82 $previous_day = phabricator_format_local_time(
83 $previous_transaction->getDateCreated(),
86 $current_day = phabricator_format_local_time(
87 $transaction->getDateCreated(),
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) {
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();
114 $transaction_view = id(clone $transaction_view_template)
115 ->setConpherenceTransaction($transaction);
117 $transaction_view->addClass('conpherence-transaction-collapsed');
120 $rendered_transactions[] = $transaction_view->render();
121 $previous_transaction = $transaction;
123 $latest_transaction_id = $transaction->getID();
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,
134 public static function renderMessagePaneContent(
136 $oldest_transaction_id,
137 $newest_transaction_id) {
139 $oldscrollbutton = '';
140 if ($oldest_transaction_id) {
141 $oldscrollbutton = javelin_tag(
145 'mustcapture' => true,
146 'sigil' => 'show-older-messages',
147 'class' => 'conpherence-show-more-messages',
149 'oldest_transaction_id' => $oldest_transaction_id,
152 pht('Show Older Messages'));
153 $oldscrollbutton = javelin_tag(
156 'sigil' => 'conpherence-transaction-view',
158 'id' => $oldest_transaction_id - 0.5,
164 $newscrollbutton = '';
165 if ($newest_transaction_id) {
166 $newscrollbutton = javelin_tag(
170 'mustcapture' => true,
171 'sigil' => 'show-newer-messages',
172 'class' => 'conpherence-show-more-messages',
174 'newest_transaction_id' => $newest_transaction_id,
177 pht('Show Newer Messages'));
178 $newscrollbutton = javelin_tag(
181 'sigil' => 'conpherence-transaction-view',
183 'id' => $newest_transaction_id +
0.5,