From bd95121b33cc68e6963505113df75a1b11eddb68 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 22 Feb 2013 15:54:56 -0800 Subject: [PATCH] Don't try to implicitly subscribe users who are already subscribed Summary: Fixes T2587. Specifically: - Don't try to implicitly subscribe the actor if they're already subscribed. - Since there are like 5 things that need to interact with subscribers, just load them once upfront for Subscribable objects. Test Plan: Made a comment on a mock I was CC'd on without an error. Reviewers: vrana Reviewed By: vrana CC: aran Maniphest Tasks: T2587 Differential Revision: https://secure.phabricator.com/D5091 --- ...habricatorApplicationTransactionEditor.php | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index fa9abaf77d..a27606e5e7 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -16,6 +16,7 @@ abstract class PhabricatorApplicationTransactionEditor private $mentionedPHIDs; private $continueOnNoEffect; private $parentMessageID; + private $subscribers; private $isPreview; @@ -95,13 +96,7 @@ abstract class PhabricatorApplicationTransactionEditor PhabricatorApplicationTransaction $xaction) { switch ($xaction->getTransactionType()) { case PhabricatorTransactions::TYPE_SUBSCRIBERS: - if ($object->getPHID()) { - $old_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID( - $object->getPHID()); - } else { - $old_phids = array(); - } - return array_values($old_phids); + return array_values($this->subscribers); case PhabricatorTransactions::TYPE_VIEW_POLICY: return $object->getViewPolicy(); case PhabricatorTransactions::TYPE_EDIT_POLICY: @@ -222,6 +217,15 @@ abstract class PhabricatorApplicationTransactionEditor $actor = $this->requireActor(); + if ($object->getPHID() && + ($object instanceof PhabricatorSubscribableInterface)) { + $subs = PhabricatorSubscribersQuery::loadSubscribersForPHID( + $object->getPHID()); + $this->subscribers = array_fuse($subs); + } else { + $this->subscribers = array(); + } + $xactions = $this->applyImplicitCC($object, $xactions); $mention_xaction = $this->buildMentionTransaction($object, $xactions); @@ -422,9 +426,7 @@ abstract class PhabricatorApplicationTransactionEditor // Don't try to subscribe already-subscribed mentions: we want to generate // a dialog about an action having no effect if the user explicitly adds // existing CCs, but not if they merely mention existing subscribers. - $current = PhabricatorSubscribersQuery::loadSubscribersForPHID( - $object->getPHID()); - $phids = array_diff($phids, $current); + $phids = array_diff($phids, $this->subscribers); } if (!$phids) { @@ -678,6 +680,11 @@ abstract class PhabricatorApplicationTransactionEditor } if ($object->getPHID()) { + if (isset($this->subscribers[$actor_phid])) { + // If the user is already subscribed, don't implicitly CC them. + return $xactions; + } + $unsub = PhabricatorEdgeQuery::loadDestinationPHIDs( $object->getPHID(), PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER); @@ -840,8 +847,7 @@ abstract class PhabricatorApplicationTransactionEditor */ protected function getMailCC(PhabricatorLiskDAO $object) { if ($object instanceof PhabricatorSubscribableInterface) { - $phid = $object->getPHID(); - return PhabricatorSubscribersQuery::loadSubscribersForPHID($phid); + return $this->subscribers; } throw new Exception("Capability not supported."); }