Skip to content

Commit 87d360b

Browse files
committed
Conpherence - refactor display classes a bit
Summary: D12409 made me realize this was a bit janky. `PhabricatorTransactionView` was only being used by Conpherence, so move and rename that class to `ConpherenceTransactionView`. Also, rename the existing `ConpherenceTransactionView` to `ConpherenceTransactionRenderer`, moving the actual view bits into the new `ConpherenceTransactionView`. Resulting code is a bit cleaner IMO. Diff 1 of 2 (second diff has to be written. =D). Diff 2 will take care of the CSS and possibly clean things up further. Test Plan: played around in conpherence full and conpherence column and things looked nice Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D12410
1 parent d90496a commit 87d360b

File tree

7 files changed

+319
-349
lines changed

7 files changed

+319
-349
lines changed

src/__phutil_library_map__.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
'ConpherenceTransaction' => 'applications/conpherence/storage/ConpherenceTransaction.php',
265265
'ConpherenceTransactionComment' => 'applications/conpherence/storage/ConpherenceTransactionComment.php',
266266
'ConpherenceTransactionQuery' => 'applications/conpherence/query/ConpherenceTransactionQuery.php',
267+
'ConpherenceTransactionRenderer' => 'applications/conpherence/ConpherenceTransactionRenderer.php',
267268
'ConpherenceTransactionType' => 'applications/conpherence/constants/ConpherenceTransactionType.php',
268269
'ConpherenceTransactionView' => 'applications/conpherence/view/ConpherenceTransactionView.php',
269270
'ConpherenceUpdateActions' => 'applications/conpherence/constants/ConpherenceUpdateActions.php',
@@ -2610,7 +2611,6 @@
26102611
'PhabricatorTokensApplication' => 'applications/tokens/application/PhabricatorTokensApplication.php',
26112612
'PhabricatorTokensSettingsPanel' => 'applications/settings/panel/PhabricatorTokensSettingsPanel.php',
26122613
'PhabricatorTooltipUIExample' => 'applications/uiexample/examples/PhabricatorTooltipUIExample.php',
2613-
'PhabricatorTransactionView' => 'view/layout/PhabricatorTransactionView.php',
26142614
'PhabricatorTransactions' => 'applications/transactions/constants/PhabricatorTransactions.php',
26152615
'PhabricatorTransactionsApplication' => 'applications/transactions/application/PhabricatorTransactionsApplication.php',
26162616
'PhabricatorTransformedFile' => 'applications/files/storage/PhabricatorTransformedFile.php',
@@ -3446,6 +3446,7 @@
34463446
'ConpherenceDAO',
34473447
'PhabricatorPolicyInterface',
34483448
'PhabricatorApplicationTransactionInterface',
3449+
'PhabricatorMentionableInterface',
34493450
'PhabricatorDestructibleInterface',
34503451
),
34513452
'ConpherenceThreadIndexer' => 'PhabricatorSearchDocumentIndexer',
@@ -6009,7 +6010,6 @@
60096010
'PhabricatorTokensApplication' => 'PhabricatorApplication',
60106011
'PhabricatorTokensSettingsPanel' => 'PhabricatorSettingsPanel',
60116012
'PhabricatorTooltipUIExample' => 'PhabricatorUIExample',
6012-
'PhabricatorTransactionView' => 'AphrontView',
60136013
'PhabricatorTransactionsApplication' => 'PhabricatorApplication',
60146014
'PhabricatorTransformedFile' => 'PhabricatorFileDAO',
60156015
'PhabricatorTranslationsConfigOptions' => 'PhabricatorApplicationConfigOptions',
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
}

src/applications/conpherence/controller/ConpherenceUpdateController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private function loadAndRenderUpdates(
408408

409409
$non_update = false;
410410
if ($need_transactions && $conpherence->getTransactions()) {
411-
$data = ConpherenceTransactionView::renderTransactions(
411+
$data = ConpherenceTransactionRenderer::renderTransactions(
412412
$user,
413413
$conpherence,
414414
!$this->getRequest()->getExists('minimal_display'));

src/applications/conpherence/controller/ConpherenceViewController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public function handleRequest(AphrontRequest $request) {
3636
unset($write_guard);
3737
}
3838

39-
$data = ConpherenceTransactionView::renderTransactions(
39+
$data = ConpherenceTransactionRenderer::renderTransactions(
4040
$user,
4141
$conpherence);
42-
$messages = ConpherenceTransactionView::renderMessagePaneContent(
42+
$messages = ConpherenceTransactionRenderer::renderMessagePaneContent(
4343
$data['transactions'],
4444
$data['oldest_transaction_id']);
4545
if ($before_transaction_id) {

src/applications/conpherence/view/ConpherenceDurableColumnView.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,11 @@ private function buildTransactions() {
446446
);
447447
}
448448

449-
$data = ConpherenceTransactionView::renderTransactions(
449+
$data = ConpherenceTransactionRenderer::renderTransactions(
450450
$this->getUser(),
451451
$conpherence,
452452
$full_display = false);
453-
$messages = ConpherenceTransactionView::renderMessagePaneContent(
453+
$messages = ConpherenceTransactionRenderer::renderMessagePaneContent(
454454
$data['transactions'],
455455
$data['oldest_transaction_id']);
456456

0 commit comments

Comments
 (0)