@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 244 lines 6.1 kB view raw
1<?php 2 3final class PholioMockEditor extends PhabricatorApplicationTransactionEditor { 4 5 private $images = array(); 6 7 public function getEditorApplicationClass() { 8 return PhabricatorPholioApplication::class; 9 } 10 11 public function getEditorObjectsDescription() { 12 return pht('Pholio Mocks'); 13 } 14 15 public function getCreateObjectTitle($author, $object) { 16 return pht('%s created this mock.', $author); 17 } 18 19 public function getCreateObjectTitleForFeed($author, $object) { 20 return pht('%s created %s.', $author, $object); 21 } 22 23 public function getTransactionTypes() { 24 $types = parent::getTransactionTypes(); 25 26 $types[] = PhabricatorTransactions::TYPE_EDGE; 27 $types[] = PhabricatorTransactions::TYPE_COMMENT; 28 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 29 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 30 31 return $types; 32 } 33 34 protected function shouldSendMail( 35 PhabricatorLiskDAO $object, 36 array $xactions) { 37 return true; 38 } 39 40 protected function buildReplyHandler(PhabricatorLiskDAO $object) { 41 return id(new PholioReplyHandler()) 42 ->setMailReceiver($object); 43 } 44 45 protected function buildMailTemplate(PhabricatorLiskDAO $object) { 46 $monogram = $object->getMonogram(); 47 $name = $object->getName(); 48 49 return id(new PhabricatorMetaMTAMail()) 50 ->setSubject("{$monogram}: {$name}"); 51 } 52 53 protected function getMailTo(PhabricatorLiskDAO $object) { 54 return array( 55 $object->getAuthorPHID(), 56 $this->requireActor()->getPHID(), 57 ); 58 } 59 60 protected function buildMailBody( 61 PhabricatorLiskDAO $object, 62 array $xactions) { 63 64 $viewer = $this->requireActor(); 65 66 $body = id(new PhabricatorMetaMTAMailBody()) 67 ->setViewer($viewer); 68 69 $mock_uri = $object->getURI(); 70 $mock_uri = PhabricatorEnv::getProductionURI($mock_uri); 71 72 $this->addHeadersAndCommentsToMailBody( 73 $body, 74 $xactions, 75 pht('View Mock'), 76 $mock_uri); 77 78 $type_inline = PholioMockInlineTransaction::TRANSACTIONTYPE; 79 80 $inlines = array(); 81 foreach ($xactions as $xaction) { 82 if ($xaction->getTransactionType() == $type_inline) { 83 $inlines[] = $xaction; 84 } 85 } 86 87 $this->appendInlineCommentsForMail($object, $inlines, $body); 88 89 $body->addLinkSection( 90 pht('MOCK DETAIL'), 91 PhabricatorEnv::getProductionURI($object->getURI())); 92 93 return $body; 94 } 95 96 private function appendInlineCommentsForMail( 97 $object, 98 array $inlines, 99 PhabricatorMetaMTAMailBody $body) { 100 101 if (!$inlines) { 102 return; 103 } 104 105 $viewer = $this->requireActor(); 106 107 $header = pht('INLINE COMMENTS'); 108 $body->addRawPlaintextSection($header); 109 $body->addRawHTMLSection(phutil_tag('strong', array(), $header)); 110 111 $image_ids = array(); 112 foreach ($inlines as $inline) { 113 $comment = $inline->getComment(); 114 $image_id = $comment->getImageID(); 115 $image_ids[$image_id] = $image_id; 116 } 117 118 $images = id(new PholioImageQuery()) 119 ->setViewer($viewer) 120 ->withIDs($image_ids) 121 ->execute(); 122 $images = mpull($images, null, 'getID'); 123 124 foreach ($inlines as $inline) { 125 $comment = $inline->getComment(); 126 $content = $comment->getContent(); 127 $image_id = $comment->getImageID(); 128 $image = idx($images, $image_id); 129 if ($image) { 130 $image_name = $image->getName(); 131 } else { 132 $image_name = pht('Unknown (ID %d)', $image_id); 133 } 134 135 $body->addRemarkupSection( 136 pht('Image "%s":', $image_name), 137 $content); 138 } 139 } 140 141 protected function getMailSubjectPrefix() { 142 return pht('[Pholio]'); 143 } 144 145 public function getMailTagsMap() { 146 return array( 147 PholioTransaction::MAILTAG_STATUS => 148 pht("A mock's status changes."), 149 PholioTransaction::MAILTAG_COMMENT => 150 pht('Someone comments on a mock.'), 151 PholioTransaction::MAILTAG_UPDATED => 152 pht('Mock images or descriptions change.'), 153 PholioTransaction::MAILTAG_OTHER => 154 pht('Other mock activity not listed above occurs.'), 155 ); 156 } 157 158 protected function shouldPublishFeedStory( 159 PhabricatorLiskDAO $object, 160 array $xactions) { 161 return true; 162 } 163 164 protected function supportsSearch() { 165 return true; 166 } 167 168 protected function shouldApplyHeraldRules( 169 PhabricatorLiskDAO $object, 170 array $xactions) { 171 return true; 172 } 173 174 protected function buildHeraldAdapter( 175 PhabricatorLiskDAO $object, 176 array $xactions) { 177 178 return id(new HeraldPholioMockAdapter()) 179 ->setMock($object); 180 } 181 182 protected function sortTransactions(array $xactions) { 183 $head = array(); 184 $tail = array(); 185 186 // Move inline comments to the end, so the comments precede them. 187 foreach ($xactions as $xaction) { 188 $type = $xaction->getTransactionType(); 189 if ($type == PholioMockInlineTransaction::TRANSACTIONTYPE) { 190 $tail[] = $xaction; 191 } else { 192 $head[] = $xaction; 193 } 194 } 195 196 return array_values(array_merge($head, $tail)); 197 } 198 199 protected function shouldImplyCC( 200 PhabricatorLiskDAO $object, 201 PhabricatorApplicationTransaction $xaction) { 202 203 switch ($xaction->getTransactionType()) { 204 case PholioMockInlineTransaction::TRANSACTIONTYPE: 205 return true; 206 } 207 208 return parent::shouldImplyCC($object, $xaction); 209 } 210 211 public function loadPholioImage($object, $phid) { 212 if (!isset($this->images[$phid])) { 213 214 $image = id(new PholioImageQuery()) 215 ->setViewer($this->getActor()) 216 ->withPHIDs(array($phid)) 217 ->executeOne(); 218 219 if (!$image) { 220 throw new Exception( 221 pht( 222 'No image exists with PHID "%s".', 223 $phid)); 224 } 225 226 $mock_phid = $image->getMockPHID(); 227 if ($mock_phid) { 228 if ($mock_phid !== $object->getPHID()) { 229 throw new Exception( 230 pht( 231 'Image ("%s") belongs to the wrong object ("%s", expected "%s").', 232 $phid, 233 $mock_phid, 234 $object->getPHID())); 235 } 236 } 237 238 $this->images[$phid] = $image; 239 } 240 241 return $this->images[$phid]; 242 } 243 244}