diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -310,6 +310,7 @@ '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 @@ 'ConpherenceReplyHandler' => 'PhabricatorMailReplyHandler', 'ConpherenceRoomListController' => 'ConpherenceController', 'ConpherenceRoomPictureController' => 'ConpherenceController', + 'ConpherenceRoomPreferencesController' => 'ConpherenceController', 'ConpherenceRoomSettings' => 'ConpherenceConstants', 'ConpherenceRoomTestCase' => 'ConpherenceTestCase', 'ConpherenceSchemaSpec' => 'PhabricatorConfigSchemaSpec', diff --git a/src/applications/conpherence/application/PhabricatorConpherenceApplication.php b/src/applications/conpherence/application/PhabricatorConpherenceApplication.php --- a/src/applications/conpherence/application/PhabricatorConpherenceApplication.php +++ b/src/applications/conpherence/application/PhabricatorConpherenceApplication.php @@ -55,6 +55,8 @@ => 'ConpherenceNotificationPanelController', 'participant/(?P[1-9]\d*)/' => 'ConpherenceParticipantController', + 'preferences/(?P[1-9]\d*)/' + => 'ConpherenceRoomPreferencesController', 'update/(?P[1-9]\d*)/' => 'ConpherenceUpdateController', ), diff --git a/src/applications/conpherence/constants/ConpherenceUpdateActions.php b/src/applications/conpherence/constants/ConpherenceUpdateActions.php --- a/src/applications/conpherence/constants/ConpherenceUpdateActions.php +++ b/src/applications/conpherence/constants/ConpherenceUpdateActions.php @@ -8,7 +8,6 @@ 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'; } diff --git a/src/applications/conpherence/controller/ConpherenceController.php b/src/applications/conpherence/controller/ConpherenceController.php --- a/src/applications/conpherence/controller/ConpherenceController.php +++ b/src/applications/conpherence/controller/ConpherenceController.php @@ -57,8 +57,9 @@ 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 @@ 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 @@ $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 @@ if (!$participating) { $action = ConpherenceUpdateActions::JOIN_ROOM; - $uri = $this->getApplicationURI('update/'.$conpherence->getID().'/'); + $uri = $this->getApplicationURI("update/{$id}/"); $button = phutil_tag( 'button', array( diff --git a/src/applications/conpherence/controller/ConpherenceRoomPreferencesController.php b/src/applications/conpherence/controller/ConpherenceRoomPreferencesController.php new file mode 100644 --- /dev/null +++ b/src/applications/conpherence/controller/ConpherenceRoomPreferencesController.php @@ -0,0 +1,104 @@ +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')); + } + +} diff --git a/src/applications/conpherence/controller/ConpherenceUpdateController.php b/src/applications/conpherence/controller/ConpherenceUpdateController.php --- a/src/applications/conpherence/controller/ConpherenceUpdateController.php +++ b/src/applications/conpherence/controller/ConpherenceUpdateController.php @@ -24,9 +24,6 @@ case ConpherenceUpdateActions::METADATA: $needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT; break; - case ConpherenceUpdateActions::NOTIFICATIONS: - $need_participants = true; - break; case ConpherenceUpdateActions::LOAD: break; } @@ -113,22 +110,6 @@ $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'); $topic = $request->getStr('topic'); @@ -221,9 +202,6 @@ } switch ($action) { - case ConpherenceUpdateActions::NOTIFICATIONS: - $dialog = $this->renderPreferencesDialog($conpherence); - break; case ConpherenceUpdateActions::ADD_PERSON: $dialog = $this->renderAddPersonDialog($conpherence); break; @@ -246,88 +224,6 @@ } - 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 @@ $need_transactions = true; break; case ConpherenceUpdateActions::REMOVE_PERSON: - case ConpherenceUpdateActions::NOTIFICATIONS: default: break; @@ -566,7 +461,6 @@ $people_widget = hsprintf('%s', $people_widget->render()); break; case ConpherenceUpdateActions::REMOVE_PERSON: - case ConpherenceUpdateActions::NOTIFICATIONS: default: break; } diff --git a/src/applications/conpherence/storage/ConpherenceThread.php b/src/applications/conpherence/storage/ConpherenceThread.php --- a/src/applications/conpherence/storage/ConpherenceThread.php +++ b/src/applications/conpherence/storage/ConpherenceThread.php @@ -72,6 +72,10 @@ return 'Z'.$this->getID(); } + public function getURI() { + return '/'.$this->getMonogram(); + } + public function attachParticipants(array $participants) { assert_instances_of($participants, 'ConpherenceParticipant'); $this->participants = $participants;