diff --git a/src/applications/differential/editor/DifferentialTransactionEditor.php b/src/applications/differential/editor/DifferentialTransactionEditor.php --- a/src/applications/differential/editor/DifferentialTransactionEditor.php +++ b/src/applications/differential/editor/DifferentialTransactionEditor.php @@ -636,8 +636,8 @@ $viewer = $this->requireActor(); - $body = new PhabricatorMetaMTAMailBody(); - $body->setViewer($this->requireActor()); + $body = id(new PhabricatorMetaMTAMailBody()) + ->setViewer($viewer); $revision_uri = $object->getURI(); $revision_uri = PhabricatorEnv::getProductionURI($revision_uri); diff --git a/src/applications/pholio/editor/PholioMockEditor.php b/src/applications/pholio/editor/PholioMockEditor.php --- a/src/applications/pholio/editor/PholioMockEditor.php +++ b/src/applications/pholio/editor/PholioMockEditor.php @@ -128,52 +128,31 @@ PhabricatorLiskDAO $object, array $xactions) { - $body = new PhabricatorMetaMTAMailBody(); - $headers = array(); - $comments = array(); - $inline_comments = array(); + $viewer = $this->requireActor(); - foreach ($xactions as $xaction) { - if ($xaction->shouldHide()) { - 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 = id(new PhabricatorMetaMTAMailBody()) + ->setViewer($viewer); - $body->addRawSection(implode("\n", $headers)); + $mock_uri = $object->getURI(); + $mock_uri = PhabricatorEnv::getProductionURI($mock_uri); - foreach ($comments as $comment) { - $body->addRawSection($comment); - } + $this->addHeadersAndCommentsToMailBody( + $body, + $xactions, + pht('View Mock'), + $mock_uri); - if ($inline_comments) { - $body->addRawSection(pht('INLINE COMMENTS')); - foreach ($inline_comments as $comment) { - $text = pht( - 'Image %d: %s', - $comment->getImageID(), - $comment->getContent()); - $body->addRawSection($text); + $type_inline = PholioMockInlineTransaction::TRANSACTIONTYPE; + + $inlines = array(); + foreach ($xactions as $xaction) { + if ($xaction->getTransactionType() == $type_inline) { + $inlines[] = $xaction; } } + $this->appendInlineCommentsForMail($object, $inlines, $body); + $body->addLinkSection( pht('MOCK DETAIL'), PhabricatorEnv::getProductionURI('/M'.$object->getID())); @@ -181,6 +160,51 @@ 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() { return PhabricatorEnv::getEnvConfig('metamta.pholio.subject-prefix'); } diff --git a/src/applications/pholio/storage/PholioMock.php b/src/applications/pholio/storage/PholioMock.php --- a/src/applications/pholio/storage/PholioMock.php +++ b/src/applications/pholio/storage/PholioMock.php @@ -58,6 +58,10 @@ return 'M'.$this->getID(); } + public function getURI() { + return '/'.$this->getMonogram(); + } + protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, diff --git a/src/applications/pholio/storage/PholioTransaction.php b/src/applications/pholio/storage/PholioTransaction.php --- a/src/applications/pholio/storage/PholioTransaction.php +++ b/src/applications/pholio/storage/PholioTransaction.php @@ -53,4 +53,13 @@ return $tags; } + public function isInlineCommentTransaction() { + switch ($this->getTransactionType()) { + case PholioMockInlineTransaction::TRANSACTIONTYPE: + return true; + } + + return parent::isInlineCommentTransaction(); + } + }