forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConpherenceRoomPreferencesController.php
113 lines (97 loc) · 3.82 KB
/
ConpherenceRoomPreferencesController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
final class ConpherenceRoomPreferencesController
extends ConpherenceController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$conpherence_id = $request->getURIData('id');
$conpherence = id(new ConpherenceThreadQuery())
->setViewer($viewer)
->withIDs(array($conpherence_id))
->executeOne();
if (!$conpherence) {
return new Aphront404Response();
}
$view_uri = $conpherence->getURI();
$participant = $conpherence->getParticipantIfExists($viewer->getPHID());
if (!$participant) {
if ($viewer->isLoggedIn()) {
$text = pht(
'Notification settings are available after joining the room.');
} else {
$text = pht(
'Notification settings are available after logging in and joining '.
'the room.');
}
return $this->newDialog()
->setTitle(pht('Room Preferences'))
->addCancelButton($view_uri)
->appendParagraph($text);
}
// Save the data and redirect
if ($request->isFormPost()) {
$notifications = $request->getStr('notifications');
$sounds = $request->getArr('sounds');
$theme = $request->getStr('theme');
$participant->setSettings(array(
'notifications' => $notifications,
'sounds' => $sounds,
'theme' => $theme,
));
$participant->save();
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
$notification_key = PhabricatorConpherenceNotificationsSetting::SETTINGKEY;
$notification_default = $viewer->getUserSetting($notification_key);
$sound_key = PhabricatorConpherenceSoundSetting::SETTINGKEY;
$sound_default = $viewer->getUserSetting($sound_key);
$settings = $participant->getSettings();
$notifications = idx($settings, 'notifications', $notification_default);
$theme = idx($settings, 'theme', ConpherenceRoomSettings::COLOR_LIGHT);
$sounds = idx($settings, 'sounds', array());
$map = PhabricatorConpherenceSoundSetting::getDefaultSound($sound_default);
$receive = idx($sounds,
ConpherenceRoomSettings::SOUND_RECEIVE,
$map[ConpherenceRoomSettings::SOUND_RECEIVE]);
$mention = idx($sounds,
ConpherenceRoomSettings::SOUND_MENTION,
$map[ConpherenceRoomSettings::SOUND_MENTION]);
$form = id(new AphrontFormView())
->setUser($viewer)
->appendControl(
id(new AphrontFormRadioButtonControl())
->setLabel(pht('Notify'))
->addButton(
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL,
PhabricatorConpherenceNotificationsSetting::getSettingLabel(
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL),
'')
->addButton(
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_NOTIFY,
PhabricatorConpherenceNotificationsSetting::getSettingLabel(
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_NOTIFY),
'')
->setName('notifications')
->setValue($notifications))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('New Message'))
->setName('sounds['.ConpherenceRoomSettings::SOUND_RECEIVE.']')
->setOptions(ConpherenceRoomSettings::getDropdownSoundMap())
->setValue($receive))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Theme'))
->setName('theme')
->setOptions(ConpherenceRoomSettings::getThemeMap())
->setValue($theme));
return $this->newDialog()
->setTitle(pht('Room Preferences'))
->appendForm($form)
->addCancelButton($view_uri)
->addSubmitButton(pht('Save'));
}
}