Changeset View
Standalone View
src/applications/pholio/editor/PholioMockEditor.php
Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | return array( | ||||
$this->requireActor()->getPHID(), | $this->requireActor()->getPHID(), | ||||
); | ); | ||||
} | } | ||||
protected function buildMailBody( | protected function buildMailBody( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
$body = new PhabricatorMetaMTAMailBody(); | $viewer = $this->requireActor(); | ||||
$headers = array(); | |||||
$comments = array(); | |||||
$inline_comments = array(); | |||||
foreach ($xactions as $xaction) { | $body = id(new PhabricatorMetaMTAMailBody()) | ||||
if ($xaction->shouldHide()) { | ->setViewer($viewer); | ||||
continue; | |||||
} | |||||
$comment = $xaction->getComment(); | |||||
switch ($xaction->getTransactionType()) { | |||||
case PholioMockInlineTransaction::TRANSACTIONTYPE: | |||||
if ($comment && strlen($comment->getContent())) { | |||||
$inline_comments[] = $comment; | |||||
} | |||||
break; | |||||
case PhabricatorTransactions::TYPE_COMMENT: | |||||
if ($comment && strlen($comment->getContent())) { | |||||
$comments[] = $comment->getContent(); | |||||
} | |||||
// fallthrough | |||||
default: | |||||
$headers[] = id(clone $xaction) | |||||
->setRenderingTarget('text') | |||||
->getTitle(); | |||||
break; | |||||
} | |||||
} | |||||
$body->addRawSection(implode("\n", $headers)); | $mock_uri = $object->getURI(); | ||||
$mock_uri = PhabricatorEnv::getProductionURI($mock_uri); | |||||
foreach ($comments as $comment) { | $this->addHeadersAndCommentsToMailBody( | ||||
$body->addRawSection($comment); | $body, | ||||
} | $xactions, | ||||
pht('View Mock'), | |||||
$mock_uri); | |||||
$type_inline = PholioMockInlineTransaction::TRANSACTIONTYPE; | |||||
if ($inline_comments) { | $inlines = array(); | ||||
$body->addRawSection(pht('INLINE COMMENTS')); | foreach ($xactions as $xaction) { | ||||
foreach ($inline_comments as $comment) { | if ($xaction->getTransactionType() == $type_inline) { | ||||
amckinley: Why not call the new `isInlineCommentTransaction` method? | |||||
Done Inline ActionsisInlineCommentTransaction() is really an existing method called by higher-level logic which currently means shouldSuppressCommentFromOverallListOfCommentsAtTheTopOfEmail(). Without it, addHeadersAndCommentsToMailBody() treats the inline comments as normal comments, and we get a big mess at the top of the mail like:
The isInlineCommentTransaction() method suppresses this, but other future or extension comments might want to suppress this behavior but also might not be renderable using the same "inline comment" logic. I think isInlineCommentTransaction() should probably be nuked and replaced with something more clear (and something that supports modular transactions) but didn't want to scope creep this change too much. epriestley: `isInlineCommentTransaction()` is really an existing method called by higher-level logic which… | |||||
$text = pht( | $inlines[] = $xaction; | ||||
'Image %d: %s', | |||||
$comment->getImageID(), | |||||
$comment->getContent()); | |||||
$body->addRawSection($text); | |||||
} | } | ||||
} | } | ||||
$this->appendInlineCommentsForMail($object, $inlines, $body); | |||||
$body->addLinkSection( | $body->addLinkSection( | ||||
pht('MOCK DETAIL'), | pht('MOCK DETAIL'), | ||||
PhabricatorEnv::getProductionURI('/M'.$object->getID())); | PhabricatorEnv::getProductionURI('/M'.$object->getID())); | ||||
return $body; | return $body; | ||||
} | } | ||||
private function appendInlineCommentsForMail( | |||||
$object, | |||||
array $inlines, | |||||
PhabricatorMetaMTAMailBody $body) { | |||||
if (!$inlines) { | |||||
return; | |||||
} | |||||
$viewer = $this->requireActor(); | |||||
$header = pht('INLINE COMMENTS'); | |||||
$body->addRawPlaintextSection($header); | |||||
$body->addRawHTMLSection(phutil_tag('strong', array(), $header)); | |||||
$image_ids = array(); | |||||
foreach ($inlines as $inline) { | |||||
$comment = $inline->getComment(); | |||||
$image_id = $comment->getImageID(); | |||||
$image_ids[$image_id] = $image_id; | |||||
} | |||||
$images = id(new PholioImageQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs($image_ids) | |||||
->execute(); | |||||
$images = mpull($images, null, 'getID'); | |||||
foreach ($inlines as $inline) { | |||||
$comment = $inline->getComment(); | |||||
$content = $comment->getContent(); | |||||
$image_id = $comment->getImageID(); | |||||
$image = idx($images, $image_id); | |||||
if ($image) { | |||||
$image_name = $image->getName(); | |||||
} else { | |||||
$image_name = pht('Unknown (ID %d)', $image_id); | |||||
} | |||||
$body->addRemarkupSection( | |||||
pht('Image "%s":', $image_name), | |||||
$content); | |||||
} | |||||
} | |||||
protected function getMailSubjectPrefix() { | protected function getMailSubjectPrefix() { | ||||
return PhabricatorEnv::getEnvConfig('metamta.pholio.subject-prefix'); | return PhabricatorEnv::getEnvConfig('metamta.pholio.subject-prefix'); | ||||
} | } | ||||
public function getMailTagsMap() { | public function getMailTagsMap() { | ||||
return array( | return array( | ||||
PholioTransaction::MAILTAG_STATUS => | PholioTransaction::MAILTAG_STATUS => | ||||
pht("A mock's status changes."), | pht("A mock's status changes."), | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |
Why not call the new isInlineCommentTransaction method?