2013-01-24 17:23:05 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group conpherence
|
|
|
|
|
*/
|
|
|
|
|
final class ConpherenceNewController extends ConpherenceController {
|
|
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
|
|
$conpherence = id(new ConpherenceThread())
|
|
|
|
|
->attachParticipants(array())
|
2013-04-04 16:57:38 -07:00
|
|
|
->attachFilePHIDs(array())
|
|
|
|
|
->setMessageCount(0);
|
2013-04-15 16:27:41 -07:00
|
|
|
$title = pht('New Message');
|
2013-01-24 17:23:05 -08:00
|
|
|
$participants = array();
|
|
|
|
|
$message = '';
|
|
|
|
|
$files = array();
|
|
|
|
|
$errors = array();
|
|
|
|
|
$e_participants = null;
|
|
|
|
|
$e_message = null;
|
|
|
|
|
|
|
|
|
|
// this comes from ajax requests from all over. should be a single phid.
|
|
|
|
|
$participant_prefill = $request->getStr('participant');
|
|
|
|
|
if ($participant_prefill) {
|
|
|
|
|
$participants[] = $participant_prefill;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
|
$participants = $request->getArr('participants');
|
|
|
|
|
if (empty($participants)) {
|
|
|
|
|
$e_participants = true;
|
|
|
|
|
$errors[] = pht('You must specify participants.');
|
|
|
|
|
} else {
|
|
|
|
|
$participants[] = $user->getPHID();
|
|
|
|
|
$participants = array_unique($participants);
|
2013-04-04 16:57:38 -07:00
|
|
|
$conpherence->setRecentParticipantPHIDs(
|
|
|
|
|
array_slice($participants, 0, 10));
|
2013-01-24 17:23:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$message = $request->getStr('message');
|
|
|
|
|
if (empty($message)) {
|
|
|
|
|
$e_message = true;
|
|
|
|
|
$errors[] = pht('You must write a message.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$file_phids =
|
|
|
|
|
PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
|
2013-02-19 13:33:10 -08:00
|
|
|
array($message));
|
2013-01-24 17:23:05 -08:00
|
|
|
if ($file_phids) {
|
|
|
|
|
$files = id(new PhabricatorFileQuery())
|
|
|
|
|
->setViewer($user)
|
|
|
|
|
->withPHIDs($file_phids)
|
|
|
|
|
->execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
|
$conpherence->openTransaction();
|
|
|
|
|
$conpherence->save();
|
|
|
|
|
$xactions = array();
|
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_PARTICIPANTS)
|
|
|
|
|
->setNewValue(array('+' => $participants));
|
2013-01-25 16:03:54 -08:00
|
|
|
if ($files) {
|
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_FILES)
|
|
|
|
|
->setNewValue(array('+' => mpull($files, 'getPHID')));
|
|
|
|
|
}
|
2013-01-24 17:23:05 -08:00
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
|
|
|
->attachComment(
|
|
|
|
|
id(new ConpherenceTransactionComment())
|
|
|
|
|
->setContent($message)
|
2013-02-19 13:33:10 -08:00
|
|
|
->setConpherencePHID($conpherence->getPHID()));
|
2013-05-24 10:48:34 -07:00
|
|
|
|
2013-01-24 17:23:05 -08:00
|
|
|
id(new ConpherenceEditor())
|
2013-05-24 10:48:34 -07:00
|
|
|
->setContentSourceFromRequest($request)
|
2013-01-24 17:23:05 -08:00
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
|
->setActor($user)
|
|
|
|
|
->applyTransactions($conpherence, $xactions);
|
|
|
|
|
|
|
|
|
|
$conpherence->saveTransaction();
|
|
|
|
|
|
2013-05-01 14:42:58 -07:00
|
|
|
$uri = $this->getApplicationURI($conpherence->getID());
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
|
->setURI($uri);
|
2013-01-24 17:23:05 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$error_view = null;
|
|
|
|
|
if ($errors) {
|
|
|
|
|
$error_view = id(new AphrontErrorView())
|
|
|
|
|
->setTitle(pht('Conpherence Errors'))
|
|
|
|
|
->setErrors($errors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$participant_handles = array();
|
|
|
|
|
if ($participants) {
|
|
|
|
|
$handles = id(new PhabricatorObjectHandleData($participants))
|
|
|
|
|
->setViewer($user)
|
|
|
|
|
->loadHandles();
|
|
|
|
|
$participant_handles = mpull($handles, 'getFullName', 'getPHID');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$submit_uri = $this->getApplicationURI('new/');
|
|
|
|
|
$cancel_uri = $this->getApplicationURI();
|
2013-03-31 12:44:12 -07:00
|
|
|
|
|
|
|
|
// TODO - we can get a better cancel_uri once we get better at crazy
|
|
|
|
|
// ajax jonx T2086
|
|
|
|
|
if ($participant_prefill) {
|
|
|
|
|
$handle = $handles[$participant_prefill];
|
|
|
|
|
$cancel_uri = $handle->getURI();
|
2013-01-24 17:23:05 -08:00
|
|
|
}
|
|
|
|
|
|
2013-03-31 12:44:12 -07:00
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
|
|
|
->setUser($user)
|
|
|
|
|
->setTitle($title)
|
|
|
|
|
->addCancelButton($cancel_uri)
|
2013-04-15 16:27:41 -07:00
|
|
|
->addSubmitButton(pht('Send Message'));
|
2013-03-31 12:44:12 -07:00
|
|
|
|
|
|
|
|
$form = id(new AphrontFormLayoutView())
|
2013-01-24 17:23:05 -08:00
|
|
|
->setUser($user)
|
2013-05-14 12:21:00 -07:00
|
|
|
->setFullWidth(true)
|
2013-01-24 17:23:05 -08:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
|
->setName('participants')
|
|
|
|
|
->setValue($participant_handles)
|
|
|
|
|
->setUser($user)
|
|
|
|
|
->setDatasource('/typeahead/common/users/')
|
|
|
|
|
->setLabel(pht('To'))
|
2013-02-19 13:33:10 -08:00
|
|
|
->setError($e_participants))
|
2013-01-24 17:23:05 -08:00
|
|
|
->appendChild(
|
|
|
|
|
id(new PhabricatorRemarkupControl())
|
|
|
|
|
->setName('message')
|
|
|
|
|
->setValue($message)
|
|
|
|
|
->setLabel(pht('Message'))
|
2013-02-19 13:33:10 -08:00
|
|
|
->setError($e_message));
|
2013-01-24 17:23:05 -08:00
|
|
|
|
2013-03-31 12:44:12 -07:00
|
|
|
$dialog->appendChild($form);
|
2013-01-24 17:23:05 -08:00
|
|
|
|
2013-03-31 12:44:12 -07:00
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
2013-01-24 17:23:05 -08:00
|
|
|
}
|
|
|
|
|
}
|