Skip to content

Commit 6969e93

Browse files
author
Chad Little
committed
Move room preferences into own controller
Summary: Ref T12591. These preferences are per user and we need to reload the whole UI on a change anyways. Simplifies future expansion. Test Plan: Option click into new window, set preferences. View in Conpherence, see saved settings, change sound. Hear new sound. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T12591 Differential Revision: https://secure.phabricator.com/D17740
1 parent d2560b2 commit 6969e93

File tree

7 files changed

+118
-115
lines changed

7 files changed

+118
-115
lines changed

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@
310310
'ConpherenceReplyHandler' => 'applications/conpherence/mail/ConpherenceReplyHandler.php',
311311
'ConpherenceRoomListController' => 'applications/conpherence/controller/ConpherenceRoomListController.php',
312312
'ConpherenceRoomPictureController' => 'applications/conpherence/controller/ConpherenceRoomPictureController.php',
313+
'ConpherenceRoomPreferencesController' => 'applications/conpherence/controller/ConpherenceRoomPreferencesController.php',
313314
'ConpherenceRoomSettings' => 'applications/conpherence/constants/ConpherenceRoomSettings.php',
314315
'ConpherenceRoomTestCase' => 'applications/conpherence/__tests__/ConpherenceRoomTestCase.php',
315316
'ConpherenceSchemaSpec' => 'applications/conpherence/storage/ConpherenceSchemaSpec.php',
@@ -5108,6 +5109,7 @@
51085109
'ConpherenceReplyHandler' => 'PhabricatorMailReplyHandler',
51095110
'ConpherenceRoomListController' => 'ConpherenceController',
51105111
'ConpherenceRoomPictureController' => 'ConpherenceController',
5112+
'ConpherenceRoomPreferencesController' => 'ConpherenceController',
51115113
'ConpherenceRoomSettings' => 'ConpherenceConstants',
51125114
'ConpherenceRoomTestCase' => 'ConpherenceTestCase',
51135115
'ConpherenceSchemaSpec' => 'PhabricatorConfigSchemaSpec',

src/applications/conpherence/application/PhabricatorConpherenceApplication.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function getRoutes() {
5555
=> 'ConpherenceNotificationPanelController',
5656
'participant/(?P<id>[1-9]\d*)/'
5757
=> 'ConpherenceParticipantController',
58+
'preferences/(?P<id>[1-9]\d*)/'
59+
=> 'ConpherenceRoomPreferencesController',
5860
'update/(?P<id>[1-9]\d*)/'
5961
=> 'ConpherenceUpdateController',
6062
),

src/applications/conpherence/constants/ConpherenceUpdateActions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ final class ConpherenceUpdateActions extends ConpherenceConstants {
88
const JOIN_ROOM = 'join_room';
99
const ADD_PERSON = 'add_person';
1010
const REMOVE_PERSON = 'remove_person';
11-
const NOTIFICATIONS = 'notifications';
1211
const ADD_STATUS = 'add_status';
1312
const LOAD = 'load';
1413
}

src/applications/conpherence/controller/ConpherenceController.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ protected function buildHeaderPaneContent(
5757
ConpherenceThread $conpherence) {
5858
$viewer = $this->getViewer();
5959
$header = null;
60+
$id = $conpherence->getID();
6061

61-
if ($conpherence->getID()) {
62+
if ($id) {
6263
$data = $conpherence->getDisplayData($this->getViewer());
6364

6465
$header = id(new PHUIHeaderView())
@@ -83,25 +84,22 @@ protected function buildHeaderPaneContent(
8384

8485
if ($can_edit) {
8586
$header->setImageURL(
86-
$this->getApplicationURI('picture/'.$conpherence->getID().'/'));
87+
$this->getApplicationURI("picture/{$id}/"));
8788
}
8889

8990
$participating = $conpherence->getParticipantIfExists($viewer->getPHID());
9091

9192
$header->addActionItem(
9293
id(new PHUIIconCircleView())
93-
->setHref(
94-
$this->getApplicationURI('update/'.$conpherence->getID()).'/')
94+
->setHref($this->getApplicationURI("update/{$id}/"))
9595
->setIcon('fa-pencil')
9696
->addClass('hide-on-device')
9797
->setColor('violet')
9898
->setWorkflow(true));
9999

100100
$header->addActionItem(
101101
id(new PHUIIconCircleView())
102-
->setHref(
103-
$this->getApplicationURI('update/'.$conpherence->getID()).'/'.
104-
'?action='.ConpherenceUpdateActions::NOTIFICATIONS)
102+
->setHref($this->getApplicationURI("preferences/{$id}/"))
105103
->setIcon('fa-gear')
106104
->addClass('hide-on-device')
107105
->setColor('pink')
@@ -136,7 +134,7 @@ protected function buildHeaderPaneContent(
136134

137135
if (!$participating) {
138136
$action = ConpherenceUpdateActions::JOIN_ROOM;
139-
$uri = $this->getApplicationURI('update/'.$conpherence->getID().'/');
137+
$uri = $this->getApplicationURI("update/{$id}/");
140138
$button = phutil_tag(
141139
'button',
142140
array(
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
final class ConpherenceRoomPreferencesController
4+
extends ConpherenceController {
5+
6+
public function shouldAllowPublic() {
7+
return true;
8+
}
9+
10+
public function handleRequest(AphrontRequest $request) {
11+
$viewer = $request->getViewer();
12+
$conpherence_id = $request->getURIData('id');
13+
14+
$conpherence = id(new ConpherenceThreadQuery())
15+
->setViewer($viewer)
16+
->withIDs(array($conpherence_id))
17+
->executeOne();
18+
if (!$conpherence) {
19+
return new Aphront404Response();
20+
}
21+
22+
$view_uri = $conpherence->getURI();
23+
24+
$participant = $conpherence->getParticipantIfExists($viewer->getPHID());
25+
if (!$participant) {
26+
if ($viewer->isLoggedIn()) {
27+
$text = pht(
28+
'Notification settings are available after joining the room.');
29+
} else {
30+
$text = pht(
31+
'Notification settings are available after logging in and joining '.
32+
'the room.');
33+
}
34+
return $this->newDialog()
35+
->setTitle(pht('Room Preferences'))
36+
->addCancelButton($view_uri)
37+
->appendParagraph($text);
38+
}
39+
40+
// Save the data and redirect
41+
if ($request->isFormPost()) {
42+
$notifications = $request->getStr('notifications');
43+
$sounds = $request->getArr('sounds');
44+
45+
$participant->setSettings(array(
46+
'notifications' => $notifications,
47+
'sounds' => $sounds,
48+
));
49+
$participant->save();
50+
51+
return id(new AphrontRedirectResponse())
52+
->setURI($view_uri);
53+
}
54+
55+
$notification_key = PhabricatorConpherenceNotificationsSetting::SETTINGKEY;
56+
$notification_default = $viewer->getUserSetting($notification_key);
57+
58+
$sound_key = PhabricatorConpherenceSoundSetting::SETTINGKEY;
59+
$sound_default = $viewer->getUserSetting($sound_key);
60+
61+
$settings = $participant->getSettings();
62+
$notifications = idx($settings, 'notifications', $notification_default);
63+
64+
$sounds = idx($settings, 'sounds', array());
65+
$map = PhabricatorConpherenceSoundSetting::getDefaultSound($sound_default);
66+
$receive = idx($sounds,
67+
ConpherenceRoomSettings::SOUND_RECEIVE,
68+
$map[ConpherenceRoomSettings::SOUND_RECEIVE]);
69+
$mention = idx($sounds,
70+
ConpherenceRoomSettings::SOUND_MENTION,
71+
$map[ConpherenceRoomSettings::SOUND_MENTION]);
72+
73+
$form = id(new AphrontFormView())
74+
->setUser($viewer)
75+
->appendControl(
76+
id(new AphrontFormRadioButtonControl())
77+
->setLabel(pht('Notify'))
78+
->addButton(
79+
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL,
80+
PhabricatorConpherenceNotificationsSetting::getSettingLabel(
81+
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL),
82+
'')
83+
->addButton(
84+
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_NOTIFY,
85+
PhabricatorConpherenceNotificationsSetting::getSettingLabel(
86+
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_NOTIFY),
87+
'')
88+
->setName('notifications')
89+
->setValue($notifications))
90+
->appendChild(
91+
id(new AphrontFormSelectControl())
92+
->setLabel(pht('New Message'))
93+
->setName('sounds['.ConpherenceRoomSettings::SOUND_RECEIVE.']')
94+
->setOptions(ConpherenceRoomSettings::getDropdownSoundMap())
95+
->setValue($receive));
96+
97+
return $this->newDialog()
98+
->setTitle(pht('Room Preferences'))
99+
->appendForm($form)
100+
->addCancelButton($view_uri)
101+
->addSubmitButton(pht('Save'));
102+
}
103+
104+
}

src/applications/conpherence/controller/ConpherenceUpdateController.php

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ public function handleRequest(AphrontRequest $request) {
2424
case ConpherenceUpdateActions::METADATA:
2525
$needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT;
2626
break;
27-
case ConpherenceUpdateActions::NOTIFICATIONS:
28-
$need_participants = true;
29-
break;
3027
case ConpherenceUpdateActions::LOAD:
3128
break;
3229
}
@@ -112,22 +109,6 @@ public function handleRequest(AphrontRequest $request) {
112109
->setNewValue(array('-' => array($person_phid)));
113110
$response_mode = 'go-home';
114111
}
115-
break;
116-
case ConpherenceUpdateActions::NOTIFICATIONS:
117-
$notifications = $request->getStr('notifications');
118-
$sounds = $request->getArr('sounds');
119-
$participant = $conpherence->getParticipantIfExists($user->getPHID());
120-
if (!$participant) {
121-
return id(new Aphront404Response());
122-
}
123-
$participant->setSettings(array(
124-
'notifications' => $notifications,
125-
'sounds' => $sounds,
126-
));
127-
$participant->save();
128-
return id(new AphrontRedirectResponse())
129-
->setURI('/'.$conpherence->getMonogram());
130-
131112
break;
132113
case ConpherenceUpdateActions::METADATA:
133114
$title = $request->getStr('title');
@@ -221,9 +202,6 @@ public function handleRequest(AphrontRequest $request) {
221202
}
222203

223204
switch ($action) {
224-
case ConpherenceUpdateActions::NOTIFICATIONS:
225-
$dialog = $this->renderPreferencesDialog($conpherence);
226-
break;
227205
case ConpherenceUpdateActions::ADD_PERSON:
228206
$dialog = $this->renderAddPersonDialog($conpherence);
229207
break;
@@ -246,88 +224,6 @@ public function handleRequest(AphrontRequest $request) {
246224

247225
}
248226

249-
private function renderPreferencesDialog(
250-
ConpherenceThread $conpherence) {
251-
252-
$request = $this->getRequest();
253-
$user = $request->getUser();
254-
255-
$participant = $conpherence->getParticipantIfExists($user->getPHID());
256-
if (!$participant) {
257-
if ($user->isLoggedIn()) {
258-
$text = pht(
259-
'Notification settings are available after joining the room.');
260-
} else {
261-
$text = pht(
262-
'Notification settings are available after logging in and joining '.
263-
'the room.');
264-
}
265-
return id(new AphrontDialogView())
266-
->setTitle(pht('Room Preferences'))
267-
->appendParagraph($text);
268-
}
269-
270-
$notification_key = PhabricatorConpherenceNotificationsSetting::SETTINGKEY;
271-
$notification_default = $user->getUserSetting($notification_key);
272-
273-
$sound_key = PhabricatorConpherenceSoundSetting::SETTINGKEY;
274-
$sound_default = $user->getUserSetting($sound_key);
275-
276-
$settings = $participant->getSettings();
277-
$notifications = idx($settings, 'notifications', $notification_default);
278-
279-
$sounds = idx($settings, 'sounds', array());
280-
$map = PhabricatorConpherenceSoundSetting::getDefaultSound($sound_default);
281-
$receive = idx($sounds,
282-
ConpherenceRoomSettings::SOUND_RECEIVE,
283-
$map[ConpherenceRoomSettings::SOUND_RECEIVE]);
284-
$mention = idx($sounds,
285-
ConpherenceRoomSettings::SOUND_MENTION,
286-
$map[ConpherenceRoomSettings::SOUND_MENTION]);
287-
288-
$form = id(new AphrontFormView())
289-
->setUser($user)
290-
->appendControl(
291-
id(new AphrontFormRadioButtonControl())
292-
->setLabel(pht('Notify'))
293-
->addButton(
294-
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL,
295-
PhabricatorConpherenceNotificationsSetting::getSettingLabel(
296-
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL),
297-
'')
298-
->addButton(
299-
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_NOTIFY,
300-
PhabricatorConpherenceNotificationsSetting::getSettingLabel(
301-
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_NOTIFY),
302-
'')
303-
->setName('notifications')
304-
->setValue($notifications))
305-
->appendChild(
306-
id(new AphrontFormSelectControl())
307-
->setLabel(pht('Message Received'))
308-
->setName('sounds['.ConpherenceRoomSettings::SOUND_RECEIVE.']')
309-
->setOptions(ConpherenceRoomSettings::getDropdownSoundMap())
310-
->setValue($receive));
311-
312-
// TODO: Future Adventure! Expansion Pack
313-
//
314-
// ->appendChild(
315-
// id(new AphrontFormSelectControl())
316-
// ->setLabel(pht('Username Mentioned'))
317-
// ->setName('sounds['.ConpherenceRoomSettings::SOUND_MENTION.']')
318-
// ->setOptions(ConpherenceRoomSettings::getDropdownSoundMap())
319-
// ->setValue($mention));
320-
321-
return id(new AphrontDialogView())
322-
->setTitle(pht('Room Preferences'))
323-
->addHiddenInput('action', 'notifications')
324-
->addHiddenInput(
325-
'latest_transaction_id',
326-
$request->getInt('latest_transaction_id'))
327-
->appendForm($form);
328-
329-
}
330-
331227
private function renderAddPersonDialog(
332228
ConpherenceThread $conpherence) {
333229

@@ -508,7 +404,6 @@ private function loadAndRenderUpdates(
508404
$need_transactions = true;
509405
break;
510406
case ConpherenceUpdateActions::REMOVE_PERSON:
511-
case ConpherenceUpdateActions::NOTIFICATIONS:
512407
default:
513408
break;
514409

@@ -566,7 +461,6 @@ private function loadAndRenderUpdates(
566461
$people_widget = hsprintf('%s', $people_widget->render());
567462
break;
568463
case ConpherenceUpdateActions::REMOVE_PERSON:
569-
case ConpherenceUpdateActions::NOTIFICATIONS:
570464
default:
571465
break;
572466
}

src/applications/conpherence/storage/ConpherenceThread.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public function getMonogram() {
7272
return 'Z'.$this->getID();
7373
}
7474

75+
public function getURI() {
76+
return '/'.$this->getMonogram();
77+
}
78+
7579
public function attachParticipants(array $participants) {
7680
assert_instances_of($participants, 'ConpherenceParticipant');
7781
$this->participants = $participants;

0 commit comments

Comments
 (0)