Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php
<?php | <?php | ||||
abstract class PhabricatorDiffInlineCommentQuery | abstract class PhabricatorDiffInlineCommentQuery | ||||
extends PhabricatorApplicationTransactionCommentQuery { | extends PhabricatorApplicationTransactionCommentQuery { | ||||
private $fixedStates; | private $fixedStates; | ||||
private $needReplyToComments; | private $needReplyToComments; | ||||
private $publishedComments; | private $publishedComments; | ||||
private $publishableComments; | private $publishableComments; | ||||
private $needHidden; | private $needHidden; | ||||
private $needAppliedDrafts; | |||||
abstract protected function buildInlineCommentWhereClauseParts( | abstract protected function buildInlineCommentWhereClauseParts( | ||||
AphrontDatabaseConnection $conn); | AphrontDatabaseConnection $conn); | ||||
abstract public function withObjectPHIDs(array $phids); | abstract public function withObjectPHIDs(array $phids); | ||||
abstract protected function loadHiddenCommentIDs( | abstract protected function loadHiddenCommentIDs( | ||||
$viewer_phid, | $viewer_phid, | ||||
array $comments); | array $comments); | ||||
Show All 17 Lines | final public function withPublishedComments($with_published) { | ||||
return $this; | return $this; | ||||
} | } | ||||
final public function needHidden($need_hidden) { | final public function needHidden($need_hidden) { | ||||
$this->needHidden = $need_hidden; | $this->needHidden = $need_hidden; | ||||
return $this; | return $this; | ||||
} | } | ||||
final public function needAppliedDrafts($need_applied) { | |||||
$this->needAppliedDrafts = $need_applied; | |||||
return $this; | |||||
} | |||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
$alias = $this->getPrimaryTableAlias(); | $alias = $this->getPrimaryTableAlias(); | ||||
foreach ($this->buildInlineCommentWhereClauseParts($conn) as $part) { | foreach ($this->buildInlineCommentWhereClauseParts($conn) as $part) { | ||||
$where[] = $part; | $where[] = $part; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if ($show_publishable || $show_published) { | ||||
$conn, | $conn, | ||||
'%LO', | '%LO', | ||||
$clauses); | $clauses); | ||||
} | } | ||||
return $where; | return $where; | ||||
} | } | ||||
protected function willFilterPage(array $comments) { | protected function willFilterPage(array $inlines) { | ||||
$viewer = $this->getViewer(); | |||||
if ($this->needReplyToComments) { | if ($this->needReplyToComments) { | ||||
$reply_phids = array(); | $reply_phids = array(); | ||||
foreach ($comments as $comment) { | foreach ($inlines as $inline) { | ||||
$reply_phid = $comment->getReplyToCommentPHID(); | $reply_phid = $inline->getReplyToCommentPHID(); | ||||
if ($reply_phid) { | if ($reply_phid) { | ||||
$reply_phids[] = $reply_phid; | $reply_phids[] = $reply_phid; | ||||
} | } | ||||
} | } | ||||
if ($reply_phids) { | if ($reply_phids) { | ||||
$reply_comments = newv(get_class($this), array()) | $reply_inlines = newv(get_class($this), array()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->withPHIDs($reply_phids) | ->withPHIDs($reply_phids) | ||||
->execute(); | ->execute(); | ||||
$reply_comments = mpull($reply_comments, null, 'getPHID'); | $reply_inlines = mpull($reply_inlines, null, 'getPHID'); | ||||
} else { | } else { | ||||
$reply_comments = array(); | $reply_inlines = array(); | ||||
} | } | ||||
foreach ($comments as $key => $comment) { | foreach ($inlines as $key => $inline) { | ||||
$reply_phid = $comment->getReplyToCommentPHID(); | $reply_phid = $inline->getReplyToCommentPHID(); | ||||
if (!$reply_phid) { | if (!$reply_phid) { | ||||
$comment->attachReplyToComment(null); | $inline->attachReplyToComment(null); | ||||
continue; | continue; | ||||
} | } | ||||
$reply = idx($reply_comments, $reply_phid); | $reply = idx($reply_inlines, $reply_phid); | ||||
if (!$reply) { | if (!$reply) { | ||||
$this->didRejectResult($comment); | $this->didRejectResult($inline); | ||||
unset($comments[$key]); | unset($inlines[$key]); | ||||
continue; | continue; | ||||
} | } | ||||
$comment->attachReplyToComment($reply); | $inline->attachReplyToComment($reply); | ||||
} | } | ||||
} | } | ||||
if (!$comments) { | if (!$inlines) { | ||||
return $comments; | return $inlines; | ||||
} | } | ||||
if ($this->needHidden) { | if ($this->needHidden) { | ||||
$viewer = $this->getViewer(); | |||||
$viewer_phid = $viewer->getPHID(); | $viewer_phid = $viewer->getPHID(); | ||||
if ($viewer_phid) { | if ($viewer_phid) { | ||||
$hidden = $this->loadHiddenCommentIDs( | $hidden = $this->loadHiddenCommentIDs( | ||||
$viewer_phid, | $viewer_phid, | ||||
$comments); | $inlines); | ||||
} else { | } else { | ||||
$hidden = array(); | $hidden = array(); | ||||
} | } | ||||
foreach ($comments as $inline) { | foreach ($inlines as $inline) { | ||||
$inline->attachIsHidden(isset($hidden[$inline->getID()])); | $inline->attachIsHidden(isset($hidden[$inline->getID()])); | ||||
} | } | ||||
} | } | ||||
return $comments; | if (!$inlines) { | ||||
return $inlines; | |||||
} | |||||
$need_drafts = $this->needAppliedDrafts; | |||||
$drop_void = $this->publishableComments; | |||||
$convert_objects = ($need_drafts || $drop_void); | |||||
if ($convert_objects) { | |||||
$inlines = mpull($inlines, 'newInlineCommentObject'); | |||||
PhabricatorInlineComment::loadAndAttachVersionedDrafts( | |||||
$viewer, | |||||
$inlines); | |||||
if ($need_drafts) { | |||||
// Don't count void inlines when considering draft state. | |||||
foreach ($inlines as $key => $inline) { | |||||
if ($inline->isVoidComment($viewer)) { | |||||
$this->didRejectResult($inline->getStorageObject()); | |||||
unset($inlines[$key]); | |||||
continue; | |||||
} | |||||
// For other inlines: if they have a nonempty draft state, set their | |||||
// content to the draft state content. We want to submit the comment | |||||
// as it is currently shown to the user, not as it was stored the last | |||||
// time they clicked "Save". | |||||
$draft_content = $inline->getContentForEdit($viewer); | |||||
if (strlen($draft_content)) { | |||||
$inline->setContent($draft_content); | |||||
} | |||||
} | |||||
} | |||||
// If we're loading publishable comments, discard any comments that are | |||||
// empty. | |||||
if ($drop_void) { | |||||
foreach ($inlines as $key => $inline) { | |||||
if ($inline->getTransactionPHID()) { | |||||
continue; | |||||
} | |||||
if ($inline->isVoidComment($viewer)) { | |||||
$this->didRejectResult($inline->getStorageObject()); | |||||
unset($inlines[$key]); | |||||
continue; | |||||
} | |||||
} | |||||
} | |||||
$inlines = mpull($inlines, 'getStorageObject'); | |||||
} | |||||
return $inlines; | |||||
} | } | ||||
} | } |