@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorApplicationTransactionResponse
4 extends AphrontProxyResponse {
5
6 private $viewer;
7 private $transactions;
8 private $isPreview;
9 private $previewContent;
10 private $object;
11 private $viewData = array();
12
13 protected function buildProxy() {
14 return new AphrontAjaxResponse();
15 }
16
17 /**
18 * @param array<PhabricatorApplicationTransaction> $transactions
19 */
20 public function setTransactions($transactions) {
21 assert_instances_of(
22 $transactions,
23 PhabricatorApplicationTransaction::class);
24
25 $this->transactions = $transactions;
26 return $this;
27 }
28
29 public function getTransactions() {
30 return $this->transactions;
31 }
32
33 public function setObject($object) {
34 $this->object = $object;
35 return $this;
36 }
37
38 public function getObject() {
39 return $this->object;
40 }
41
42 public function setViewer(PhabricatorUser $viewer) {
43 $this->viewer = $viewer;
44 return $this;
45 }
46
47 public function getViewer() {
48 return $this->viewer;
49 }
50
51 public function setIsPreview($is_preview) {
52 $this->isPreview = $is_preview;
53 return $this;
54 }
55
56 public function setPreviewContent($preview_content) {
57 $this->previewContent = $preview_content;
58 return $this;
59 }
60
61 public function getPreviewContent() {
62 return $this->previewContent;
63 }
64
65 public function setViewData(array $view_data) {
66 $this->viewData = $view_data;
67 return $this;
68 }
69
70 public function getViewData() {
71 return $this->viewData;
72 }
73
74 public function reduceProxyResponse() {
75 $object = $this->getObject();
76 $viewer = $this->getViewer();
77 $xactions = $this->getTransactions();
78
79 $timeline_engine = PhabricatorTimelineEngine::newForObject($object)
80 ->setViewer($viewer)
81 ->setTransactions($xactions)
82 ->setViewData($this->viewData);
83
84 $view = $timeline_engine->buildTimelineView();
85
86 $view->setIsPreview($this->isPreview);
87
88 if ($this->isPreview) {
89 $xactions = mpull($view->buildEvents(), 'render');
90 } else {
91 $xactions = mpull($view->buildEvents(), 'render', 'getTransactionPHID');
92 }
93
94 // Force whatever the underlying views built to render into HTML for
95 // the Javascript.
96 foreach ($xactions as $key => $xaction) {
97 $xactions[$key] = hsprintf('%s', $xaction);
98 }
99
100 $aural = phutil_tag(
101 'h2',
102 array(
103 'class' => 'aural-only',
104 ),
105 pht('Comment Preview'));
106
107 $content = array(
108 'header' => hsprintf('%s', $aural),
109 'xactions' => $xactions,
110 'spacer' => PHUITimelineView::renderSpacer(),
111 'previewContent' => hsprintf('%s', $this->getPreviewContent()),
112 );
113
114 return $this->getProxy()->setContent($content);
115 }
116
117
118}