@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
3/**
4 * @concrete-extensible
5 */
6class PhabricatorApplicationTransactionFeedStory
7 extends PhabricatorFeedStory {
8
9 private $primaryTransactionPHID;
10
11 public function getPrimaryObjectPHID() {
12 return $this->getValue('objectPHID');
13 }
14
15 public function getRequiredObjectPHIDs() {
16 return $this->getValue('transactionPHIDs');
17 }
18
19 public function getRequiredHandlePHIDs() {
20 $phids = array();
21 $phids[] = $this->getValue('objectPHID');
22 foreach ($this->getValue('transactionPHIDs') as $xaction_phid) {
23 $xaction = $this->getObject($xaction_phid);
24 foreach ($xaction->getRequiredHandlePHIDs() as $handle_phid) {
25 $phids[] = $handle_phid;
26 }
27 }
28 return $phids;
29 }
30
31 protected function getPrimaryTransactionPHID() {
32 if ($this->primaryTransactionPHID === null) {
33 // Transactions are filtered and sorted before they're stored, but the
34 // rendering logic can change between the time an edit occurs and when
35 // we actually render the story. Recalculate the filtering at display
36 // time because it's cheap and gets us better results when things change
37 // by letting the changes apply retroactively.
38
39 $xactions = $this->getTransactions();
40
41 foreach ($xactions as $key => $xaction) {
42 if ($xaction->shouldHideForFeed()) {
43 unset($xactions[$key]);
44 }
45 }
46
47 if ($xactions) {
48 $primary_phid = head($xactions)->getPHID();
49 } else {
50 $primary_phid = head($this->getValue('transactionPHIDs'));
51 }
52
53 $this->primaryTransactionPHID = $primary_phid;
54 }
55
56 return $this->primaryTransactionPHID;
57 }
58
59 public function isVisibleInNotifications() {
60 $xactions = $this->getTransactions();
61
62 foreach ($xactions as $key => $xaction) {
63 if (!$xaction->shouldHideForNotifications()) {
64 return true;
65 }
66 }
67
68 return false;
69 }
70
71 public function isVisibleInFeed() {
72 $xactions = $this->getTransactions();
73
74 foreach ($xactions as $key => $xaction) {
75 if (!$xaction->shouldHideForFeed()) {
76 return true;
77 }
78 }
79
80 return false;
81 }
82
83 private function getTransactions() {
84 $xaction_phids = $this->getValue('transactionPHIDs');
85
86 $xactions = array();
87 foreach ($xaction_phids as $xaction_phid) {
88 $xactions[] = $this->getObject($xaction_phid);
89 }
90
91 return $xactions;
92 }
93
94 public function getPrimaryTransaction() {
95 return $this->getObject($this->getPrimaryTransactionPHID());
96 }
97
98 public function getFieldStoryMarkupFields() {
99 $xaction_phids = $this->getValue('transactionPHIDs');
100
101 $fields = array();
102 foreach ($xaction_phids as $xaction_phid) {
103 $xaction = $this->getObject($xaction_phid);
104 foreach ($xaction->getMarkupFieldsForFeed($this) as $field) {
105 $fields[] = $field;
106 }
107 }
108
109 return $fields;
110 }
111
112 public function getMarkupText($field) {
113 $xaction_phids = $this->getValue('transactionPHIDs');
114
115 foreach ($xaction_phids as $xaction_phid) {
116 $xaction = $this->getObject($xaction_phid);
117 foreach ($xaction->getMarkupFieldsForFeed($this) as $xaction_field) {
118 if ($xaction_field == $field) {
119 return $xaction->getMarkupTextForFeed($this, $field);
120 }
121 }
122 }
123
124 return '';
125 }
126
127 public function renderView() {
128 $view = $this->newStoryView();
129
130 $handle = $this->getHandle($this->getPrimaryObjectPHID());
131 $view->setHref($handle->getURI());
132
133 $type = phid_get_type($handle->getPHID());
134 $phid_types = PhabricatorPHIDType::getAllTypes();
135 $icon = null;
136 if (!empty($phid_types[$type])) {
137 $phid_type = $phid_types[$type];
138 $class = $phid_type->getPHIDTypeApplicationClass();
139 if ($class) {
140 $application = PhabricatorApplication::getByClass($class);
141 $icon = $application->getIcon();
142 }
143 }
144
145 $view->setAppIcon($icon);
146
147 $xaction_phids = $this->getValue('transactionPHIDs');
148 $xaction = $this->getPrimaryTransaction();
149
150 $xaction->setHandles($this->getHandles());
151 $view->setTitle($xaction->getTitleForFeed());
152
153 foreach ($xaction_phids as $xaction_phid) {
154 $secondary_xaction = $this->getObject($xaction_phid);
155 $secondary_xaction->setHandles($this->getHandles());
156
157 $body = $secondary_xaction->getBodyForFeed($this);
158 if (nonempty($body)) {
159 $view->appendChild($body);
160 }
161 }
162
163 $author_phid = $xaction->getAuthorPHID();
164 $author_handle = $this->getHandle($author_phid);
165 $author_image = $author_handle->getImageURI();
166
167 if ($author_image) {
168 $view->setImage($author_image);
169 $view->setImageHref($author_handle->getURI());
170 } else {
171 $view->setAuthorIcon($author_handle->getIcon());
172 }
173
174 return $view;
175 }
176
177 public function renderText() {
178 $xaction = $this->getPrimaryTransaction();
179 $old_target = $xaction->getRenderingTarget();
180 $new_target = PhabricatorApplicationTransaction::TARGET_TEXT;
181 $xaction->setRenderingTarget($new_target);
182 $xaction->setHandles($this->getHandles());
183 $text = $xaction->getTitleForFeed();
184 $xaction->setRenderingTarget($old_target);
185 return $text;
186 }
187
188 public function renderTextBody() {
189 $all_bodies = '';
190 $new_target = PhabricatorApplicationTransaction::TARGET_TEXT;
191 $xaction_phids = $this->getValue('transactionPHIDs');
192 foreach ($xaction_phids as $xaction_phid) {
193 $secondary_xaction = $this->getObject($xaction_phid);
194 $old_target = $secondary_xaction->getRenderingTarget();
195 $secondary_xaction->setRenderingTarget($new_target);
196 $secondary_xaction->setHandles($this->getHandles());
197
198 $body = $secondary_xaction->getBodyForMail();
199 if (nonempty($body)) {
200 $all_bodies .= $body."\n";
201 }
202 $secondary_xaction->setRenderingTarget($old_target);
203 }
204 return trim($all_bodies);
205 }
206
207 public function getImageURI() {
208 $author_phid = $this->getPrimaryTransaction()->getAuthorPHID();
209 return $this->getHandle($author_phid)->getImageURI();
210 }
211
212 public function getURI() {
213 $handle = $this->getHandle($this->getPrimaryObjectPHID());
214 return PhabricatorEnv::getProductionURI($handle->getURI());
215 }
216
217 public function renderAsTextForDoorkeeper(
218 DoorkeeperFeedStoryPublisher $publisher) {
219
220 $xactions = array();
221 $xaction_phids = $this->getValue('transactionPHIDs');
222 foreach ($xaction_phids as $xaction_phid) {
223 $xaction = $this->getObject($xaction_phid);
224 $xaction->setHandles($this->getHandles());
225 $xactions[] = $xaction;
226 }
227
228 $primary = $this->getPrimaryTransaction();
229 return $primary->renderAsTextForDoorkeeper($publisher, $this, $xactions);
230 }
231
232}