public function handleRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $title = pht('New Room');
     $e_title = true;
     $v_message = null;
     $validation_exception = null;
     $conpherence = ConpherenceThread::initializeNewRoom($user);
     $participants = array();
     if ($request->isFormPost()) {
         $editor = new ConpherenceEditor();
         $xactions = array();
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TITLE)->setNewValue($request->getStr('title'));
         $participants = $request->getArr('participants');
         $participants[] = $user->getPHID();
         $participants = array_unique($participants);
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => $participants));
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TOPIC)->setNewValue($request->getStr('topic'));
         $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'));
         $v_message = $request->getStr('message');
         if (strlen($v_message)) {
             $message_xactions = $editor->generateTransactionsFromText($user, $conpherence, $v_message);
             $xactions = array_merge($xactions, $message_xactions);
         }
         try {
             $editor->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setActor($user)->applyTransactions($conpherence, $xactions);
             return id(new AphrontRedirectResponse())->setURI('/' . $conpherence->getMonogram());
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $validation_exception = $ex;
             $e_title = $ex->getShortMessage(ConpherenceTransaction::TYPE_TITLE);
             $conpherence->setViewPolicy($request->getStr('viewPolicy'));
             $conpherence->setEditPolicy($request->getStr('editPolicy'));
             $conpherence->setJoinPolicy($request->getStr('joinPolicy'));
         }
     } else {
         if ($request->getStr('participant')) {
             $participants[] = $request->getStr('participant');
         }
     }
     $policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($conpherence)->execute();
     $submit_uri = $this->getApplicationURI('new/');
     $cancel_uri = $this->getApplicationURI('search/');
     $dialog = $this->newDialog()->setWidth(AphrontDialogView::WIDTH_FORM)->setValidationException($validation_exception)->setUser($user)->setTitle($title)->addCancelButton($cancel_uri)->addSubmitButton(pht('Create Room'));
     $form = id(new PHUIFormLayoutView())->setUser($user)->appendChild(id(new AphrontFormTextControl())->setError($e_title)->setLabel(pht('Name'))->setName('title')->setValue($request->getStr('title')))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Topic'))->setName('topic')->setValue($request->getStr('topic')))->appendChild(id(new AphrontFormTokenizerControl())->setName('participants')->setUser($user)->setDatasource(new PhabricatorPeopleDatasource())->setValue($participants)->setLabel(pht('Other Participants')))->appendChild(id(new AphrontFormPolicyControl())->setName('viewPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('editPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('joinPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_JOIN)->setPolicies($policies))->appendChild(id(new PhabricatorRemarkupControl())->setUser($user)->setName('message')->setLabel(pht('First Message'))->setValue($v_message));
     $dialog->appendChild($form);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $title = pht('New Message');
     $participants = array();
     $participant_prefill = null;
     $message = '';
     $e_participants = null;
     $e_message = null;
     // this comes from ajax requests from all over. should be a single phid.
     if ($request->isFormPost()) {
         $participants = $request->getArr('participants');
         $message = $request->getStr('message');
         list($error_codes, $conpherence) = ConpherenceEditor::createConpherence($user, $participants, $conpherence_title = null, $message, PhabricatorContentSource::newFromRequest($request));
         if ($error_codes) {
             foreach ($error_codes as $error_code) {
                 switch ($error_code) {
                     case ConpherenceEditor::ERROR_EMPTY_MESSAGE:
                         $e_message = true;
                         break;
                     case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS:
                         $e_participants = true;
                         break;
                 }
             }
         } else {
             $uri = $this->getApplicationURI($conpherence->getID());
             return id(new AphrontRedirectResponse())->setURI($uri);
         }
     } else {
         $participant_prefill = $request->getStr('participant');
         if ($participant_prefill) {
             $participants[] = $participant_prefill;
         }
     }
     $participant_handles = array();
     if ($participants) {
         $participant_handles = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs($participants)->execute();
     }
     $submit_uri = $this->getApplicationURI('new/');
     $cancel_uri = $this->getApplicationURI();
     // TODO - we can get a better cancel_uri once we get better at crazy
     // ajax jonx T2086
     if ($participant_prefill) {
         $handle = $participant_handles[$participant_prefill];
         $cancel_uri = $handle->getURI();
     }
     $dialog = id(new AphrontDialogView())->setWidth(AphrontDialogView::WIDTH_FORM)->setUser($user)->setTitle($title)->addCancelButton($cancel_uri)->addSubmitButton(pht('Send Message'));
     $form = id(new PHUIFormLayoutView())->setUser($user)->setFullWidth(true)->appendChild(id(new AphrontFormTokenizerControl())->setName('participants')->setValue($participant_handles)->setUser($user)->setDatasource(new PhabricatorPeopleDatasource())->setLabel(pht('To'))->setError($e_participants))->appendChild(id(new PhabricatorRemarkupControl())->setName('message')->setValue($message)->setLabel(pht('Message'))->setError($e_message));
     $dialog->appendChild($form);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $title = pht('New Message');
     $participants = array();
     $participant_prefill = null;
     $message = '';
     $e_participants = null;
     $e_message = null;
     $errors = array();
     // this comes from ajax requests from all over. should be a single phid.
     if ($request->isFormPost()) {
         $participants = $request->getArr('participants');
         $message = $request->getStr('message');
         list($error_codes, $conpherence) = ConpherenceEditor::createThread($user, $participants, $conpherence_title = null, $message, PhabricatorContentSource::newFromRequest($request));
         if ($error_codes) {
             foreach ($error_codes as $error_code) {
                 switch ($error_code) {
                     case ConpherenceEditor::ERROR_EMPTY_MESSAGE:
                         $e_message = pht('Required');
                         $errors[] = pht('You can not send an empty message.');
                         break;
                     case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS:
                         $e_participants = pht('Required');
                         $errors[] = pht('You must choose at least one recipient for your ' . 'message.');
                         break;
                 }
             }
         } else {
             return id(new AphrontRedirectResponse())->setURI('/' . $conpherence->getMonogram());
         }
     } else {
         $participant_prefill = $request->getStr('participant');
         if ($participant_prefill) {
             $participants[] = $participant_prefill;
         }
     }
     $submit_uri = $this->getApplicationURI('new/');
     $cancel_uri = $this->getApplicationURI();
     $dialog = id(new AphrontDialogView())->setWidth(AphrontDialogView::WIDTH_FORM)->setErrors($errors)->setUser($user)->setTitle($title)->addCancelButton($cancel_uri)->addSubmitButton(pht('Send Message'));
     $form = id(new AphrontFormView())->setUser($user)->setFullWidth(true)->appendControl(id(new AphrontFormTokenizerControl())->setName('participants')->setValue($participants)->setUser($user)->setDatasource(new PhabricatorPeopleDatasource())->setLabel(pht('To'))->setError($e_participants))->appendChild(id(new PhabricatorRemarkupControl())->setUser($user)->setName('message')->setValue($message)->setLabel(pht('Message'))->setError($e_message));
     $dialog->appendForm($form);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $participant_phids = $request->getValue('participantPHIDs', array());
     $message = $request->getValue('message');
     $title = $request->getValue('title');
     list($errors, $conpherence) = ConpherenceEditor::createThread($request->getUser(), $participant_phids, $title, $message, $request->newContentSource());
     if ($errors) {
         foreach ($errors as $error_code) {
             switch ($error_code) {
                 case ConpherenceEditor::ERROR_EMPTY_MESSAGE:
                     throw new ConduitException('ERR_EMPTY_MESSAGE');
                     break;
                 case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS:
                     throw new ConduitException('ERR_EMPTY_PARTICIPANT_PHIDS');
                     break;
             }
         }
     }
     return array('conpherenceID' => $conpherence->getID(), 'conpherencePHID' => $conpherence->getPHID(), 'conpherenceURI' => $this->getConpherenceURI($conpherence));
 }
 private function createThread(PhabricatorUser $creator, array $participant_phids)
 {
     list($errors, $conpherence) = ConpherenceEditor::createThread($creator, $participant_phids, pht('Test'), pht('Test'), PhabricatorContentSource::newConsoleSource());
     return $conpherence;
 }