2013-01-25 02:23:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group conpherence
|
|
|
|
*/
|
|
|
|
final class ConpherenceNewController extends ConpherenceController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$conpherence = id(new ConpherenceThread())
|
|
|
|
->attachParticipants(array())
|
|
|
|
->attachFilePHIDs(array());
|
2013-01-29 19:20:17 +01:00
|
|
|
$title = pht('New Conversation');
|
2013-01-25 02:23:05 +01: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = $request->getStr('message');
|
|
|
|
if (empty($message)) {
|
|
|
|
$e_message = true;
|
|
|
|
$errors[] = pht('You must write a message.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_phids =
|
|
|
|
PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
|
2013-02-19 22:33:10 +01:00
|
|
|
array($message));
|
2013-01-25 02:23:05 +01: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-26 01:03:54 +01:00
|
|
|
if ($files) {
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_FILES)
|
|
|
|
->setNewValue(array('+' => mpull($files, 'getPHID')));
|
|
|
|
}
|
2013-01-25 02:23:05 +01:00
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
|
|
->attachComment(
|
|
|
|
id(new ConpherenceTransactionComment())
|
|
|
|
->setContent($message)
|
2013-02-19 22:33:10 +01:00
|
|
|
->setConpherencePHID($conpherence->getPHID()));
|
2013-01-25 02:23:05 +01:00
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_WEB,
|
|
|
|
array(
|
|
|
|
'ip' => $request->getRemoteAddr()
|
2013-02-19 22:33:10 +01:00
|
|
|
));
|
2013-01-25 02:23:05 +01:00
|
|
|
id(new ConpherenceEditor())
|
|
|
|
->setContentSource($content_source)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setActor($user)
|
|
|
|
->applyTransactions($conpherence, $xactions);
|
|
|
|
|
|
|
|
$conpherence->saveTransaction();
|
|
|
|
|
|
|
|
if ($request->isAjax()) {
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle('Success')
|
|
|
|
->addCancelButton('#', 'Okay')
|
|
|
|
->appendChild(
|
2013-01-25 14:50:50 +01:00
|
|
|
phutil_tag(
|
|
|
|
'p',
|
|
|
|
array(),
|
2013-02-05 19:23:16 +01:00
|
|
|
pht('Message sent successfully.')));
|
2013-01-25 02:23:05 +01:00
|
|
|
$response = id(new AphrontDialogResponse())
|
|
|
|
->setDialog($dialog);
|
|
|
|
} else {
|
|
|
|
$uri = $this->getApplicationURI($conpherence->getID());
|
|
|
|
$response = id(new AphrontRedirectResponse())
|
|
|
|
->setURI($uri);
|
|
|
|
}
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$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();
|
|
|
|
if ($request->isAjax()) {
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
$form = id(new AphrontDialogView())
|
|
|
|
->setSubmitURI($submit_uri)
|
|
|
|
->addSubmitButton()
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
|
|
->addCancelButton($cancel_uri);
|
|
|
|
} else {
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setID('conpherence-message-pane')
|
|
|
|
->setAction($submit_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
$form
|
|
|
|
->setUser($user)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setName('participants')
|
|
|
|
->setValue($participant_handles)
|
|
|
|
->setUser($user)
|
|
|
|
->setDatasource('/typeahead/common/users/')
|
|
|
|
->setLabel(pht('To'))
|
2013-02-19 22:33:10 +01:00
|
|
|
->setError($e_participants))
|
2013-01-25 02:23:05 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new PhabricatorRemarkupControl())
|
|
|
|
->setName('message')
|
|
|
|
->setValue($message)
|
|
|
|
->setLabel(pht('Message'))
|
|
|
|
->setPlaceHolder(pht('Drag and drop to include files...'))
|
2013-02-19 22:33:10 +01:00
|
|
|
->setError($e_message));
|
2013-01-25 02:23:05 +01:00
|
|
|
|
|
|
|
if ($request->isAjax()) {
|
|
|
|
$form->setTitle($title);
|
|
|
|
return id(new AphrontDialogResponse())
|
|
|
|
->setDialog($form);
|
|
|
|
}
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue(pht('Submit'))
|
2013-02-19 22:33:10 +01:00
|
|
|
->addCancelButton($cancel_uri));
|
2013-01-25 02:23:05 +01:00
|
|
|
|
|
|
|
$this->loadStartingConpherences();
|
|
|
|
$this->setSelectedConpherencePHID(null);
|
|
|
|
$this->initJavelinBehaviors();
|
|
|
|
$nav = $this->buildSideNavView('new');
|
|
|
|
$header = id(new PhabricatorHeaderView())
|
|
|
|
->setHeader($title);
|
|
|
|
|
|
|
|
$nav->appendChild(
|
|
|
|
array(
|
|
|
|
$header,
|
|
|
|
$error_view,
|
|
|
|
$form,
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
$nav,
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
'device' => true,
|
2013-02-19 22:33:10 +01:00
|
|
|
));
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
}
|