2012-02-24 23:14:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionCommentView extends AphrontView {
|
|
|
|
|
|
|
|
private $user;
|
|
|
|
private $comment;
|
|
|
|
private $commentNumber;
|
|
|
|
private $handles;
|
2012-02-27 22:00:23 +01:00
|
|
|
private $isPreview;
|
2012-03-20 03:56:06 +01:00
|
|
|
private $pathMap;
|
|
|
|
|
|
|
|
private $inlineComments;
|
2012-10-24 02:46:44 +02:00
|
|
|
private $markupEngine;
|
2012-02-24 23:14:39 +01:00
|
|
|
|
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setComment(PhabricatorAuditComment $comment) {
|
|
|
|
$this->comment = $comment;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCommentNumber($comment_number) {
|
|
|
|
$this->commentNumber = $comment_number;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setHandles(array $handles) {
|
2012-04-04 01:22:31 +02:00
|
|
|
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
2012-02-24 23:14:39 +01:00
|
|
|
$this->handles = $handles;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-02-27 22:00:23 +01:00
|
|
|
public function setIsPreview($is_preview) {
|
|
|
|
$this->isPreview = $is_preview;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-03-20 03:56:06 +01:00
|
|
|
public function setInlineComments(array $inline_comments) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
2012-03-20 03:56:06 +01:00
|
|
|
$this->inlineComments = $inline_comments;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPathMap(array $path_map) {
|
|
|
|
$this->pathMap = $path_map;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-24 02:46:44 +02:00
|
|
|
public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) {
|
|
|
|
$this->markupEngine = $markup_engine;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMarkupEngine() {
|
|
|
|
return $this->markupEngine;
|
|
|
|
}
|
|
|
|
|
2012-02-27 22:00:23 +01:00
|
|
|
public function getRequiredHandlePHIDs() {
|
|
|
|
return array($this->comment->getActorPHID());
|
|
|
|
}
|
|
|
|
|
2012-02-24 23:14:39 +01:00
|
|
|
private function getHandle($phid) {
|
|
|
|
if (empty($this->handles[$phid])) {
|
|
|
|
throw new Exception("Unloaded handle '{$phid}'!");
|
|
|
|
}
|
|
|
|
return $this->handles[$phid];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
$comment = $this->comment;
|
|
|
|
$author = $this->getHandle($comment->getActorPHID());
|
|
|
|
$author_link = $author->renderLink();
|
|
|
|
|
|
|
|
$actions = $this->renderActions();
|
|
|
|
$content = $this->renderContent();
|
|
|
|
$classes = $this->renderClasses();
|
|
|
|
|
|
|
|
$xaction_view = id(new PhabricatorTransactionView())
|
|
|
|
->setUser($this->user)
|
|
|
|
->setImageURI($author->getImageURI())
|
|
|
|
->setActions($actions)
|
|
|
|
->appendChild($content);
|
|
|
|
|
2012-02-27 22:00:23 +01:00
|
|
|
if ($this->isPreview) {
|
|
|
|
$xaction_view->setIsPreview(true);
|
|
|
|
} else {
|
|
|
|
$xaction_view
|
|
|
|
->setAnchor('comment-'.$this->commentNumber, '#'.$this->commentNumber)
|
|
|
|
->setEpoch($comment->getDateCreated());
|
|
|
|
}
|
|
|
|
|
2012-02-24 23:14:39 +01:00
|
|
|
foreach ($classes as $class) {
|
|
|
|
$xaction_view->addClass($class);
|
|
|
|
}
|
|
|
|
|
2012-02-27 22:00:23 +01:00
|
|
|
return $xaction_view->render();
|
2012-02-24 23:14:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderActions() {
|
|
|
|
$comment = $this->comment;
|
|
|
|
$author = $this->getHandle($comment->getActorPHID());
|
|
|
|
$author_link = $author->renderLink();
|
|
|
|
|
2012-03-26 18:44:06 +02:00
|
|
|
$action = $comment->getAction();
|
|
|
|
$verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($action);
|
|
|
|
|
2012-04-23 22:50:04 +02:00
|
|
|
$metadata = $comment->getMetadata();
|
|
|
|
$added_auditors = idx(
|
|
|
|
$metadata,
|
|
|
|
PhabricatorAuditComment::METADATA_ADDED_AUDITORS,
|
|
|
|
array());
|
|
|
|
$added_ccs = idx(
|
|
|
|
$metadata,
|
|
|
|
PhabricatorAuditComment::METADATA_ADDED_CCS,
|
|
|
|
array());
|
|
|
|
|
2012-02-24 23:14:39 +01:00
|
|
|
$actions = array();
|
2012-04-23 22:50:04 +02:00
|
|
|
if ($action == PhabricatorAuditActionConstants::ADD_CCS) {
|
|
|
|
$rendered_ccs = $this->renderHandleList($added_ccs);
|
|
|
|
$actions[] = "{$author_link} added CCs: {$rendered_ccs}.";
|
|
|
|
} else if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS) {
|
|
|
|
$rendered_auditors = $this->renderHandleList($added_auditors);
|
|
|
|
$actions[] = "{$author_link} added auditors: ".
|
|
|
|
"{$rendered_auditors}.";
|
|
|
|
} else {
|
|
|
|
$actions[] = "{$author_link} ".phutil_escape_html($verb)." this commit.";
|
|
|
|
}
|
2012-02-24 23:14:39 +01:00
|
|
|
|
|
|
|
foreach ($actions as $key => $action) {
|
|
|
|
$actions[$key] = '<div>'.$action.'</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderContent() {
|
|
|
|
$comment = $this->comment;
|
2012-10-24 02:46:44 +02:00
|
|
|
$engine = $this->getMarkupEngine();
|
2012-02-24 23:14:39 +01:00
|
|
|
|
2012-03-26 19:05:15 +02:00
|
|
|
if (!strlen($comment->getContent()) && empty($this->inlineComments)) {
|
2012-03-26 18:44:06 +02:00
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return
|
|
|
|
'<div class="phabricator-remarkup">'.
|
2012-10-24 02:46:44 +02:00
|
|
|
$engine->getOutput(
|
|
|
|
$comment,
|
|
|
|
PhabricatorAuditComment::MARKUP_FIELD_BODY).
|
2012-03-26 18:44:06 +02:00
|
|
|
$this->renderSingleView($this->renderInlines()).
|
|
|
|
'</div>';
|
|
|
|
}
|
2012-02-24 23:14:39 +01:00
|
|
|
}
|
|
|
|
|
2012-03-20 03:56:06 +01:00
|
|
|
private function renderInlines() {
|
|
|
|
if (!$this->inlineComments) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-10-24 02:46:44 +02:00
|
|
|
$engine = $this->getMarkupEngine();
|
|
|
|
|
2012-03-20 03:56:06 +01:00
|
|
|
$inlines_by_path = mgroup($this->inlineComments, 'getPathID');
|
|
|
|
|
|
|
|
$view = new PhabricatorInlineSummaryView();
|
|
|
|
foreach ($inlines_by_path as $path_id => $inlines) {
|
|
|
|
$path = idx($this->pathMap, $path_id);
|
|
|
|
if ($path === null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$items = array();
|
|
|
|
foreach ($inlines as $inline) {
|
|
|
|
$items[] = array(
|
|
|
|
'id' => $inline->getID(),
|
|
|
|
'line' => $inline->getLineNumber(),
|
|
|
|
'length' => $inline->getLineLength(),
|
2012-10-24 02:46:44 +02:00
|
|
|
'content' => $engine->getOutput(
|
2012-03-20 03:56:06 +01:00
|
|
|
$inline,
|
2012-10-24 02:46:44 +02:00
|
|
|
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY),
|
2012-03-20 03:56:06 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->addCommentGroup($path, $items);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2012-04-23 22:50:04 +02:00
|
|
|
private function renderHandleList(array $phids) {
|
|
|
|
$result = array();
|
|
|
|
foreach ($phids as $phid) {
|
|
|
|
$result[] = $this->handles[$phid]->renderLink();
|
|
|
|
}
|
|
|
|
return implode(', ', $result);
|
|
|
|
}
|
|
|
|
|
2012-02-24 23:14:39 +01:00
|
|
|
private function renderClasses() {
|
|
|
|
$comment = $this->comment;
|
|
|
|
|
|
|
|
$classes = array();
|
|
|
|
switch ($comment->getAction()) {
|
|
|
|
case PhabricatorAuditActionConstants::ACCEPT:
|
|
|
|
$classes[] = 'audit-accept';
|
|
|
|
break;
|
|
|
|
case PhabricatorAuditActionConstants::CONCERN:
|
|
|
|
$classes[] = 'audit-concern';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|