3 final class PhabricatorSubscriptionsEditor
extends PhabricatorEditor
{
7 private $explicitSubscribePHIDs = array();
8 private $implicitSubscribePHIDs = array();
9 private $unsubscribePHIDs = array();
11 public function setObject(PhabricatorSubscribableInterface
$object) {
12 $this->object = $object;
17 * Add explicit subscribers. These subscribers have explicitly subscribed
18 * (or been subscribed) to the object, and will be added even if they
19 * had previously unsubscribed.
21 * @param list<phid> List of PHIDs to explicitly subscribe.
24 public function subscribeExplicit(array $phids) {
25 $this->explicitSubscribePHIDs +
= array_fill_keys($phids, true);
31 * Add implicit subscribers. These subscribers have taken some action which
32 * implicitly subscribes them (e.g., adding a comment) but it will be
33 * suppressed if they've previously unsubscribed from the object.
35 * @param list<phid> List of PHIDs to implicitly subscribe.
38 public function subscribeImplicit(array $phids) {
39 $this->implicitSubscribePHIDs +
= array_fill_keys($phids, true);
45 * Unsubscribe PHIDs and mark them as unsubscribed, so implicit subscriptions
46 * will not resubscribe them.
48 * @param list<phid> List of PHIDs to unsubscribe.
51 public function unsubscribe(array $phids) {
52 $this->unsubscribePHIDs +
= array_fill_keys($phids, true);
57 public function save() {
59 throw new PhutilInvalidStateException('setObject');
61 $actor = $this->requireActor();
63 $src = $this->object->getPHID();
65 if ($this->implicitSubscribePHIDs
) {
66 $unsub = PhabricatorEdgeQuery
::loadDestinationPHIDs(
68 PhabricatorObjectHasUnsubscriberEdgeType
::EDGECONST
);
69 $unsub = array_fill_keys($unsub, true);
70 $this->implicitSubscribePHIDs
= array_diff_key(
71 $this->implicitSubscribePHIDs
,
75 $add = $this->implicitSubscribePHIDs +
$this->explicitSubscribePHIDs
;
76 $del = $this->unsubscribePHIDs
;
78 // If a PHID is marked for both subscription and unsubscription, treat
79 // unsubscription as the stronger action.
80 $add = array_diff_key($add, $del);
83 $u_type = PhabricatorObjectHasUnsubscriberEdgeType
::EDGECONST
;
84 $s_type = PhabricatorObjectHasSubscriberEdgeType
::EDGECONST
;
86 $editor = new PhabricatorEdgeEditor();
88 foreach ($add as $phid => $ignored) {
89 $editor->removeEdge($src, $u_type, $phid);
90 $editor->addEdge($src, $s_type, $phid);
93 foreach ($del as $phid => $ignored) {
94 $editor->removeEdge($src, $s_type, $phid);
95 $editor->addEdge($src, $u_type, $phid);