private function renderSettingsWidgetPaneContent()
 {
     $viewer = $this->getViewer();
     $conpherence = $this->getConpherence();
     $participant = $conpherence->getParticipantIfExists($viewer->getPHID());
     if (!$participant) {
         $can_join = PhabricatorPolicyFilter::hasCapability($viewer, $conpherence, PhabricatorPolicyCapability::CAN_JOIN);
         if ($can_join) {
             $text = pht('Notification settings are available after joining the room.');
         } else {
             if ($viewer->isLoggedIn()) {
                 $text = pht('Notification settings not applicable to rooms you can not join.');
             } else {
                 $text = pht('Notification settings are available after logging in and joining ' . 'the room.');
             }
         }
         return phutil_tag('div', array('class' => 'no-settings'), $text);
     }
     $notification_key = PhabricatorConpherenceNotificationsSetting::SETTINGKEY;
     $notification_default = $viewer->getUserSetting($notification_key);
     $settings = $participant->getSettings();
     $notifications = idx($settings, 'notifications', $notification_default);
     $options = id(new AphrontFormRadioButtonControl())->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);
     $layout = array($options, phutil_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'notifications')), phutil_tag('button', array('type' => 'submit', 'class' => 'notifications-update'), pht('Save')));
     return phabricator_form($viewer, array('method' => 'POST', 'action' => $this->getWidgetURI(), 'sigil' => 'notifications-update'), $layout);
 }
 private function renderPreferencesDialog(ConpherenceThread $conpherence)
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $participant = $conpherence->getParticipantIfExists($user->getPHID());
     if (!$participant) {
         $can_join = PhabricatorPolicyFilter::hasCapability($user, $conpherence, PhabricatorPolicyCapability::CAN_JOIN);
         if ($can_join) {
             $text = pht('Notification settings are available after joining the room.');
         } else {
             if ($user->isLoggedIn()) {
                 $text = pht('Notification settings not applicable to rooms you can not join.');
             } 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);
     $settings = $participant->getSettings();
     $notifications = idx($settings, 'notifications', $notification_default);
     $form = id(new AphrontFormView())->setUser($user)->setFullWidth(true)->appendControl(id(new AphrontFormRadioButtonControl())->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));
     return id(new AphrontDialogView())->setTitle(pht('Room Preferences'))->addHiddenInput('action', 'notifications')->addHiddenInput('latest_transaction_id', $request->getInt('latest_transaction_id'))->appendForm($form);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $conpherence_id = $request->getURIData('id');
     if (!$conpherence_id) {
         return new Aphront404Response();
     }
     $need_participants = false;
     $needed_capabilities = array(PhabricatorPolicyCapability::CAN_VIEW);
     $action = $request->getStr('action', ConpherenceUpdateActions::METADATA);
     switch ($action) {
         case ConpherenceUpdateActions::REMOVE_PERSON:
             $person_phid = $request->getStr('remove_person');
             if ($person_phid != $user->getPHID()) {
                 $needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT;
             }
             break;
         case ConpherenceUpdateActions::ADD_PERSON:
         case ConpherenceUpdateActions::METADATA:
             $needed_capabilities[] = PhabricatorPolicyCapability::CAN_EDIT;
             break;
         case ConpherenceUpdateActions::JOIN_ROOM:
             $needed_capabilities[] = PhabricatorPolicyCapability::CAN_JOIN;
             break;
         case ConpherenceUpdateActions::NOTIFICATIONS:
             $need_participants = true;
             break;
         case ConpherenceUpdateActions::LOAD:
             break;
     }
     $conpherence = id(new ConpherenceThreadQuery())->setViewer($user)->withIDs(array($conpherence_id))->needFilePHIDs(true)->needOrigPics(true)->needCropPics(true)->needParticipants($need_participants)->requireCapabilities($needed_capabilities)->executeOne();
     $latest_transaction_id = null;
     $response_mode = $request->isAjax() ? 'ajax' : 'redirect';
     $error_view = null;
     $e_file = array();
     $errors = array();
     $delete_draft = false;
     $xactions = array();
     if ($request->isFormPost() || $action == ConpherenceUpdateActions::LOAD) {
         $editor = id(new ConpherenceEditor())->setContinueOnNoEffect($request->isContinueRequest())->setContentSourceFromRequest($request)->setActor($user);
         switch ($action) {
             case ConpherenceUpdateActions::DRAFT:
                 $draft = PhabricatorDraft::newFromUserAndKey($user, $conpherence->getPHID());
                 $draft->setDraft($request->getStr('text'));
                 $draft->replaceOrDelete();
                 return new AphrontAjaxResponse();
             case ConpherenceUpdateActions::JOIN_ROOM:
                 $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => array($user->getPHID())));
                 $delete_draft = true;
                 $message = $request->getStr('text');
                 if ($message) {
                     $message_xactions = $editor->generateTransactionsFromText($user, $conpherence, $message);
                     $xactions = array_merge($xactions, $message_xactions);
                 }
                 // for now, just redirect back to the conpherence so everything
                 // will work okay...!
                 $response_mode = 'redirect';
                 break;
             case ConpherenceUpdateActions::MESSAGE:
                 $message = $request->getStr('text');
                 if (strlen($message)) {
                     $xactions = $editor->generateTransactionsFromText($user, $conpherence, $message);
                     $delete_draft = true;
                 } else {
                     $action = ConpherenceUpdateActions::LOAD;
                     $updated = false;
                     $response_mode = 'ajax';
                 }
                 break;
             case ConpherenceUpdateActions::ADD_PERSON:
                 $person_phids = $request->getArr('add_person');
                 if (!empty($person_phids)) {
                     $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => $person_phids));
                 }
                 break;
             case ConpherenceUpdateActions::REMOVE_PERSON:
                 if (!$request->isContinueRequest()) {
                     // do nothing; we'll display a confirmation dialogue instead
                     break;
                 }
                 $person_phid = $request->getStr('remove_person');
                 if ($person_phid) {
                     $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('-' => array($person_phid)));
                     $response_mode = 'go-home';
                 }
                 break;
             case ConpherenceUpdateActions::NOTIFICATIONS:
                 $notifications = $request->getStr('notifications');
                 $participant = $conpherence->getParticipantIfExists($user->getPHID());
                 if (!$participant) {
                     return id(new Aphront404Response());
                 }
                 $participant->setSettings(array('notifications' => $notifications));
                 $participant->save();
                 $label = PhabricatorConpherenceNotificationsSetting::getSettingLabel($notifications);
                 $result = pht('Updated notification settings to "%s".', $label);
                 return id(new AphrontAjaxResponse())->setContent($result);
                 break;
             case ConpherenceUpdateActions::METADATA:
                 $top = $request->getInt('image_y');
                 $left = $request->getInt('image_x');
                 $file_id = $request->getInt('file_id');
                 $title = $request->getStr('title');
                 if ($file_id) {
                     $orig_file = id(new PhabricatorFileQuery())->setViewer($user)->withIDs(array($file_id))->executeOne();
                     $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PICTURE)->setNewValue($orig_file);
                     $okay = $orig_file->isTransformableImage();
                     if ($okay) {
                         $xformer = new PhabricatorImageTransformer();
                         $crop_file = $xformer->executeConpherenceTransform($orig_file, 0, 0, ConpherenceImageData::CROP_WIDTH, ConpherenceImageData::CROP_HEIGHT);
                         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PICTURE_CROP)->setNewValue($crop_file->getPHID());
                     }
                     $response_mode = 'redirect';
                 }
                 // all other metadata updates are continue requests
                 if (!$request->isContinueRequest()) {
                     break;
                 }
                 if ($top !== null || $left !== null) {
                     $file = $conpherence->getImage(ConpherenceImageData::SIZE_ORIG);
                     $xformer = new PhabricatorImageTransformer();
                     $xformed = $xformer->executeConpherenceTransform($file, $top, $left, ConpherenceImageData::CROP_WIDTH, ConpherenceImageData::CROP_HEIGHT);
                     $image_phid = $xformed->getPHID();
                     $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PICTURE_CROP)->setNewValue($image_phid);
                 }
                 $title = $request->getStr('title');
                 $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TITLE)->setNewValue($title);
                 $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($request->getStr('viewPolicy'));
                 $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($request->getStr('editPolicy'));
                 $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY)->setNewValue($request->getStr('joinPolicy'));
                 if (!$request->getExists('force_ajax')) {
                     $response_mode = 'redirect';
                 }
                 break;
             case ConpherenceUpdateActions::LOAD:
                 $updated = false;
                 $response_mode = 'ajax';
                 break;
             default:
                 throw new Exception(pht('Unknown action: %s', $action));
                 break;
         }
         if ($xactions) {
             try {
                 $xactions = $editor->applyTransactions($conpherence, $xactions);
                 if ($delete_draft) {
                     $draft = PhabricatorDraft::newFromUserAndKey($user, $conpherence->getPHID());
                     $draft->delete();
                 }
             } catch (PhabricatorApplicationTransactionNoEffectException $ex) {
                 return id(new PhabricatorApplicationTransactionNoEffectResponse())->setCancelURI($this->getApplicationURI($conpherence_id . '/'))->setException($ex);
             }
             // xactions had no effect...!
             if (empty($xactions)) {
                 $errors[] = pht('That was a non-update. Try cancel.');
             }
         }
         if ($xactions || $action == ConpherenceUpdateActions::LOAD) {
             switch ($response_mode) {
                 case 'ajax':
                     $latest_transaction_id = $request->getInt('latest_transaction_id');
                     $content = $this->loadAndRenderUpdates($action, $conpherence_id, $latest_transaction_id);
                     return id(new AphrontAjaxResponse())->setContent($content);
                     break;
                 case 'go-home':
                     $content = array('href' => $this->getApplicationURI());
                     return id(new AphrontAjaxResponse())->setContent($content);
                     break;
                 case 'redirect':
                 default:
                     return id(new AphrontRedirectResponse())->setURI('/' . $conpherence->getMonogram());
                     break;
             }
         }
     }
     if ($errors) {
         $error_view = id(new PHUIInfoView())->setErrors($errors);
     }
     switch ($action) {
         case ConpherenceUpdateActions::ADD_PERSON:
             $dialogue = $this->renderAddPersonDialogue($conpherence);
             break;
         case ConpherenceUpdateActions::REMOVE_PERSON:
             $dialogue = $this->renderRemovePersonDialogue($conpherence);
             break;
         case ConpherenceUpdateActions::METADATA:
         default:
             $dialogue = $this->renderMetadataDialogue($conpherence, $error_view);
             break;
     }
     return id(new AphrontDialogResponse())->setDialog($dialogue->setUser($user)->setWidth(AphrontDialogView::WIDTH_FORM)->setSubmitURI($this->getApplicationURI('update/' . $conpherence_id . '/'))->addSubmitButton()->addCancelButton($this->getApplicationURI($conpherence->getID() . '/')));
 }