1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 17:28:51 +02:00

Render inline comments in "Pro" mail

Summary: Ref T2222. This enriches mail a little bit to get these rendering pretty much like they do now.

Test Plan: {F118255}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2222

Differential Revision: https://secure.phabricator.com/D8343
This commit is contained in:
epriestley 2014-02-25 15:29:10 -08:00
parent 64d15c344e
commit 424ba2e588
4 changed files with 141 additions and 6 deletions

View file

@ -776,10 +776,26 @@ final class DifferentialTransactionEditor
$body = parent::buildMailBody($object, $xactions); $body = parent::buildMailBody($object, $xactions);
$type_inline = DifferentialTransaction::TYPE_INLINE;
$inlines = array();
foreach ($xactions as $xaction) {
if ($xaction->getTransactionType() == $type_inline) {
$inlines[] = $xaction;
}
}
if ($inlines) {
$body->addTextSection(
pht('INLINE COMMENTS'),
$this->renderInlineCommentsForMail($object, $inlines));
}
$body->addTextSection( $body->addTextSection(
pht('REVISION DETAIL'), pht('REVISION DETAIL'),
PhabricatorEnv::getProductionURI('/D'.$object->getID())); PhabricatorEnv::getProductionURI('/D'.$object->getID()));
return $body; return $body;
} }
@ -797,4 +813,76 @@ final class DifferentialTransactionEditor
return parent::extractFilePHIDsFromCustomTransaction($object, $xaction); return parent::extractFilePHIDsFromCustomTransaction($object, $xaction);
} }
private function renderInlineCommentsForMail(
PhabricatorLiskDAO $object,
array $inlines) {
$context_key = 'metamta.differential.unified-comment-context';
$show_context = PhabricatorEnv::getEnvConfig($context_key);
$changeset_ids = array();
foreach ($inlines as $inline) {
$id = $inline->getComment()->getChangesetID();
$changeset_ids[$id] = $id;
}
// TODO: We should write a proper Query class for this eventually.
$changesets = id(new DifferentialChangeset())->loadAllWhere(
'id IN (%Ld)',
$changeset_ids);
if ($show_context) {
$hunk_parser = new DifferentialHunkParser();
foreach ($changesets as $changeset) {
$changeset->attachHunks($changeset->loadHunks());
}
}
$inline_groups = DifferentialTransactionComment::sortAndGroupInlines(
$inlines,
$changesets);
$result = array();
foreach ($inline_groups as $changeset_id => $group) {
$changeset = idx($changesets, $changeset_id);
if (!$changeset) {
continue;
}
foreach ($group as $inline) {
$comment = $inline->getComment();
$file = $changeset->getFilename();
$start = $comment->getLineNumber();
$len = $comment->getLineLength();
if ($len) {
$range = $start.'-'.($start + $len);
} else {
$range = $start;
}
$inline_content = $comment->getContent();
if (!$show_context) {
$result[] = "{$file}:{$range} {$inline_content}";
} else {
$result[] = "================";
$result[] = "Comment at: " . $file . ":" . $range;
$result[] = $hunk_parser->makeContextDiff(
$changeset->getHunks(),
$comment->getIsNewFile(),
$comment->getLineNumber(),
$comment->getLineLength(),
1);
$result[] = "----------------";
$result[] = $inline_content;
$result[] = null;
}
}
}
return implode("\n", $result);
}
} }

View file

@ -41,6 +41,36 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction {
return false; return false;
} }
public function shouldHideForMail(array $xactions) {
switch ($this->getTransactionType()) {
case self::TYPE_INLINE:
// Hide inlines when rendering mail transactions if any other
// transaction type exists.
foreach ($xactions as $xaction) {
if ($xaction->getTransactionType() != self::TYPE_INLINE) {
return true;
}
}
// If only inline transactions exist, we just render the first one.
return ($this !== head($xactions));
}
return $this->shouldHide();
}
public function getBodyForMail() {
switch ($this->getTransactionType()) {
case self::TYPE_INLINE:
// Don't render inlines into the mail body; they render into a special
// section immediately after the body instead.
return null;
}
return parent::getBodyForMail();
}
public function getTitle() { public function getTitle() {
$author_phid = $this->getAuthorPHID(); $author_phid = $this->getAuthorPHID();
$author_handle = $this->renderHandleLink($author_phid); $author_handle = $this->renderHandleLink($author_phid);

View file

@ -1592,13 +1592,18 @@ abstract class PhabricatorApplicationTransactionEditor
$comments = array(); $comments = array();
foreach ($xactions as $xaction) { foreach ($xactions as $xaction) {
if ($xaction->shouldHideForMail()) { if ($xaction->shouldHideForMail($xactions)) {
continue; continue;
} }
$headers[] = id(clone $xaction)->setRenderingTarget('text')->getTitle();
$comment = $xaction->getComment(); $header = $xaction->getTitleForMail();
if ($comment && strlen($comment->getContent())) { if ($header !== null) {
$comments[] = $comment->getContent(); $headers[] = $header;
}
$comment = $xaction->getBodyForMail();
if ($comment !== null) {
$comments[] = $comment;
} }
} }

View file

@ -318,10 +318,22 @@ abstract class PhabricatorApplicationTransaction
return false; return false;
} }
public function shouldHideForMail() { public function shouldHideForMail(array $xactions) {
return $this->shouldHide(); return $this->shouldHide();
} }
public function getTitleForMail() {
return id(clone $this)->setRenderingTarget('text')->getTitle();
}
public function getBodyForMail() {
$comment = $this->getComment();
if ($comment && strlen($comment->getContent())) {
return $comment->getContent();
}
return null;
}
public function getNoEffectDescription() { public function getNoEffectDescription() {
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {