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

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

+141 -6
+88
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 776 776 777 777 $body = parent::buildMailBody($object, $xactions); 778 778 779 + $type_inline = DifferentialTransaction::TYPE_INLINE; 780 + 781 + $inlines = array(); 782 + foreach ($xactions as $xaction) { 783 + if ($xaction->getTransactionType() == $type_inline) { 784 + $inlines[] = $xaction; 785 + } 786 + } 787 + 788 + if ($inlines) { 789 + $body->addTextSection( 790 + pht('INLINE COMMENTS'), 791 + $this->renderInlineCommentsForMail($object, $inlines)); 792 + } 793 + 779 794 $body->addTextSection( 780 795 pht('REVISION DETAIL'), 781 796 PhabricatorEnv::getProductionURI('/D'.$object->getID())); 797 + 782 798 783 799 return $body; 784 800 } ··· 796 812 797 813 return parent::extractFilePHIDsFromCustomTransaction($object, $xaction); 798 814 } 815 + 816 + private function renderInlineCommentsForMail( 817 + PhabricatorLiskDAO $object, 818 + array $inlines) { 819 + 820 + $context_key = 'metamta.differential.unified-comment-context'; 821 + $show_context = PhabricatorEnv::getEnvConfig($context_key); 822 + 823 + $changeset_ids = array(); 824 + foreach ($inlines as $inline) { 825 + $id = $inline->getComment()->getChangesetID(); 826 + $changeset_ids[$id] = $id; 827 + } 828 + 829 + // TODO: We should write a proper Query class for this eventually. 830 + $changesets = id(new DifferentialChangeset())->loadAllWhere( 831 + 'id IN (%Ld)', 832 + $changeset_ids); 833 + if ($show_context) { 834 + $hunk_parser = new DifferentialHunkParser(); 835 + foreach ($changesets as $changeset) { 836 + $changeset->attachHunks($changeset->loadHunks()); 837 + } 838 + } 839 + 840 + $inline_groups = DifferentialTransactionComment::sortAndGroupInlines( 841 + $inlines, 842 + $changesets); 843 + 844 + $result = array(); 845 + foreach ($inline_groups as $changeset_id => $group) { 846 + $changeset = idx($changesets, $changeset_id); 847 + if (!$changeset) { 848 + continue; 849 + } 850 + 851 + foreach ($group as $inline) { 852 + $comment = $inline->getComment(); 853 + $file = $changeset->getFilename(); 854 + $start = $comment->getLineNumber(); 855 + $len = $comment->getLineLength(); 856 + if ($len) { 857 + $range = $start.'-'.($start + $len); 858 + } else { 859 + $range = $start; 860 + } 861 + 862 + $inline_content = $comment->getContent(); 863 + 864 + if (!$show_context) { 865 + $result[] = "{$file}:{$range} {$inline_content}"; 866 + } else { 867 + $result[] = "================"; 868 + $result[] = "Comment at: " . $file . ":" . $range; 869 + $result[] = $hunk_parser->makeContextDiff( 870 + $changeset->getHunks(), 871 + $comment->getIsNewFile(), 872 + $comment->getLineNumber(), 873 + $comment->getLineLength(), 874 + 1); 875 + $result[] = "----------------"; 876 + 877 + $result[] = $inline_content; 878 + $result[] = null; 879 + } 880 + } 881 + } 882 + 883 + return implode("\n", $result); 884 + } 885 + 886 + 799 887 800 888 }
+30
src/applications/differential/storage/DifferentialTransaction.php
··· 41 41 return false; 42 42 } 43 43 44 + public function shouldHideForMail(array $xactions) { 45 + switch ($this->getTransactionType()) { 46 + case self::TYPE_INLINE: 47 + // Hide inlines when rendering mail transactions if any other 48 + // transaction type exists. 49 + foreach ($xactions as $xaction) { 50 + if ($xaction->getTransactionType() != self::TYPE_INLINE) { 51 + return true; 52 + } 53 + } 54 + 55 + // If only inline transactions exist, we just render the first one. 56 + return ($this !== head($xactions)); 57 + } 58 + 59 + return $this->shouldHide(); 60 + } 61 + 62 + public function getBodyForMail() { 63 + switch ($this->getTransactionType()) { 64 + case self::TYPE_INLINE: 65 + // Don't render inlines into the mail body; they render into a special 66 + // section immediately after the body instead. 67 + return null; 68 + } 69 + 70 + return parent::getBodyForMail(); 71 + } 72 + 73 + 44 74 public function getTitle() { 45 75 $author_phid = $this->getAuthorPHID(); 46 76 $author_handle = $this->renderHandleLink($author_phid);
+10 -5
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 1592 1592 $comments = array(); 1593 1593 1594 1594 foreach ($xactions as $xaction) { 1595 - if ($xaction->shouldHideForMail()) { 1595 + if ($xaction->shouldHideForMail($xactions)) { 1596 1596 continue; 1597 1597 } 1598 - $headers[] = id(clone $xaction)->setRenderingTarget('text')->getTitle(); 1599 - $comment = $xaction->getComment(); 1600 - if ($comment && strlen($comment->getContent())) { 1601 - $comments[] = $comment->getContent(); 1598 + 1599 + $header = $xaction->getTitleForMail(); 1600 + if ($header !== null) { 1601 + $headers[] = $header; 1602 + } 1603 + 1604 + $comment = $xaction->getBodyForMail(); 1605 + if ($comment !== null) { 1606 + $comments[] = $comment; 1602 1607 } 1603 1608 } 1604 1609
+13 -1
src/applications/transactions/storage/PhabricatorApplicationTransaction.php
··· 318 318 return false; 319 319 } 320 320 321 - public function shouldHideForMail() { 321 + public function shouldHideForMail(array $xactions) { 322 322 return $this->shouldHide(); 323 + } 324 + 325 + public function getTitleForMail() { 326 + return id(clone $this)->setRenderingTarget('text')->getTitle(); 327 + } 328 + 329 + public function getBodyForMail() { 330 + $comment = $this->getComment(); 331 + if ($comment && strlen($comment->getContent())) { 332 + return $comment->getContent(); 333 + } 334 + return null; 323 335 } 324 336 325 337 public function getNoEffectDescription() {