1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

Prepare revision mail for the "Draft" status

Summary:
Ref T2543. Currently, we always do some special things when a revision is created, mostly adding more stuff to the mail.

With drafts, we want to suppress initial mail and send this big, rich mail only when the revision actually moves out of "draft".

Prepare the code for this, with the actual methods hard-coded to the current behavior. This will probably take some tweaking but I think I got most of it.

Test Plan: Banged around in Differential so it sent some mail, saw normal mail without anything new.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T2543

Differential Revision: https://secure.phabricator.com/D18627
This commit is contained in:
epriestley 2017-09-18 14:40:36 -07:00
parent c7af663523
commit fca553f142
5 changed files with 64 additions and 19 deletions

View file

@ -24,7 +24,7 @@ final class DifferentialChangesSinceLastUpdateField
PhabricatorApplicationTransactionEditor $editor, PhabricatorApplicationTransactionEditor $editor,
array $xactions) { array $xactions) {
if ($editor->getIsNewObject()) { if ($editor->isFirstBroadcast()) {
return; return;
} }

View file

@ -67,7 +67,7 @@ final class DifferentialSummaryField
PhabricatorApplicationTransactionEditor $editor, PhabricatorApplicationTransactionEditor $editor,
array $xactions) { array $xactions) {
if (!$editor->getIsNewObject()) { if (!$editor->isFirstBroadcast()) {
return; return;
} }

View file

@ -71,7 +71,7 @@ final class DifferentialTestPlanField
PhabricatorApplicationTransactionEditor $editor, PhabricatorApplicationTransactionEditor $editor,
array $xactions) { array $xactions) {
if (!$editor->getIsNewObject()) { if (!$editor->isFirstBroadcast()) {
return; return;
} }

View file

@ -26,6 +26,10 @@ final class DifferentialTransactionEditor
return pht('%s created %s.', $author, $object); return pht('%s created %s.', $author, $object);
} }
public function isFirstBroadcast() {
return $this->getIsNewObject();
}
public function getDiffUpdateTransaction(array $xactions) { public function getDiffUpdateTransaction(array $xactions) {
$type_update = DifferentialTransaction::TYPE_UPDATE; $type_update = DifferentialTransaction::TYPE_UPDATE;
@ -600,24 +604,25 @@ final class DifferentialTransactionEditor
return array_values(array_merge($head, $tail)); return array_values(array_merge($head, $tail));
} }
protected function requireCapabilities(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {}
return parent::requireCapabilities($object, $xaction);
}
protected function shouldPublishFeedStory( protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {
if (!$object->shouldBroadcast()) {
return false;
}
return true; return true;
} }
protected function shouldSendMail( protected function shouldSendMail(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {
if (!$object->shouldBroadcast()) {
return false;
}
return true; return true;
} }
@ -633,14 +638,25 @@ final class DifferentialTransactionEditor
protected function getMailAction( protected function getMailAction(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {
$action = parent::getMailAction($object, $xactions);
$strongest = $this->getStrongestAction($object, $xactions); $show_lines = false;
switch ($strongest->getTransactionType()) { if ($this->isFirstBroadcast()) {
case DifferentialTransaction::TYPE_UPDATE: $action = pht('Request');
$count = new PhutilNumber($object->getLineCount());
$action = pht('%s, %s line(s)', $action, $count); $show_lines = true;
break; } else {
$action = parent::getMailAction($object, $xactions);
$strongest = $this->getStrongestAction($object, $xactions);
$type_update = DifferentialTransaction::TYPE_UPDATE;
if ($strongest->getTransactionType() == $type_update) {
$show_lines = true;
}
}
if ($show_lines) {
$count = new PhutilNumber($object->getLineCount());
$action = pht('%s, %s line(s)', $action, $count);
} }
return $action; return $action;
@ -679,6 +695,16 @@ final class DifferentialTransactionEditor
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {
$viewer = $this->requireActor();
// If this is the first time we're sending mail about this revision, we
// generate mail for all prior transactions, not just whatever is being
// applied now. This gets the "added reviewers" lines and other relevant
// information into the mail.
if ($this->isFirstBroadcast()) {
$xactions = $this->loadUnbroadcastTransactions($object);
}
$body = new PhabricatorMetaMTAMailBody(); $body = new PhabricatorMetaMTAMailBody();
$body->setViewer($this->requireActor()); $body->setViewer($this->requireActor());
@ -1491,4 +1517,15 @@ final class DifferentialTransactionEditor
$acting_phid); $acting_phid);
} }
private function loadUnbroadcastTransactions($object) {
$viewer = $this->requireActor();
$xactions = id(new DifferentialTransactionQuery())
->setViewer($viewer)
->withObjectPHIDs(array($object->getPHID()))
->execute();
return array_reverse($xactions);
}
} }

View file

@ -694,6 +694,14 @@ final class DifferentialRevision extends DifferentialDAO
return $this; return $this;
} }
public function shouldBroadcast() {
if (!$this->isDraft()) {
return true;
}
return false;
}
/* -( HarbormasterBuildableInterface )------------------------------------- */ /* -( HarbormasterBuildableInterface )------------------------------------- */