Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15405684
D8343.id19842.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D8343.id19842.diff
View Options
Index: src/applications/differential/editor/DifferentialTransactionEditor.php
===================================================================
--- src/applications/differential/editor/DifferentialTransactionEditor.php
+++ src/applications/differential/editor/DifferentialTransactionEditor.php
@@ -776,10 +776,26 @@
$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(
pht('REVISION DETAIL'),
PhabricatorEnv::getProductionURI('/D'.$object->getID()));
+
return $body;
}
@@ -797,4 +813,76 @@
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);
+ }
+
+
+
}
Index: src/applications/differential/storage/DifferentialTransaction.php
===================================================================
--- src/applications/differential/storage/DifferentialTransaction.php
+++ src/applications/differential/storage/DifferentialTransaction.php
@@ -41,6 +41,36 @@
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() {
$author_phid = $this->getAuthorPHID();
$author_handle = $this->renderHandleLink($author_phid);
Index: src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
===================================================================
--- src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
+++ src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
@@ -1592,13 +1592,18 @@
$comments = array();
foreach ($xactions as $xaction) {
- if ($xaction->shouldHideForMail()) {
+ if ($xaction->shouldHideForMail($xactions)) {
continue;
}
- $headers[] = id(clone $xaction)->setRenderingTarget('text')->getTitle();
- $comment = $xaction->getComment();
- if ($comment && strlen($comment->getContent())) {
- $comments[] = $comment->getContent();
+
+ $header = $xaction->getTitleForMail();
+ if ($header !== null) {
+ $headers[] = $header;
+ }
+
+ $comment = $xaction->getBodyForMail();
+ if ($comment !== null) {
+ $comments[] = $comment;
}
}
Index: src/applications/transactions/storage/PhabricatorApplicationTransaction.php
===================================================================
--- src/applications/transactions/storage/PhabricatorApplicationTransaction.php
+++ src/applications/transactions/storage/PhabricatorApplicationTransaction.php
@@ -318,10 +318,22 @@
return false;
}
- public function shouldHideForMail() {
+ public function shouldHideForMail(array $xactions) {
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() {
switch ($this->getTransactionType()) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 19, 11:47 AM (3 d, 5 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7319365
Default Alt Text
D8343.id19842.diff (6 KB)
Attached To
Mode
D8343: Render inline comments in "Pro" mail
Attached
Detach File
Event Timeline
Log In to Comment