Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / settings / panel / PhabricatorNotificationsSettingsPanel.php
blobae5679d9ddc4b1662409043b6e7da1887873ba12
1 <?php
3 final class PhabricatorNotificationsSettingsPanel
4 extends PhabricatorSettingsPanel {
6 public function isEnabled() {
7 $servers = PhabricatorNotificationServerRef::getEnabledAdminServers();
8 if (!$servers) {
9 return false;
12 return PhabricatorApplication::isClassInstalled(
13 'PhabricatorNotificationsApplication');
16 public function getPanelKey() {
17 return 'notifications';
20 public function getPanelName() {
21 return pht('Notifications');
24 public function getPanelMenuIcon() {
25 return 'fa-bell-o';
28 public function getPanelGroupKey() {
29 return PhabricatorSettingsApplicationsPanelGroup::PANELGROUPKEY;
32 public function processRequest(AphrontRequest $request) {
33 $viewer = $this->getViewer();
34 $preferences = $this->getPreferences();
36 $notifications_key = PhabricatorNotificationsSetting::SETTINGKEY;
37 $notifications_value = $preferences->getSettingValue($notifications_key);
39 if ($request->isFormPost()) {
41 $this->writeSetting(
42 $preferences,
43 $notifications_key,
44 $request->getInt($notifications_key));
46 return id(new AphrontRedirectResponse())
47 ->setURI($this->getPanelURI('?saved=true'));
50 $title = pht('Notifications');
51 $control_id = celerity_generate_unique_node_id();
52 $status_id = celerity_generate_unique_node_id();
53 $browser_status_id = celerity_generate_unique_node_id();
54 $cancel_ask = pht(
55 'The dialog asking for permission to send desktop notifications was '.
56 'closed without granting permission. Only application notifications '.
57 'will be sent.');
58 $accept_ask = pht(
59 'Click "Save Preference" to persist these changes.');
60 $reject_ask = pht(
61 'Permission for desktop notifications was denied. Only application '.
62 'notifications will be sent.');
63 $no_support = pht(
64 'This web browser does not support desktop notifications. Only '.
65 'application notifications will be sent for this browser regardless of '.
66 'this preference.');
67 $default_status = phutil_tag(
68 'span',
69 array(),
70 array(
71 pht(
72 'Your browser has not yet granted this server permission to send '.
73 'desktop notifications.'),
74 phutil_tag('br'),
75 phutil_tag('br'),
76 javelin_tag(
77 'button',
78 array(
79 'sigil' => 'desktop-notifications-permission-button',
80 'class' => 'green',
82 pht('Grant Permission')),
83 ));
84 $granted_status = phutil_tag(
85 'span',
86 array(),
87 pht('Your browser has granted this server permission to send desktop '.
88 'notifications.'));
89 $denied_status = phutil_tag(
90 'span',
91 array(),
92 pht('This browser has denied permission to send desktop notifications '.
93 'to this server. Consult your browser settings / '.
94 'documentation to figure out how to clear this setting, do so, '.
95 'and then re-visit this page to grant permission.'));
97 $message_id = celerity_generate_unique_node_id();
99 $message_container = phutil_tag(
100 'span',
101 array(
102 'id' => $message_id,
105 $saved_box = null;
106 if ($request->getBool('saved')) {
107 $saved_box = id(new PHUIInfoView())
108 ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
109 ->appendChild(pht('Changes saved.'));
112 $status_box = id(new PHUIInfoView())
113 ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
114 ->setID($status_id)
115 ->setIsHidden(true)
116 ->appendChild($message_container);
118 $status_box = id(new PHUIBoxView())
119 ->addClass('mll mlr')
120 ->appendChild($status_box);
122 $control_config = array(
123 'controlID' => $control_id,
124 'statusID' => $status_id,
125 'messageID' => $message_id,
126 'browserStatusID' => $browser_status_id,
127 'defaultMode' => 0,
128 'desktop' => 1,
129 'desktopOnly' => 2,
130 'cancelAsk' => $cancel_ask,
131 'grantedAsk' => $accept_ask,
132 'deniedAsk' => $reject_ask,
133 'defaultStatus' => $default_status,
134 'deniedStatus' => $denied_status,
135 'grantedStatus' => $granted_status,
136 'noSupport' => $no_support,
139 $form = id(new AphrontFormView())
140 ->setUser($viewer)
141 ->appendChild(
142 id(new AphrontFormSelectControl())
143 ->setLabel($title)
144 ->setControlID($control_id)
145 ->setName($notifications_key)
146 ->setValue($notifications_value)
147 ->setOptions(PhabricatorNotificationsSetting::getOptionsMap())
148 ->setCaption(
149 pht(
150 'This server can send real-time notifications to your web browser '.
151 'or to your desktop. Select where you want to receive these '.
152 'real-time updates.'))
153 ->initBehavior(
154 'desktop-notifications-control',
155 $control_config))
156 ->appendChild(
157 id(new AphrontFormSubmitControl())
158 ->setValue(pht('Save Preference')));
160 $button = id(new PHUIButtonView())
161 ->setTag('a')
162 ->setIcon('fa-send-o')
163 ->setWorkflow(true)
164 ->setText(pht('Send Test Notification'))
165 ->setHref('/notification/test/')
166 ->setColor(PHUIButtonView::GREY);
168 $form_content = array($saved_box, $status_box, $form);
169 $form_box = $this->newBox(
170 pht('Notifications'), $form_content, array($button));
172 $browser_status_box = id(new PHUIInfoView())
173 ->setID($browser_status_id)
174 ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
175 ->setIsHidden(true)
176 ->appendChild($default_status);
178 return array(
179 $form_box,
180 $browser_status_box,