mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add implicit CC rules to ApplicationTransactions
Summary: When you make a comment on an object (or take certain other actions), we want to automatically CC you. Build this into ApplicationTransactions since it's a common behavior shared across multiple apps. Fixes T2215. Test Plan: Made a comment on a macro, got cc'd. Reviewers: chad Reviewed By: chad CC: aran Maniphest Tasks: T2215 Differential Revision: https://secure.phabricator.com/D5019
This commit is contained in:
parent
db2c32acdf
commit
fb90d5ffed
1 changed files with 69 additions and 1 deletions
|
@ -220,9 +220,10 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
|
|
||||||
$this->validateEditParameters($object, $xactions);
|
$this->validateEditParameters($object, $xactions);
|
||||||
|
|
||||||
|
|
||||||
$actor = $this->requireActor();
|
$actor = $this->requireActor();
|
||||||
|
|
||||||
|
$xactions = $this->applyImplicitCC($object, $xactions);
|
||||||
|
|
||||||
$mention_xaction = $this->buildMentionTransaction($object, $xactions);
|
$mention_xaction = $this->buildMentionTransaction($object, $xactions);
|
||||||
if ($mention_xaction) {
|
if ($mention_xaction) {
|
||||||
$xactions[] = $mention_xaction;
|
$xactions[] = $mention_xaction;
|
||||||
|
@ -642,6 +643,73 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -( Implicit CCs )------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When a user interacts with an object, we might want to add them to CC.
|
||||||
|
*/
|
||||||
|
final public function applyImplicitCC(
|
||||||
|
PhabricatorLiskDAO $object,
|
||||||
|
array $xactions) {
|
||||||
|
|
||||||
|
if (!($object instanceof PhabricatorSubscribableInterface)) {
|
||||||
|
// If the object isn't subscribable, we can't CC them.
|
||||||
|
return $xactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
$actor_phid = $this->requireActor()->getPHID();
|
||||||
|
if ($object->isAutomaticallySubscribed($actor_phid)) {
|
||||||
|
// If they're auto-subscribed, don't CC them.
|
||||||
|
return $xactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
$should_cc = false;
|
||||||
|
foreach ($xactions as $xaction) {
|
||||||
|
if ($this->shouldImplyCC($object, $xaction)) {
|
||||||
|
$should_cc = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$should_cc) {
|
||||||
|
// Only some types of actions imply a CC (like adding a comment).
|
||||||
|
return $xactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($object->getPHID()) {
|
||||||
|
$unsub = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||||
|
$object->getPHID(),
|
||||||
|
PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER);
|
||||||
|
$unsub = array_fuse($unsub);
|
||||||
|
if (isset($unsub[$actor_phid])) {
|
||||||
|
// If the user has previously unsubscribed from this object explicitly,
|
||||||
|
// don't implicitly CC them.
|
||||||
|
return $xactions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$xaction = newv(get_class(head($xactions)), array());
|
||||||
|
$xaction->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS);
|
||||||
|
$xaction->setNewValue(array('+' => array($actor_phid)));
|
||||||
|
|
||||||
|
array_unshift($xactions, $xaction);
|
||||||
|
|
||||||
|
return $xactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function shouldImplyCC(
|
||||||
|
PhabricatorLiskDAO $object,
|
||||||
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
|
||||||
|
switch ($xaction->getTransactionType()) {
|
||||||
|
case PhabricatorTransactions::TYPE_COMMENT:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Sending Mail )------------------------------------------------------- */
|
/* -( Sending Mail )------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue