mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Share more inline "Done" code between Differential and Diffusion
Summary: Ref T13222. See PHI995. Before making a change to inline rendering, consolidate this code for generating the "alice added inlines comments." and "alice marked X inlines as done." transactions. Both Differential and Diffusion have four very similar chunks of code. Merge them into shared methods and reduce code duplication across the methods. (In the next change, I plan to hide the "done" story when the mark affects your own inline, since users marking their own inlines as "done" is generally not very interesting or useful.) Test Plan: As author and reviewer/auditor, added inlines in Differential and Diffusion. As author, marked own and others inlines as done and undone. Got sensible transaction rendering and persistence of "Done". Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13222 Differential Revision: https://secure.phabricator.com/D19858
This commit is contained in:
parent
68b1dee139
commit
46feccdfcf
5 changed files with 103 additions and 135 deletions
|
@ -251,47 +251,16 @@ final class PhabricatorAuditEditor
|
|||
case PhabricatorTransactions::TYPE_COMMENT:
|
||||
$this->didExpandInlineState = true;
|
||||
|
||||
$actor_phid = $this->getActingAsPHID();
|
||||
$author_phid = $object->getAuthorPHID();
|
||||
$actor_is_author = ($actor_phid == $author_phid);
|
||||
$query_template = id(new DiffusionDiffInlineCommentQuery())
|
||||
->withCommitPHIDs(array($object->getPHID()));
|
||||
|
||||
$state_map = PhabricatorTransactions::getInlineStateMap();
|
||||
$state_xaction = $this->newInlineStateTransaction(
|
||||
$object,
|
||||
$query_template);
|
||||
|
||||
$query = id(new DiffusionDiffInlineCommentQuery())
|
||||
->setViewer($this->getActor())
|
||||
->withCommitPHIDs(array($object->getPHID()))
|
||||
->withFixedStates(array_keys($state_map));
|
||||
|
||||
$inlines = array();
|
||||
|
||||
$inlines[] = id(clone $query)
|
||||
->withAuthorPHIDs(array($actor_phid))
|
||||
->withHasTransaction(false)
|
||||
->execute();
|
||||
|
||||
if ($actor_is_author) {
|
||||
$inlines[] = id(clone $query)
|
||||
->withHasTransaction(true)
|
||||
->execute();
|
||||
if ($state_xaction) {
|
||||
$xactions[] = $state_xaction;
|
||||
}
|
||||
|
||||
$inlines = array_mergev($inlines);
|
||||
|
||||
if (!$inlines) {
|
||||
break;
|
||||
}
|
||||
|
||||
$old_value = mpull($inlines, 'getFixedState', 'getPHID');
|
||||
$new_value = array();
|
||||
foreach ($old_value as $key => $state) {
|
||||
$new_value[$key] = $state_map[$state];
|
||||
}
|
||||
|
||||
$xactions[] = id(new PhabricatorAuditTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_INLINESTATE)
|
||||
->setIgnoreOnNoEffect(true)
|
||||
->setOldValue($old_value)
|
||||
->setNewValue($new_value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -279,36 +279,17 @@ final class DifferentialRevisionEditEngine
|
|||
$object);
|
||||
$inlines = msort($inlines, 'getID');
|
||||
|
||||
foreach ($inlines as $inline) {
|
||||
$xactions[] = id(new DifferentialTransaction())
|
||||
->setTransactionType(DifferentialTransaction::TYPE_INLINE)
|
||||
->attachComment($inline);
|
||||
}
|
||||
$editor = $object->getApplicationTransactionEditor()
|
||||
->setActor($viewer);
|
||||
|
||||
$viewer_phid = $viewer->getPHID();
|
||||
$viewer_is_author = ($object->getAuthorPHID() == $viewer_phid);
|
||||
if ($viewer_is_author) {
|
||||
$state_map = PhabricatorTransactions::getInlineStateMap();
|
||||
$query_template = id(new DifferentialDiffInlineCommentQuery())
|
||||
->withRevisionPHIDs(array($object->getPHID()));
|
||||
|
||||
$inlines = id(new DifferentialDiffInlineCommentQuery())
|
||||
->setViewer($viewer)
|
||||
->withRevisionPHIDs(array($object->getPHID()))
|
||||
->withFixedStates(array_keys($state_map))
|
||||
->execute();
|
||||
if ($inlines) {
|
||||
$old_value = mpull($inlines, 'getFixedState', 'getPHID');
|
||||
$new_value = array();
|
||||
foreach ($old_value as $key => $state) {
|
||||
$new_value[$key] = $state_map[$state];
|
||||
}
|
||||
|
||||
$xactions[] = id(new DifferentialTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_INLINESTATE)
|
||||
->setIgnoreOnNoEffect(true)
|
||||
->setOldValue($old_value)
|
||||
->setNewValue($new_value);
|
||||
}
|
||||
}
|
||||
$xactions = $editor->newAutomaticInlineTransactions(
|
||||
$object,
|
||||
$inlines,
|
||||
DifferentialTransaction::TYPE_INLINE,
|
||||
$query_template);
|
||||
|
||||
return $xactions;
|
||||
}
|
||||
|
|
|
@ -247,50 +247,16 @@ final class DifferentialTransactionEditor
|
|||
case DifferentialTransaction::TYPE_INLINE:
|
||||
$this->didExpandInlineState = true;
|
||||
|
||||
$actor_phid = $this->getActingAsPHID();
|
||||
$author_phid = $object->getAuthorPHID();
|
||||
$actor_is_author = ($actor_phid == $author_phid);
|
||||
$query_template = id(new DifferentialDiffInlineCommentQuery())
|
||||
->withRevisionPHIDs(array($object->getPHID()));
|
||||
|
||||
$state_map = PhabricatorTransactions::getInlineStateMap();
|
||||
$state_xaction = $this->newInlineStateTransaction(
|
||||
$object,
|
||||
$query_template);
|
||||
|
||||
$query = id(new DifferentialDiffInlineCommentQuery())
|
||||
->setViewer($this->getActor())
|
||||
->withRevisionPHIDs(array($object->getPHID()))
|
||||
->withFixedStates(array_keys($state_map));
|
||||
|
||||
$inlines = array();
|
||||
|
||||
// We're going to undraft any "done" marks on your own inlines.
|
||||
$inlines[] = id(clone $query)
|
||||
->withAuthorPHIDs(array($actor_phid))
|
||||
->withHasTransaction(false)
|
||||
->execute();
|
||||
|
||||
// If you're the author, we also undraft any "done" marks on other
|
||||
// inlines.
|
||||
if ($actor_is_author) {
|
||||
$inlines[] = id(clone $query)
|
||||
->withHasTransaction(true)
|
||||
->execute();
|
||||
if ($state_xaction) {
|
||||
$results[] = $state_xaction;
|
||||
}
|
||||
|
||||
$inlines = array_mergev($inlines);
|
||||
|
||||
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(PhabricatorTransactions::TYPE_INLINESTATE)
|
||||
->setIgnoreOnNoEffect(true)
|
||||
->setOldValue($old_value)
|
||||
->setNewValue($new_value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,36 +170,17 @@ final class DiffusionCommitEditEngine
|
|||
$raw = true);
|
||||
$inlines = msort($inlines, 'getID');
|
||||
|
||||
foreach ($inlines as $inline) {
|
||||
$xactions[] = $object->getApplicationTransactionTemplate()
|
||||
->setTransactionType(PhabricatorAuditActionConstants::INLINE)
|
||||
->attachComment($inline);
|
||||
}
|
||||
$editor = $object->getApplicationTransactionEditor()
|
||||
->setActor($viewer);
|
||||
|
||||
$viewer_phid = $viewer->getPHID();
|
||||
$viewer_is_author = ($object->getAuthorPHID() == $viewer_phid);
|
||||
if ($viewer_is_author) {
|
||||
$state_map = PhabricatorTransactions::getInlineStateMap();
|
||||
$query_template = id(new DiffusionDiffInlineCommentQuery())
|
||||
->withCommitPHIDs(array($object->getPHID()));
|
||||
|
||||
$inlines = id(new DiffusionDiffInlineCommentQuery())
|
||||
->setViewer($viewer)
|
||||
->withCommitPHIDs(array($object->getPHID()))
|
||||
->withFixedStates(array_keys($state_map))
|
||||
->execute();
|
||||
if ($inlines) {
|
||||
$old_value = mpull($inlines, 'getFixedState', 'getPHID');
|
||||
$new_value = array();
|
||||
foreach ($old_value as $key => $state) {
|
||||
$new_value[$key] = $state_map[$state];
|
||||
}
|
||||
|
||||
$xactions[] = $object->getApplicationTransactionTemplate()
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_INLINESTATE)
|
||||
->setIgnoreOnNoEffect(true)
|
||||
->setOldValue($old_value)
|
||||
->setNewValue($new_value);
|
||||
}
|
||||
}
|
||||
$xactions = $editor->newAutomaticInlineTransactions(
|
||||
$object,
|
||||
$inlines,
|
||||
PhabricatorAuditActionConstants::INLINE,
|
||||
$query_template);
|
||||
|
||||
return $xactions;
|
||||
}
|
||||
|
|
|
@ -4594,4 +4594,75 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
return $mail;
|
||||
}
|
||||
|
||||
public function newAutomaticInlineTransactions(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $inlines,
|
||||
$transaction_type,
|
||||
PhabricatorCursorPagedPolicyAwareQuery $query_template) {
|
||||
|
||||
$xactions = array();
|
||||
|
||||
foreach ($inlines as $inline) {
|
||||
$xactions[] = $object->getApplicationTransactionTemplate()
|
||||
->setTransactionType($transaction_type)
|
||||
->attachComment($inline);
|
||||
}
|
||||
|
||||
$state_xaction = $this->newInlineStateTransaction(
|
||||
$object,
|
||||
$query_template);
|
||||
|
||||
if ($state_xaction) {
|
||||
$xactions[] = $state_xaction;
|
||||
}
|
||||
|
||||
return $xactions;
|
||||
}
|
||||
|
||||
protected function newInlineStateTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorCursorPagedPolicyAwareQuery $query_template) {
|
||||
|
||||
$actor_phid = $this->getActingAsPHID();
|
||||
$author_phid = $object->getAuthorPHID();
|
||||
$actor_is_author = ($actor_phid == $author_phid);
|
||||
|
||||
$state_map = PhabricatorTransactions::getInlineStateMap();
|
||||
|
||||
$query = id(clone $query_template)
|
||||
->setViewer($this->getActor())
|
||||
->withFixedStates(array_keys($state_map));
|
||||
|
||||
$inlines = array();
|
||||
|
||||
$inlines[] = id(clone $query)
|
||||
->withAuthorPHIDs(array($actor_phid))
|
||||
->withHasTransaction(false)
|
||||
->execute();
|
||||
|
||||
if ($actor_is_author) {
|
||||
$inlines[] = id(clone $query)
|
||||
->withHasTransaction(true)
|
||||
->execute();
|
||||
}
|
||||
|
||||
$inlines = array_mergev($inlines);
|
||||
|
||||
if (!$inlines) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$old_value = mpull($inlines, 'getFixedState', 'getPHID');
|
||||
$new_value = array();
|
||||
foreach ($old_value as $key => $state) {
|
||||
$new_value[$key] = $state_map[$state];
|
||||
}
|
||||
|
||||
return $object->getApplicationTransactionTemplate()
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_INLINESTATE)
|
||||
->setIgnoreOnNoEffect(true)
|
||||
->setOldValue($old_value)
|
||||
->setNewValue($new_value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue