2015-04-14 21:25:35 +02:00
|
|
|
<?php
|
|
|
|
|
2015-06-15 10:02:26 +02:00
|
|
|
final class ConpherenceTransactionRenderer extends Phobject {
|
2015-04-14 21:25:35 +02:00
|
|
|
|
|
|
|
public static function renderTransactions(
|
|
|
|
PhabricatorUser $user,
|
|
|
|
ConpherenceThread $conpherence,
|
2015-05-01 01:54:57 +02:00
|
|
|
$full_display = true,
|
|
|
|
$marker_type = 'older') {
|
2015-04-14 21:25:35 +02:00
|
|
|
|
|
|
|
$transactions = $conpherence->getTransactions();
|
2015-05-01 01:54:57 +02:00
|
|
|
|
2015-04-14 21:25:35 +02:00
|
|
|
$oldest_transaction_id = 0;
|
2015-05-01 01:54:57 +02:00
|
|
|
$newest_transaction_id = 0;
|
2015-04-14 21:25:35 +02:00
|
|
|
$too_many = ConpherenceThreadQuery::TRANSACTION_LIMIT + 1;
|
|
|
|
if (count($transactions) == $too_many) {
|
2015-05-01 01:54:57 +02:00
|
|
|
if ($marker_type == 'olderandnewer') {
|
|
|
|
$last_transaction = end($transactions);
|
|
|
|
$first_transaction = reset($transactions);
|
|
|
|
unset($transactions[$last_transaction->getID()]);
|
|
|
|
unset($transactions[$first_transaction->getID()]);
|
|
|
|
$oldest_transaction_id = $last_transaction->getID();
|
|
|
|
$newest_transaction_id = $first_transaction->getID();
|
|
|
|
} else if ($marker_type == 'newer') {
|
|
|
|
$first_transaction = reset($transactions);
|
|
|
|
unset($transactions[$first_transaction->getID()]);
|
|
|
|
$newest_transaction_id = $first_transaction->getID();
|
|
|
|
} else if ($marker_type == 'older') {
|
|
|
|
$last_transaction = end($transactions);
|
|
|
|
unset($transactions[$last_transaction->getID()]);
|
|
|
|
$oldest_transaction = end($transactions);
|
|
|
|
$oldest_transaction_id = $oldest_transaction->getID();
|
|
|
|
}
|
|
|
|
// we need **at least** the newer marker in this mode even if
|
|
|
|
// we didn't get a full set of transactions
|
|
|
|
} else if ($marker_type == 'olderandnewer') {
|
|
|
|
$first_transaction = reset($transactions);
|
|
|
|
unset($transactions[$first_transaction->getID()]);
|
|
|
|
$newest_transaction_id = $first_transaction->getID();
|
2015-04-14 21:25:35 +02:00
|
|
|
}
|
2015-05-01 01:54:57 +02:00
|
|
|
|
2015-04-14 21:25:35 +02:00
|
|
|
$transactions = array_reverse($transactions);
|
|
|
|
$handles = $conpherence->getHandles();
|
|
|
|
$rendered_transactions = array();
|
|
|
|
$engine = id(new PhabricatorMarkupEngine())
|
|
|
|
->setViewer($user)
|
|
|
|
->setContextObject($conpherence);
|
|
|
|
foreach ($transactions as $key => $transaction) {
|
|
|
|
if ($transaction->shouldHide()) {
|
|
|
|
unset($transactions[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($transaction->getComment()) {
|
|
|
|
$engine->addObject(
|
|
|
|
$transaction->getComment(),
|
|
|
|
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$engine->process();
|
|
|
|
// we're going to insert a dummy date marker transaction for breaks
|
|
|
|
// between days. some setup required!
|
|
|
|
$previous_transaction = null;
|
|
|
|
$date_marker_transaction = id(new ConpherenceTransaction())
|
2015-06-08 01:54:53 +02:00
|
|
|
->setTransactionType(ConpherenceTransaction::TYPE_DATE_MARKER)
|
2015-04-14 21:25:35 +02:00
|
|
|
->makeEphemeral();
|
|
|
|
$date_marker_transaction_view = id(new ConpherenceTransactionView())
|
|
|
|
->setUser($user)
|
|
|
|
->setConpherenceTransaction($date_marker_transaction)
|
|
|
|
->setConpherenceThread($conpherence)
|
|
|
|
->setHandles($handles)
|
|
|
|
->setMarkupEngine($engine);
|
|
|
|
|
|
|
|
$transaction_view_template = id(new ConpherenceTransactionView())
|
|
|
|
->setUser($user)
|
|
|
|
->setConpherenceThread($conpherence)
|
|
|
|
->setHandles($handles)
|
2015-05-29 00:27:08 +02:00
|
|
|
->setMarkupEngine($engine)
|
|
|
|
->setFullDisplay($full_display);
|
2015-04-14 21:25:35 +02:00
|
|
|
|
|
|
|
foreach ($transactions as $transaction) {
|
2016-09-29 21:19:45 +02:00
|
|
|
$collapsed = false;
|
2015-04-14 21:25:35 +02:00
|
|
|
if ($previous_transaction) {
|
|
|
|
$previous_day = phabricator_format_local_time(
|
|
|
|
$previous_transaction->getDateCreated(),
|
|
|
|
$user,
|
|
|
|
'Ymd');
|
|
|
|
$current_day = phabricator_format_local_time(
|
|
|
|
$transaction->getDateCreated(),
|
|
|
|
$user,
|
|
|
|
'Ymd');
|
2016-09-29 21:19:45 +02:00
|
|
|
|
|
|
|
// See if same user / time
|
|
|
|
$previous_author = $previous_transaction->getAuthorPHID();
|
|
|
|
$current_author = $transaction->getAuthorPHID();
|
|
|
|
$previous_time = $previous_transaction->getDateCreated();
|
|
|
|
$current_time = $transaction->getDateCreated();
|
|
|
|
$previous_type = $previous_transaction->getTransactionType();
|
|
|
|
$current_type = $transaction->getTransactionType();
|
|
|
|
if (($previous_author == $current_author) &&
|
|
|
|
($previous_type == $current_type)) {
|
|
|
|
// Group messages within the last x seconds
|
|
|
|
if (($current_time - $previous_time) < 120) {
|
|
|
|
$collapsed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 21:25:35 +02:00
|
|
|
// date marker transaction time!
|
|
|
|
if ($previous_day != $current_day) {
|
|
|
|
$date_marker_transaction->setDateCreated(
|
|
|
|
$transaction->getDateCreated());
|
2015-05-13 20:06:54 +02:00
|
|
|
$date_marker_transaction->setID($previous_transaction->getID());
|
2015-04-14 21:25:35 +02:00
|
|
|
$rendered_transactions[] = $date_marker_transaction_view->render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$transaction_view = id(clone $transaction_view_template)
|
|
|
|
->setConpherenceTransaction($transaction);
|
2016-09-29 21:19:45 +02:00
|
|
|
if ($collapsed) {
|
|
|
|
$transaction_view->addClass('conpherence-transaction-collapsed');
|
|
|
|
}
|
2015-04-14 21:25:35 +02:00
|
|
|
|
|
|
|
$rendered_transactions[] = $transaction_view->render();
|
|
|
|
$previous_transaction = $transaction;
|
|
|
|
}
|
|
|
|
$latest_transaction_id = $transaction->getID();
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'transactions' => $rendered_transactions,
|
|
|
|
'latest_transaction' => $transaction,
|
|
|
|
'latest_transaction_id' => $latest_transaction_id,
|
|
|
|
'oldest_transaction_id' => $oldest_transaction_id,
|
2015-05-01 01:54:57 +02:00
|
|
|
'newest_transaction_id' => $newest_transaction_id,
|
2015-04-14 21:25:35 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function renderMessagePaneContent(
|
|
|
|
array $transactions,
|
2015-05-01 01:54:57 +02:00
|
|
|
$oldest_transaction_id,
|
|
|
|
$newest_transaction_id) {
|
2015-04-14 21:25:35 +02:00
|
|
|
|
2015-05-01 01:54:57 +02:00
|
|
|
$oldscrollbutton = '';
|
2015-04-14 21:25:35 +02:00
|
|
|
if ($oldest_transaction_id) {
|
2015-05-01 01:54:57 +02:00
|
|
|
$oldscrollbutton = javelin_tag(
|
2015-04-14 21:25:35 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'show-older-messages',
|
2015-05-01 01:54:57 +02:00
|
|
|
'class' => 'conpherence-show-more-messages',
|
2015-04-14 21:25:35 +02:00
|
|
|
'meta' => array(
|
|
|
|
'oldest_transaction_id' => $oldest_transaction_id,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
pht('Show Older Messages'));
|
2015-05-13 20:06:54 +02:00
|
|
|
$oldscrollbutton = javelin_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'sigil' => 'conpherence-transaction-view',
|
|
|
|
'meta' => array(
|
|
|
|
'id' => $oldest_transaction_id - 0.5,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
$oldscrollbutton);
|
2015-04-14 21:25:35 +02:00
|
|
|
}
|
|
|
|
|
2015-05-01 01:54:57 +02:00
|
|
|
$newscrollbutton = '';
|
|
|
|
if ($newest_transaction_id) {
|
|
|
|
$newscrollbutton = javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'show-newer-messages',
|
|
|
|
'class' => 'conpherence-show-more-messages',
|
|
|
|
'meta' => array(
|
|
|
|
'newest_transaction_id' => $newest_transaction_id,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
pht('Show Newer Messages'));
|
2015-05-13 20:06:54 +02:00
|
|
|
$newscrollbutton = javelin_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'sigil' => 'conpherence-transaction-view',
|
|
|
|
'meta' => array(
|
|
|
|
'id' => $newest_transaction_id + 0.5,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
$newscrollbutton);
|
2015-05-01 01:54:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hsprintf(
|
|
|
|
'%s%s%s',
|
|
|
|
$oldscrollbutton,
|
|
|
|
$transactions,
|
|
|
|
$newscrollbutton);
|
2015-04-14 21:25:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|