1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Write "hasReplies" to database for inline comments

Summary:
Ref T1460. Ref T2618.

When publishing a draft inline, mark the inline it replies to (if any) as replied to.

Also, don't load deleted comments as drafts (sets the stage for T2618).

I'll make an effort to clean up the loading mess here in the next revision, and find some more appropriate home for the shared code.

Test Plan: Made and replied to comments in Differential and Diffusion. Saw comments get marked as "Has Replies" and "Is Reply".

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2618, T1460

Differential Revision: https://secure.phabricator.com/D12025
This commit is contained in:
epriestley 2015-03-09 11:51:26 -07:00
parent f66edccf62
commit 2972894a4d
7 changed files with 91 additions and 5 deletions

View file

@ -135,9 +135,14 @@ final class PhabricatorAuditEditor
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
case PhabricatorTransactions::TYPE_EDGE:
case PhabricatorAuditActionConstants::ACTION:
case PhabricatorAuditActionConstants::INLINE:
case PhabricatorAuditTransaction::TYPE_COMMIT:
return;
case PhabricatorAuditActionConstants::INLINE:
$reply = $xaction->getComment()->getReplyToComment();
if ($reply && !$reply->getHasReplies()) {
$reply->setHasReplies(1)->save();
}
return;
case PhabricatorAuditActionConstants::ADD_AUDITORS:
$new = $xaction->getNewValue();
if (!is_array($new)) {

View file

@ -63,10 +63,15 @@ final class PhabricatorAuditInlineComment
$inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere(
'authorPHID = %s AND commitPHID = %s AND transactionPHID IS NULL
AND pathID IS NOT NULL',
AND pathID IS NOT NULL
AND isDeleted = 0',
$viewer->getPHID(),
$commit_phid);
$inlines = PhabricatorInlineCommentController::loadAndAttachReplies(
$viewer,
$inlines);
return self::buildProxies($inlines);
}
@ -96,7 +101,7 @@ final class PhabricatorAuditInlineComment
} else {
$inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere(
'commitPHID = %s AND pathID = %d AND
(authorPHID = %s OR transactionPHID IS NOT NULL)',
((authorPHID = %s AND isDeleted = 0) OR transactionPHID IS NOT NULL)',
$commit_phid,
$path_id,
$viewer->getPHID());

View file

@ -13,6 +13,8 @@ final class PhabricatorAuditTransactionComment
protected $replyToCommentPHID;
protected $legacyCommentID;
private $replyToComment = self::ATTACHABLE;
public function getApplicationTransactionObject() {
return new PhabricatorAuditTransaction();
}
@ -55,4 +57,14 @@ final class PhabricatorAuditTransactionComment
return $config;
}
public function attachReplyToComment(
PhabricatorAuditTransactionComment $comment = null) {
$this->replyToComment = $comment;
return $this;
}
public function getReplyToComment() {
return $this->assertAttached($this->replyToComment);
}
}

View file

@ -534,7 +534,12 @@ final class DifferentialTransactionEditor
case PhabricatorTransactions::TYPE_EDGE:
case PhabricatorTransactions::TYPE_COMMENT:
case DifferentialTransaction::TYPE_ACTION:
return;
case DifferentialTransaction::TYPE_INLINE:
$reply = $xaction->getComment()->getReplyToComment();
if ($reply && !$reply->getHasReplies()) {
$reply->setHasReplies(1)->save();
}
return;
case DifferentialTransaction::TYPE_UPDATE:
// Now that we're inside the transaction, do a final check.

View file

@ -25,7 +25,8 @@ final class DifferentialTransactionQuery
'SELECT phid FROM %T
WHERE revisionPHID = %s
AND authorPHID = %s
AND transactionPHID IS NULL',
AND transactionPHID IS NULL
AND isDeleted = 0',
$table->getTableName(),
$revision->getPHID(),
$viewer->getPHID());
@ -35,11 +36,17 @@ final class DifferentialTransactionQuery
return array();
}
return id(new PhabricatorApplicationTransactionCommentQuery())
$comments = id(new PhabricatorApplicationTransactionCommentQuery())
->setTemplate(new DifferentialTransactionComment())
->setViewer($viewer)
->withPHIDs($phids)
->execute();
$comments = PhabricatorInlineCommentController::loadAndAttachReplies(
$viewer,
$comments);
return $comments;
}
}

View file

@ -12,10 +12,22 @@ final class DifferentialTransactionComment
protected $hasReplies = 0;
protected $replyToCommentPHID;
private $replyToComment = self::ATTACHABLE;
public function getApplicationTransactionObject() {
return new DifferentialTransaction();
}
public function attachReplyToComment(
DifferentialTransactionComment $comment = null) {
$this->replyToComment = $comment;
return $this;
}
public function getReplyToComment() {
return $this->assertAttached($this->replyToComment);
}
protected function getConfiguration() {
$config = parent::getConfiguration();
$config[self::CONFIG_COLUMN_SCHEMA] = array(

View file

@ -309,4 +309,44 @@ abstract class PhabricatorInlineCommentController
->addRowScaffold($view);
}
public static function loadAndAttachReplies(
PhabricatorUser $viewer,
array $comments) {
// TODO: This code doesn't really belong here, but we don't have a much
// better place to put it at the moment.
if (!$comments) {
return $comments;
}
$template = head($comments);
$reply_phids = array();
foreach ($comments as $comment) {
$reply_phid = $comment->getReplyToCommentPHID();
if ($reply_phid) {
$reply_phids[] = $reply_phid;
}
}
if ($reply_phids) {
$reply_comments = id(new PhabricatorApplicationTransactionCommentQuery())
->setTemplate($template)
->setViewer($viewer)
->withPHIDs($reply_phids)
->execute();
$reply_comments = mpull($reply_comments, null, 'getPHID');
} else {
$reply_comments = array();
}
foreach ($comments as $comment) {
$reply_phid = $comment->getReplyToCommentPHID();
$reply = idx($reply_comments, $reply_phid);
$comment->attachReplyToComment($reply);
}
return $comments;
}
}