@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorSubscriptionsMuteController
4 extends PhabricatorController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8 $phid = $request->getURIData('phid');
9
10 $handle = id(new PhabricatorHandleQuery())
11 ->setViewer($viewer)
12 ->withPHIDs(array($phid))
13 ->executeOne();
14
15 $object = id(new PhabricatorObjectQuery())
16 ->setViewer($viewer)
17 ->withPHIDs(array($phid))
18 ->executeOne();
19
20 if (!($object instanceof PhabricatorSubscribableInterface)) {
21 return new Aphront400Response();
22 }
23
24 $muted_type = PhabricatorMutedByEdgeType::EDGECONST;
25
26 $edge_query = id(new PhabricatorEdgeQuery())
27 ->withSourcePHIDs(array($object->getPHID()))
28 ->withEdgeTypes(array($muted_type))
29 ->withDestinationPHIDs(array($viewer->getPHID()));
30
31 $edge_query->execute();
32
33 $is_mute = !$edge_query->getDestinationPHIDs();
34 $object_uri = $handle->getURI();
35
36 if ($request->isFormPost()) {
37 if ($is_mute) {
38 $xaction_value = array(
39 '+' => array_fuse(array($viewer->getPHID())),
40 );
41 } else {
42 $xaction_value = array(
43 '-' => array_fuse(array($viewer->getPHID())),
44 );
45 }
46
47 $xaction = id($object->getApplicationTransactionTemplate())
48 ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
49 ->setMetadataValue('edge:type', $muted_type)
50 ->setNewValue($xaction_value);
51
52 $editor = id($object->getApplicationTransactionEditor())
53 ->setActor($viewer)
54 ->setContinueOnNoEffect(true)
55 ->setContinueOnMissingFields(true)
56 ->setContentSourceFromRequest($request);
57
58 $editor->applyTransactions($object, array($xaction));
59
60 return id(new AphrontReloadResponse())->setURI($object_uri);
61 }
62
63 $dialog = $this->newDialog()
64 ->addCancelButton($object_uri);
65
66 if ($is_mute) {
67 $dialog
68 ->setTitle(pht('Mute Notifications'))
69 ->appendParagraph(
70 pht(
71 'Mute this object? You will no longer receive notifications or '.
72 'email about it.'))
73 ->addSubmitButton(pht('Mute'));
74 } else {
75 $dialog
76 ->setTitle(pht('Unmute Notifications'))
77 ->appendParagraph(
78 pht(
79 'Unmute this object? You will receive notifications and email '.
80 'again.'))
81 ->addSubmitButton(pht('Unmute'));
82 }
83
84 return $dialog;
85 }
86
87
88}