protected function renderTransactionContent(PhabricatorApplicationTransaction $xaction) { $out = array(); $type_inline = DifferentialTransaction::TYPE_INLINE; $group = $xaction->getTransactionGroup(); if ($xaction->getTransactionType() == $type_inline) { array_unshift($group, $xaction); } else { $out[] = parent::renderTransactionContent($xaction); } if (!$group) { return $out; } $inlines = array(); foreach ($group as $xaction) { switch ($xaction->getTransactionType()) { case DifferentialTransaction::TYPE_INLINE: $inlines[] = $xaction; break; default: throw new Exception('Unknown grouped transaction type!'); } } if ($inlines) { $inline_view = new PhabricatorInlineSummaryView(); $changesets = $this->getChangesets(); $inline_groups = DifferentialTransactionComment::sortAndGroupInlines($inlines, $changesets); foreach ($inline_groups as $changeset_id => $group) { $changeset = $changesets[$changeset_id]; $items = array(); foreach ($group as $inline) { $comment = $inline->getComment(); $item = array('id' => $comment->getID(), 'line' => $comment->getLineNumber(), 'length' => $comment->getLineLength(), 'content' => parent::renderTransactionContent($inline)); $changeset_diff_id = $changeset->getDiffID(); if ($comment->getIsNewFile()) { $visible_diff_id = $this->getRightDiff()->getID(); } else { $visible_diff_id = $this->getLeftDiff()->getID(); } // TODO: We still get one edge case wrong here, when we have a // versus diff and the file didn't exist in the old version. The // comment is visible because we show the left side of the target // diff when there's no corresponding file in the versus diff, but // we incorrectly link it off-page. $is_visible = $changeset_diff_id == $visible_diff_id; if (!$is_visible) { $item['where'] = pht('(On Diff #%d)', $changeset_diff_id); $revision_id = $this->getRevision()->getID(); $comment_id = $comment->getID(); $item['href'] = '/D' . $revision_id . '?id=' . $changeset_diff_id . '#inline-' . $comment_id; } $items[] = $item; } $inline_view->addCommentGroup($changeset->getFilename(), $items); } $out[] = $inline_view; } return $out; }
private function renderInlineCommentsForMail(PhabricatorLiskDAO $object, array $inlines) { $context_key = 'metamta.differential.unified-comment-context'; $show_context = PhabricatorEnv::getEnvConfig($context_key); $changeset_ids = array(); $line_numbers_by_changeset = array(); foreach ($inlines as $inline) { $id = $inline->getComment()->getChangesetID(); $changeset_ids[$id] = $id; $line_numbers_by_changeset[$id][] = $inline->getComment()->getLineNumber(); } $changesets = id(new DifferentialChangesetQuery())->setViewer($this->getActor())->withIDs($changeset_ids)->needHunks(true)->execute(); $inline_groups = DifferentialTransactionComment::sortAndGroupInlines($inlines, $changesets); if ($show_context) { $hunk_parser = new DifferentialHunkParser(); $table = new DifferentialTransactionComment(); $conn_r = $table->establishConnection('r'); $queries = array(); foreach ($line_numbers_by_changeset as $id => $line_numbers) { $queries[] = qsprintf($conn_r, '(changesetID = %d AND lineNumber IN (%Ld))', $id, $line_numbers); } $all_comments = id(new DifferentialTransactionComment())->loadAllWhere('transactionPHID IS NOT NULL AND (%Q)', implode(' OR ', $queries)); $comments_by_line_number = array(); foreach ($all_comments as $comment) { $comments_by_line_number[$comment->getChangesetID()][$comment->getLineNumber()][$comment->getID()] = $comment; } $author_phids = mpull($all_comments, 'getAuthorPHID'); $authors = id(new PhabricatorPeopleQuery())->setViewer($this->getActor())->withPHIDs($author_phids)->execute(); $authors_by_phid = mpull($authors, null, 'getPHID'); } $section = new PhabricatorMetaMTAMailSection(); 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) { $section->addFragment("{$file}:{$range} {$inline_content}"); } else { $patch = $hunk_parser->makeContextDiff($changeset->getHunks(), $comment->getIsNewFile(), $comment->getLineNumber(), $comment->getLineLength(), 1); $nested_comments = $this->nestCommentHistory($inline->getComment(), $comments_by_line_number, $authors_by_phid); $section->addFragment('================')->addFragment(pht('Comment at: %s:%s', $file, $range))->addPlaintextFragment($patch)->addHTMLFragment($this->renderPatchHTMLForMail($patch))->addFragment('----------------')->addFragment($nested_comments)->addFragment(null); } } } return $section; }
private function groupInlines(array $inlines) { return DifferentialTransactionComment::sortAndGroupInlines($inlines, $this->changesets); }