diff --git a/src/applications/differential/editor/DifferentialTransactionEditor.php b/src/applications/differential/editor/DifferentialTransactionEditor.php --- a/src/applications/differential/editor/DifferentialTransactionEditor.php +++ b/src/applications/differential/editor/DifferentialTransactionEditor.php @@ -7,6 +7,7 @@ private $changedPriorToCommitURI; private $isCloseByCommit; private $repositoryPHIDOverride = false; + private $expandedDone = false; public function getEditorApplicationClass() { return 'PhabricatorDifferentialApplication'; @@ -99,6 +100,7 @@ case PhabricatorTransactions::TYPE_EDIT_POLICY: case DifferentialTransaction::TYPE_ACTION: case DifferentialTransaction::TYPE_UPDATE: + case DifferentialTransaction::TYPE_INLINEDONE: return $xaction->getNewValue(); case DifferentialTransaction::TYPE_INLINE: return null; @@ -197,6 +199,7 @@ case PhabricatorTransactions::TYPE_SUBSCRIBERS: case PhabricatorTransactions::TYPE_COMMENT: case DifferentialTransaction::TYPE_INLINE: + case DifferentialTransaction::TYPE_INLINEDONE: return; case PhabricatorTransactions::TYPE_EDGE: return; @@ -524,6 +527,52 @@ break; } + if (!$this->expandedDone) { + switch ($xaction->getTransactionType()) { + case PhabricatorTransactions::TYPE_COMMENT: + case DifferentialTransaction::TYPE_ACTION: + case DifferentialTransaction::TYPE_UPDATE: + case DifferentialTransaction::TYPE_INLINE: + $this->expandedDone = true; + + $actor_phid = $this->getActingAsPHID(); + $actor_is_author = ($object->getAuthorPHID() == $actor_phid); + if (!$actor_is_author) { + break; + } + + $state_map = array( + PhabricatorInlineCommentInterface::STATE_DRAFT => + PhabricatorInlineCommentInterface::STATE_DONE, + PhabricatorInlineCommentInterface::STATE_UNDRAFT => + PhabricatorInlineCommentInterface::STATE_UNDONE, + ); + + $inlines = id(new DifferentialDiffInlineCommentQuery()) + ->setViewer($this->getActor()) + ->withRevisionPHIDs(array($object->getPHID())) + ->withFixedStates(array_keys($state_map)) + ->execute(); + + if (!$inlines) { + break; + } + + $old_value = mpull($inlines, 'getFixedState', 'getPHID'); + $new_value = array(); + foreach ($old_value as $key => $state) { + $new_value[$key] = $state_map[$state]; + } + + $results[] = id(new DifferentialTransaction()) + ->setTransactionType(DifferentialTransaction::TYPE_INLINEDONE) + ->setIgnoreOnNoEffect(true) + ->setOldValue($old_value) + ->setNewValue($new_value); + break; + } + } + return $results; } @@ -546,6 +595,18 @@ $reply->setHasReplies(1)->save(); } return; + case DifferentialTransaction::TYPE_INLINEDONE: + $table = new DifferentialTransactionComment(); + $conn_w = $table->establishConnection('w'); + foreach ($xaction->getNewValue() as $phid => $state) { + queryfx( + $conn_w, + 'UPDATE %T SET fixedState = %s WHERE phid = %s', + $table->getTableName(), + $state, + $phid); + } + return; case DifferentialTransaction::TYPE_UPDATE: // Now that we're inside the transaction, do a final check. $diff = $this->requireDiff($xaction->getNewValue()); diff --git a/src/applications/differential/storage/DifferentialTransaction.php b/src/applications/differential/storage/DifferentialTransaction.php --- a/src/applications/differential/storage/DifferentialTransaction.php +++ b/src/applications/differential/storage/DifferentialTransaction.php @@ -18,6 +18,7 @@ const TYPE_UPDATE = 'differential:update'; const TYPE_ACTION = 'differential:action'; const TYPE_STATUS = 'differential:status'; + const TYPE_INLINEDONE = 'differential:inlinedone'; public function getApplicationName() { return 'differential'; @@ -35,6 +36,15 @@ return new DifferentialTransactionView(); } + public function shouldGenerateOldValue() { + switch ($this->getTransactionType()) { + case DifferentialTransaction::TYPE_INLINEDONE: + return false; + } + + return parent::shouldGenerateOldValue(); + } + public function shouldHide() { $old = $this->getOldValue(); $new = $this->getNewValue(); @@ -231,6 +241,35 @@ return pht( '%s added inline comments.', $author_handle); + case self::TYPE_INLINEDONE: + $done = 0; + $undone = 0; + foreach ($new as $phid => $state) { + if ($state == PhabricatorInlineCommentInterface::STATE_DONE) { + $done++; + } else { + $undone++; + } + } + if ($done && $undone) { + return pht( + '%s marked %s inline comment(s) as done and %s inline comment(s) '. + 'as not done.', + $author_handle, + new PhutilNumber($done), + new PhutilNumber($undone)); + } else if ($done) { + return pht( + '%s marked %s inline comment(s) as done.', + $author_handle, + new PhutilNumber($done)); + } else { + return pht( + '%s marked %s inline comment(s) as not done.', + $author_handle, + new PhutilNumber($undone)); + } + break; case self::TYPE_UPDATE: if ($this->getMetadataValue('isCommitUpdate')) { return pht( diff --git a/src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php b/src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php --- a/src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php +++ b/src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php @@ -3,13 +3,33 @@ abstract class PhabricatorDiffInlineCommentQuery extends PhabricatorApplicationTransactionCommentQuery { + private $fixedStates; private $needReplyToComments; + public function withFixedStates(array $states) { + $this->fixedStates = $states; + return $this; + } + public function needReplyToComments($need_reply_to) { $this->needReplyToComments = $need_reply_to; return $this; } + protected function buildWhereClauseComponents( + AphrontDatabaseConnection $conn_r) { + $where = parent::buildWhereClauseComponents($conn_r); + + if ($this->fixedStates !== null) { + $where[] = qsprintf( + $conn_r, + 'fixedState IN (%Ls)', + $this->fixedStates); + } + + return $where; + } + protected function willFilterPage(array $comments) { if ($this->needReplyToComments) { $reply_phids = array(); diff --git a/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php b/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php --- a/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php +++ b/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php @@ -967,6 +967,38 @@ 'Show Last %d Lines', ), + '%s marked %s inline comment(s) as done and %s inline comment(s) as '. + 'not done.' => array( + array( + array( + '%s marked an inline comment as done and an inline comment '. + 'as not done.', + '%s marked an inline comment as done and %3$s inline comments '. + 'as not done.', + ), + array( + '%s marked %s inline comments as done and an inline comment '. + 'as not done.', + '%s marked %s inline comments as done and %s inline comments '. + 'as done.', + ), + ), + ), + + '%s marked %s inline comment(s) as done.' => array( + array( + '%s marked an inline comment as done.', + '%s marked %s inline comments as done.', + ), + ), + + '%s marked %s inline comment(s) as not done.' => array( + array( + '%s marked an inline comment as not done.', + '%s marked %s inline comments as not done.', + ), + ), + ); }