mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-03 11:21:01 +01:00
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
This commit is contained in:
parent
d2560b2462
commit
6969e9389f
7 changed files with 118 additions and 115 deletions
|
@ -310,6 +310,7 @@ phutil_register_library_map(array(
|
|||
'ConpherenceReplyHandler' => 'applications/conpherence/mail/ConpherenceReplyHandler.php',
|
||||
'ConpherenceRoomListController' => 'applications/conpherence/controller/ConpherenceRoomListController.php',
|
||||
'ConpherenceRoomPictureController' => 'applications/conpherence/controller/ConpherenceRoomPictureController.php',
|
||||
'ConpherenceRoomPreferencesController' => 'applications/conpherence/controller/ConpherenceRoomPreferencesController.php',
|
||||
'ConpherenceRoomSettings' => 'applications/conpherence/constants/ConpherenceRoomSettings.php',
|
||||
'ConpherenceRoomTestCase' => 'applications/conpherence/__tests__/ConpherenceRoomTestCase.php',
|
||||
'ConpherenceSchemaSpec' => 'applications/conpherence/storage/ConpherenceSchemaSpec.php',
|
||||
|
@ -5108,6 +5109,7 @@ phutil_register_library_map(array(
|
|||
'ConpherenceReplyHandler' => 'PhabricatorMailReplyHandler',
|
||||
'ConpherenceRoomListController' => 'ConpherenceController',
|
||||
'ConpherenceRoomPictureController' => 'ConpherenceController',
|
||||
'ConpherenceRoomPreferencesController' => 'ConpherenceController',
|
||||
'ConpherenceRoomSettings' => 'ConpherenceConstants',
|
||||
'ConpherenceRoomTestCase' => 'ConpherenceTestCase',
|
||||
'ConpherenceSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||
|
|
|
@ -55,6 +55,8 @@ final class PhabricatorConpherenceApplication extends PhabricatorApplication {
|
|||
=> 'ConpherenceNotificationPanelController',
|
||||
'participant/(?P<id>[1-9]\d*)/'
|
||||
=> 'ConpherenceParticipantController',
|
||||
'preferences/(?P<id>[1-9]\d*)/'
|
||||
=> 'ConpherenceRoomPreferencesController',
|
||||
'update/(?P<id>[1-9]\d*)/'
|
||||
=> 'ConpherenceUpdateController',
|
||||
),
|
||||
|
|
|
@ -8,7 +8,6 @@ final class ConpherenceUpdateActions extends ConpherenceConstants {
|
|||
const JOIN_ROOM = 'join_room';
|
||||
const ADD_PERSON = 'add_person';
|
||||
const REMOVE_PERSON = 'remove_person';
|
||||
const NOTIFICATIONS = 'notifications';
|
||||
const ADD_STATUS = 'add_status';
|
||||
const LOAD = 'load';
|
||||
}
|
||||
|
|
|
@ -57,8 +57,9 @@ abstract class ConpherenceController extends PhabricatorController {
|
|||
ConpherenceThread $conpherence) {
|
||||
$viewer = $this->getViewer();
|
||||
$header = null;
|
||||
$id = $conpherence->getID();
|
||||
|
||||
if ($conpherence->getID()) {
|
||||
if ($id) {
|
||||
$data = $conpherence->getDisplayData($this->getViewer());
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
|
@ -83,15 +84,14 @@ abstract class ConpherenceController extends PhabricatorController {
|
|||
|
||||
if ($can_edit) {
|
||||
$header->setImageURL(
|
||||
$this->getApplicationURI('picture/'.$conpherence->getID().'/'));
|
||||
$this->getApplicationURI("picture/{$id}/"));
|
||||
}
|
||||
|
||||
$participating = $conpherence->getParticipantIfExists($viewer->getPHID());
|
||||
|
||||
$header->addActionItem(
|
||||
id(new PHUIIconCircleView())
|
||||
->setHref(
|
||||
$this->getApplicationURI('update/'.$conpherence->getID()).'/')
|
||||
->setHref($this->getApplicationURI("update/{$id}/"))
|
||||
->setIcon('fa-pencil')
|
||||
->addClass('hide-on-device')
|
||||
->setColor('violet')
|
||||
|
@ -99,9 +99,7 @@ abstract class ConpherenceController extends PhabricatorController {
|
|||
|
||||
$header->addActionItem(
|
||||
id(new PHUIIconCircleView())
|
||||
->setHref(
|
||||
$this->getApplicationURI('update/'.$conpherence->getID()).'/'.
|
||||
'?action='.ConpherenceUpdateActions::NOTIFICATIONS)
|
||||
->setHref($this->getApplicationURI("preferences/{$id}/"))
|
||||
->setIcon('fa-gear')
|
||||
->addClass('hide-on-device')
|
||||
->setColor('pink')
|
||||
|
@ -136,7 +134,7 @@ abstract class ConpherenceController extends PhabricatorController {
|
|||
|
||||
if (!$participating) {
|
||||
$action = ConpherenceUpdateActions::JOIN_ROOM;
|
||||
$uri = $this->getApplicationURI('update/'.$conpherence->getID().'/');
|
||||
$uri = $this->getApplicationURI("update/{$id}/");
|
||||
$button = phutil_tag(
|
||||
'button',
|
||||
array(
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
<?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');
|
||||
|
||||
$participant->setSettings(array(
|
||||
'notifications' => $notifications,
|
||||
'sounds' => $sounds,
|
||||
));
|
||||
$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);
|
||||
|
||||
$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));
|
||||
|
||||
return $this->newDialog()
|
||||
->setTitle(pht('Room Preferences'))
|
||||
->appendForm($form)
|
||||
->addCancelButton($view_uri)
|
||||
->addSubmitButton(pht('Save'));
|
||||
}
|
||||
|
||||
}
|
|
@ -24,9 +24,6 @@ final class ConpherenceUpdateController
|
|||
case ConpherenceUpdateActions::METADATA:
|
||||
$needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT;
|
||||
break;
|
||||
case ConpherenceUpdateActions::NOTIFICATIONS:
|
||||
$need_participants = true;
|
||||
break;
|
||||
case ConpherenceUpdateActions::LOAD:
|
||||
break;
|
||||
}
|
||||
|
@ -112,22 +109,6 @@ final class ConpherenceUpdateController
|
|||
->setNewValue(array('-' => array($person_phid)));
|
||||
$response_mode = 'go-home';
|
||||
}
|
||||
break;
|
||||
case ConpherenceUpdateActions::NOTIFICATIONS:
|
||||
$notifications = $request->getStr('notifications');
|
||||
$sounds = $request->getArr('sounds');
|
||||
$participant = $conpherence->getParticipantIfExists($user->getPHID());
|
||||
if (!$participant) {
|
||||
return id(new Aphront404Response());
|
||||
}
|
||||
$participant->setSettings(array(
|
||||
'notifications' => $notifications,
|
||||
'sounds' => $sounds,
|
||||
));
|
||||
$participant->save();
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI('/'.$conpherence->getMonogram());
|
||||
|
||||
break;
|
||||
case ConpherenceUpdateActions::METADATA:
|
||||
$title = $request->getStr('title');
|
||||
|
@ -221,9 +202,6 @@ final class ConpherenceUpdateController
|
|||
}
|
||||
|
||||
switch ($action) {
|
||||
case ConpherenceUpdateActions::NOTIFICATIONS:
|
||||
$dialog = $this->renderPreferencesDialog($conpherence);
|
||||
break;
|
||||
case ConpherenceUpdateActions::ADD_PERSON:
|
||||
$dialog = $this->renderAddPersonDialog($conpherence);
|
||||
break;
|
||||
|
@ -246,88 +224,6 @@ final class ConpherenceUpdateController
|
|||
|
||||
}
|
||||
|
||||
private function renderPreferencesDialog(
|
||||
ConpherenceThread $conpherence) {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$participant = $conpherence->getParticipantIfExists($user->getPHID());
|
||||
if (!$participant) {
|
||||
if ($user->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 id(new AphrontDialogView())
|
||||
->setTitle(pht('Room Preferences'))
|
||||
->appendParagraph($text);
|
||||
}
|
||||
|
||||
$notification_key = PhabricatorConpherenceNotificationsSetting::SETTINGKEY;
|
||||
$notification_default = $user->getUserSetting($notification_key);
|
||||
|
||||
$sound_key = PhabricatorConpherenceSoundSetting::SETTINGKEY;
|
||||
$sound_default = $user->getUserSetting($sound_key);
|
||||
|
||||
$settings = $participant->getSettings();
|
||||
$notifications = idx($settings, 'notifications', $notification_default);
|
||||
|
||||
$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($user)
|
||||
->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('Message Received'))
|
||||
->setName('sounds['.ConpherenceRoomSettings::SOUND_RECEIVE.']')
|
||||
->setOptions(ConpherenceRoomSettings::getDropdownSoundMap())
|
||||
->setValue($receive));
|
||||
|
||||
// TODO: Future Adventure! Expansion Pack
|
||||
//
|
||||
// ->appendChild(
|
||||
// id(new AphrontFormSelectControl())
|
||||
// ->setLabel(pht('Username Mentioned'))
|
||||
// ->setName('sounds['.ConpherenceRoomSettings::SOUND_MENTION.']')
|
||||
// ->setOptions(ConpherenceRoomSettings::getDropdownSoundMap())
|
||||
// ->setValue($mention));
|
||||
|
||||
return id(new AphrontDialogView())
|
||||
->setTitle(pht('Room Preferences'))
|
||||
->addHiddenInput('action', 'notifications')
|
||||
->addHiddenInput(
|
||||
'latest_transaction_id',
|
||||
$request->getInt('latest_transaction_id'))
|
||||
->appendForm($form);
|
||||
|
||||
}
|
||||
|
||||
private function renderAddPersonDialog(
|
||||
ConpherenceThread $conpherence) {
|
||||
|
||||
|
@ -508,7 +404,6 @@ final class ConpherenceUpdateController
|
|||
$need_transactions = true;
|
||||
break;
|
||||
case ConpherenceUpdateActions::REMOVE_PERSON:
|
||||
case ConpherenceUpdateActions::NOTIFICATIONS:
|
||||
default:
|
||||
break;
|
||||
|
||||
|
@ -566,7 +461,6 @@ final class ConpherenceUpdateController
|
|||
$people_widget = hsprintf('%s', $people_widget->render());
|
||||
break;
|
||||
case ConpherenceUpdateActions::REMOVE_PERSON:
|
||||
case ConpherenceUpdateActions::NOTIFICATIONS:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -72,6 +72,10 @@ final class ConpherenceThread extends ConpherenceDAO
|
|||
return 'Z'.$this->getID();
|
||||
}
|
||||
|
||||
public function getURI() {
|
||||
return '/'.$this->getMonogram();
|
||||
}
|
||||
|
||||
public function attachParticipants(array $participants) {
|
||||
assert_instances_of($participants, 'ConpherenceParticipant');
|
||||
$this->participants = $participants;
|
||||
|
|
Loading…
Reference in a new issue