@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 113 lines 3.9 kB view raw
1<?php 2 3final 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 $theme = $request->getStr('theme'); 45 46 $participant->setSettings(array( 47 'notifications' => $notifications, 48 'sounds' => $sounds, 49 'theme' => $theme, 50 )); 51 $participant->save(); 52 53 return id(new AphrontRedirectResponse()) 54 ->setURI($view_uri); 55 } 56 57 $notification_key = PhabricatorConpherenceNotificationsSetting::SETTINGKEY; 58 $notification_default = $viewer->getUserSetting($notification_key); 59 60 $sound_key = PhabricatorConpherenceSoundSetting::SETTINGKEY; 61 $sound_default = $viewer->getUserSetting($sound_key); 62 63 $settings = $participant->getSettings(); 64 $notifications = idx($settings, 'notifications', $notification_default); 65 $theme = idx($settings, 'theme', ConpherenceRoomSettings::COLOR_LIGHT); 66 67 $sounds = idx($settings, 'sounds', array()); 68 $map = PhabricatorConpherenceSoundSetting::getDefaultSound($sound_default); 69 $receive = idx($sounds, 70 ConpherenceRoomSettings::SOUND_RECEIVE, 71 $map[ConpherenceRoomSettings::SOUND_RECEIVE]); 72 $mention = idx($sounds, 73 ConpherenceRoomSettings::SOUND_MENTION, 74 $map[ConpherenceRoomSettings::SOUND_MENTION]); 75 76 $form = id(new AphrontFormView()) 77 ->setUser($viewer) 78 ->appendControl( 79 id(new AphrontFormRadioButtonControl()) 80 ->setLabel(pht('Notify')) 81 ->addButton( 82 PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL, 83 PhabricatorConpherenceNotificationsSetting::getSettingLabel( 84 PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL), 85 '') 86 ->addButton( 87 PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_NOTIFY, 88 PhabricatorConpherenceNotificationsSetting::getSettingLabel( 89 PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_NOTIFY), 90 '') 91 ->setName('notifications') 92 ->setValue($notifications)) 93 ->appendChild( 94 id(new AphrontFormSelectControl()) 95 ->setLabel(pht('New Message')) 96 ->setName('sounds['.ConpherenceRoomSettings::SOUND_RECEIVE.']') 97 ->setOptions(ConpherenceRoomSettings::getDropdownSoundMap()) 98 ->setValue($receive)) 99 ->appendChild( 100 id(new AphrontFormSelectControl()) 101 ->setLabel(pht('Theme')) 102 ->setName('theme') 103 ->setOptions(ConpherenceRoomSettings::getThemeMap()) 104 ->setValue($theme)); 105 106 return $this->newDialog() 107 ->setTitle(pht('Room Preferences')) 108 ->appendForm($form) 109 ->addCancelButton($view_uri) 110 ->addSubmitButton(pht('Save')); 111 } 112 113}