| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 12:52:30 -07:00
										 |  |  | final class ConpherenceUpdateController | 
					
						
							|  |  |  |   extends ConpherenceController { | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   private $conpherenceID; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public function setConpherenceID($conpherence_id) { | 
					
						
							|  |  |  |     $this->conpherenceID = $conpherence_id; | 
					
						
							|  |  |  |     return $this; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   public function getConpherenceID() { | 
					
						
							|  |  |  |     return $this->conpherenceID; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   public function willProcessRequest(array $data) { | 
					
						
							|  |  |  |     $this->setConpherenceID(idx($data, 'id')); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public function processRequest() { | 
					
						
							|  |  |  |     $request = $this->getRequest(); | 
					
						
							|  |  |  |     $user = $request->getUser(); | 
					
						
							|  |  |  |     $conpherence_id = $this->getConpherenceID(); | 
					
						
							|  |  |  |     if (!$conpherence_id) { | 
					
						
							|  |  |  |       return new Aphront404Response(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $conpherence = id(new ConpherenceThreadQuery()) | 
					
						
							|  |  |  |       ->setViewer($user) | 
					
						
							|  |  |  |       ->withIDs(array($conpherence_id)) | 
					
						
							| 
									
										
										
										
											2013-04-08 11:13:35 -07:00
										 |  |  |       ->needFilePHIDs(true) | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |       ->executeOne(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |     $action = $request->getStr('action', ConpherenceUpdateActions::METADATA); | 
					
						
							| 
									
										
										
										
											2014-06-11 13:52:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 15:45:36 -08:00
										 |  |  |     $latest_transaction_id = null; | 
					
						
							| 
									
										
										
										
											2014-05-16 08:24:25 -07:00
										 |  |  |     $response_mode = $request->isAjax() ? 'ajax' : 'redirect'; | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |     $error_view = null; | 
					
						
							| 
									
										
										
										
											2013-01-26 17:14:58 -08:00
										 |  |  |     $e_file = array(); | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |     $errors = array(); | 
					
						
							| 
									
										
										
										
											2014-02-17 15:57:13 -08:00
										 |  |  |     $delete_draft = false; | 
					
						
							| 
									
										
										
										
											2014-02-24 11:56:04 -08:00
										 |  |  |     $xactions = array(); | 
					
						
							| 
									
										
										
										
											2014-06-11 13:52:15 -07:00
										 |  |  |     if ($request->isFormPost() || ($action == ConpherenceUpdateActions::LOAD)) { | 
					
						
							| 
									
										
										
										
											2013-01-26 19:56:39 -08:00
										 |  |  |       $editor = id(new ConpherenceEditor()) | 
					
						
							| 
									
										
										
										
											2013-01-29 16:53:57 -08:00
										 |  |  |         ->setContinueOnNoEffect($request->isContinueRequest()) | 
					
						
							| 
									
										
										
										
											2013-05-24 10:48:34 -07:00
										 |  |  |         ->setContentSourceFromRequest($request) | 
					
						
							| 
									
										
										
										
											2013-01-26 19:56:39 -08:00
										 |  |  |         ->setActor($user); | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       switch ($action) { | 
					
						
							| 
									
										
										
										
											2014-02-17 15:57:13 -08:00
										 |  |  |         case ConpherenceUpdateActions::DRAFT: | 
					
						
							|  |  |  |           $draft = PhabricatorDraft::newFromUserAndKey( | 
					
						
							|  |  |  |             $user, | 
					
						
							|  |  |  |             $conpherence->getPHID()); | 
					
						
							|  |  |  |           $draft->setDraft($request->getStr('text')); | 
					
						
							|  |  |  |           $draft->replaceOrDelete(); | 
					
						
							| 
									
										
											  
											
												Fix some issues where Conpherence would make to many draft requests
Summary:
A few minor fixes:
  - When we build a tag with `"meta" => null`, strip the attribute like we do for all other attributes. Previously, we would actually set the metadata to `null`. This happened with the Conpherence form.
  - Just respond to the draft request with an empty (but valid) response, instead of building a dialog.
  - `PhabricatorShapedRequest` is confusingly named and I should have caught this in review, but the basic shape of it is:
    - You make one object.
    - You call `trigger()` when stuff changes (e.g., a keystroke).
    - It manages making a small number of requests (e.g., one request after the user stops typing for a moment).
  - The way it was being used previously would incorrectly send a request for every keystroke.
I think I'm going to simplify `ShapedRequest` and merge it into some larger queue for T430.
Test Plan: Typed some text, no longer saw a flurry of requests. Reloaded page, still saw draft text.
Reviewers: btrahan, chad
Reviewed By: chad
CC: aran, chad
Differential Revision: https://secure.phabricator.com/D8380
											
										 
											2014-03-01 11:23:08 -08:00
										 |  |  |           return new AphrontAjaxResponse(); | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |         case ConpherenceUpdateActions::MESSAGE: | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |           $message = $request->getStr('text'); | 
					
						
							| 
									
										
										
										
											2013-01-26 19:56:39 -08:00
										 |  |  |           $xactions = $editor->generateTransactionsFromText( | 
					
						
							| 
									
										
										
										
											2014-04-23 16:30:38 -07:00
										 |  |  |             $user, | 
					
						
							| 
									
										
										
										
											2013-01-26 19:56:39 -08:00
										 |  |  |             $conpherence, | 
					
						
							| 
									
										
										
										
											2013-02-19 13:33:10 -08:00
										 |  |  |             $message); | 
					
						
							| 
									
										
										
										
											2014-02-17 15:57:13 -08:00
										 |  |  |           $delete_draft = true; | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |           break; | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |         case ConpherenceUpdateActions::ADD_PERSON: | 
					
						
							| 
									
										
										
										
											2013-05-29 17:21:07 -07:00
										 |  |  |           $person_phids = $request->getArr('add_person'); | 
					
						
							|  |  |  |           if (!empty($person_phids)) { | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |             $xactions[] = id(new ConpherenceTransaction()) | 
					
						
							|  |  |  |               ->setTransactionType( | 
					
						
							|  |  |  |                 ConpherenceTransactionType::TYPE_PARTICIPANTS) | 
					
						
							| 
									
										
										
										
											2013-05-29 17:21:07 -07:00
										 |  |  |               ->setNewValue(array('+' => $person_phids)); | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |           } | 
					
						
							|  |  |  |           break; | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |         case ConpherenceUpdateActions::REMOVE_PERSON: | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |           if (!$request->isContinueRequest()) { | 
					
						
							|  |  |  |             // do nothing; we'll display a confirmation dialogue instead
 | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           $person_phid = $request->getStr('remove_person'); | 
					
						
							|  |  |  |           if ($person_phid && $person_phid == $user->getPHID()) { | 
					
						
							|  |  |  |             $xactions[] = id(new ConpherenceTransaction()) | 
					
						
							|  |  |  |               ->setTransactionType( | 
					
						
							|  |  |  |                 ConpherenceTransactionType::TYPE_PARTICIPANTS) | 
					
						
							|  |  |  |               ->setNewValue(array('-' => array($person_phid))); | 
					
						
							|  |  |  |             $response_mode = 'go-home'; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           break; | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |         case ConpherenceUpdateActions::NOTIFICATIONS: | 
					
						
							| 
									
										
										
										
											2013-03-26 13:30:35 -07:00
										 |  |  |           $notifications = $request->getStr('notifications'); | 
					
						
							|  |  |  |           $participant = $conpherence->getParticipant($user->getPHID()); | 
					
						
							|  |  |  |           $participant->setSettings(array('notifications' => $notifications)); | 
					
						
							|  |  |  |           $participant->save(); | 
					
						
							|  |  |  |           $result = pht( | 
					
						
							|  |  |  |             'Updated notification settings to "%s".', | 
					
						
							|  |  |  |             ConpherenceSettings::getHumanString($notifications)); | 
					
						
							|  |  |  |           return id(new AphrontAjaxResponse()) | 
					
						
							|  |  |  |             ->setContent($result); | 
					
						
							|  |  |  |           break; | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |         case ConpherenceUpdateActions::METADATA: | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |           $updated = false; | 
					
						
							| 
									
										
										
										
											2013-05-24 10:50:18 -07:00
										 |  |  |           // all metadata updates are continue requests
 | 
					
						
							| 
									
										
										
										
											2013-03-18 16:31:38 -07:00
										 |  |  |           if (!$request->isContinueRequest()) { | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 16:05:47 -07:00
										 |  |  |           $title = $request->getStr('title'); | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |           if ($title != $conpherence->getTitle()) { | 
					
						
							|  |  |  |             $xactions[] = id(new ConpherenceTransaction()) | 
					
						
							|  |  |  |               ->setTransactionType(ConpherenceTransactionType::TYPE_TITLE) | 
					
						
							|  |  |  |               ->setNewValue($title); | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |             $updated = true; | 
					
						
							| 
									
										
										
										
											2013-05-24 10:50:18 -07:00
										 |  |  |             $response_mode = 'redirect'; | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2013-03-18 16:31:38 -07:00
										 |  |  |           if (!$updated) { | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |             $errors[] = pht( | 
					
						
							|  |  |  |               'That was a non-update. Try cancel.'); | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |           } | 
					
						
							|  |  |  |           break; | 
					
						
							| 
									
										
										
										
											2014-06-11 13:52:15 -07:00
										 |  |  |         case ConpherenceUpdateActions::LOAD: | 
					
						
							|  |  |  |           $updated = false; | 
					
						
							|  |  |  |           $response_mode = 'ajax'; | 
					
						
							|  |  |  |           break; | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |         default: | 
					
						
							|  |  |  |           throw new Exception('Unknown action: '.$action); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2014-06-11 13:52:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if ($xactions || ($action == ConpherenceUpdateActions::LOAD)) { | 
					
						
							|  |  |  |         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); | 
					
						
							| 
									
										
										
										
											2014-02-17 15:57:13 -08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-06-11 13:52:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |         switch ($response_mode) { | 
					
						
							|  |  |  |           case 'ajax': | 
					
						
							|  |  |  |             $latest_transaction_id = $request->getInt('latest_transaction_id'); | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |             $content = $this->loadAndRenderUpdates( | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |               $action, | 
					
						
							| 
									
										
										
										
											2013-03-05 15:45:36 -08:00
										 |  |  |               $conpherence_id, | 
					
						
							|  |  |  |               $latest_transaction_id); | 
					
						
							|  |  |  |             return id(new AphrontAjaxResponse()) | 
					
						
							|  |  |  |               ->setContent($content); | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |             break; | 
					
						
							|  |  |  |           case 'go-home': | 
					
						
							|  |  |  |             return id(new AphrontRedirectResponse()) | 
					
						
							|  |  |  |               ->setURI($this->getApplicationURI()); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           case 'redirect': | 
					
						
							|  |  |  |           default: | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |             return id(new AphrontRedirectResponse()) | 
					
						
							|  |  |  |               ->setURI($this->getApplicationURI($conpherence->getID().'/')); | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2013-01-29 16:53:57 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($errors) { | 
					
						
							|  |  |  |       $error_view = id(new AphrontErrorView()) | 
					
						
							|  |  |  |         ->setErrors($errors); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |     switch ($action) { | 
					
						
							| 
									
										
										
										
											2013-05-29 17:21:07 -07:00
										 |  |  |       case ConpherenceUpdateActions::ADD_PERSON: | 
					
						
							|  |  |  |         $dialogue = $this->renderAddPersonDialogue($conpherence); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |       case ConpherenceUpdateActions::REMOVE_PERSON: | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |         $dialogue = $this->renderRemovePersonDialogue($conpherence); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |       case ConpherenceUpdateActions::METADATA: | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |       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().'/'))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-29 17:21:07 -07:00
										 |  |  |   private function renderAddPersonDialogue( | 
					
						
							|  |  |  |     ConpherenceThread $conpherence) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $request = $this->getRequest(); | 
					
						
							|  |  |  |     $user = $request->getUser(); | 
					
						
							|  |  |  |     $add_person = $request->getStr('add_person'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-26 11:53:11 -07:00
										 |  |  |     $form = id(new PHUIFormLayoutView()) | 
					
						
							| 
									
										
										
										
											2013-05-29 17:21:07 -07:00
										 |  |  |       ->setUser($user) | 
					
						
							| 
									
										
										
										
											2013-05-30 08:30:56 -07:00
										 |  |  |       ->setFullWidth(true) | 
					
						
							|  |  |  |       ->appendChild( | 
					
						
							|  |  |  |         id(new AphrontFormTokenizerControl()) | 
					
						
							|  |  |  |         ->setName('add_person') | 
					
						
							|  |  |  |         ->setUser($user) | 
					
						
							|  |  |  |         ->setDatasource('/typeahead/common/users/')); | 
					
						
							| 
									
										
										
										
											2013-05-29 17:21:07 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     require_celerity_resource('conpherence-update-css'); | 
					
						
							|  |  |  |     return id(new AphrontDialogView()) | 
					
						
							| 
									
										
										
										
											2013-05-30 08:30:56 -07:00
										 |  |  |       ->setTitle(pht('Add Participants')) | 
					
						
							| 
									
										
										
										
											2013-05-29 17:21:07 -07:00
										 |  |  |       ->addHiddenInput('action', 'add_person') | 
					
						
							| 
									
										
										
										
											2013-05-30 08:30:56 -07:00
										 |  |  |       ->appendChild($form); | 
					
						
							| 
									
										
										
										
											2013-05-29 17:21:07 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |   private function renderRemovePersonDialogue( | 
					
						
							|  |  |  |     ConpherenceThread $conpherence) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $request = $this->getRequest(); | 
					
						
							|  |  |  |     $user = $request->getUser(); | 
					
						
							|  |  |  |     $remove_person = $request->getStr('remove_person'); | 
					
						
							|  |  |  |     $participants = $conpherence->getParticipants(); | 
					
						
							|  |  |  |     $message = pht( | 
					
						
							|  |  |  |       'Are you sure you want to remove yourself from this conpherence? '); | 
					
						
							|  |  |  |     if (count($participants) == 1) { | 
					
						
							|  |  |  |       $message .= pht( | 
					
						
							|  |  |  |         'The conpherence will be inaccessible forever and ever.'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       $message .= pht( | 
					
						
							|  |  |  |         'Someone else in the conpherence can add you back later.'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     $body = phutil_tag( | 
					
						
							|  |  |  |       'p', | 
					
						
							|  |  |  |       array( | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       $message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     require_celerity_resource('conpherence-update-css'); | 
					
						
							|  |  |  |     return id(new AphrontDialogView()) | 
					
						
							| 
									
										
										
										
											2013-05-30 08:30:56 -07:00
										 |  |  |       ->setTitle(pht('Remove Participants')) | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |       ->addHiddenInput('action', 'remove_person') | 
					
						
							|  |  |  |       ->addHiddenInput('__continue__', true) | 
					
						
							|  |  |  |       ->addHiddenInput('remove_person', $remove_person) | 
					
						
							|  |  |  |       ->appendChild($body); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |   private function renderMetadataDialogue( | 
					
						
							|  |  |  |     ConpherenceThread $conpherence, | 
					
						
							|  |  |  |     $error_view) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-26 11:53:11 -07:00
										 |  |  |     $form = id(new PHUIFormLayoutView()) | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |       ->appendChild($error_view) | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |       ->appendChild( | 
					
						
							|  |  |  |         id(new AphrontFormTextControl()) | 
					
						
							|  |  |  |         ->setLabel(pht('Title')) | 
					
						
							|  |  |  |         ->setName('title') | 
					
						
							| 
									
										
										
										
											2013-02-19 13:33:10 -08:00
										 |  |  |         ->setValue($conpherence->getTitle())); | 
					
						
							| 
									
										
										
										
											2013-02-06 14:03:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |     require_celerity_resource('conpherence-update-css'); | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |     return id(new AphrontDialogView()) | 
					
						
							|  |  |  |       ->setTitle(pht('Update Conpherence')) | 
					
						
							|  |  |  |       ->addHiddenInput('action', 'metadata') | 
					
						
							|  |  |  |       ->addHiddenInput('__continue__', true) | 
					
						
							|  |  |  |       ->appendChild($form); | 
					
						
							| 
									
										
										
										
											2013-01-24 17:23:05 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-03-05 15:45:36 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |   private function loadAndRenderUpdates( | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |     $action, | 
					
						
							| 
									
										
										
										
											2013-03-05 15:45:36 -08:00
										 |  |  |     $conpherence_id, | 
					
						
							|  |  |  |     $latest_transaction_id) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |     $need_widget_data = false; | 
					
						
							|  |  |  |     $need_transactions = false; | 
					
						
							|  |  |  |     switch ($action) { | 
					
						
							|  |  |  |       case ConpherenceUpdateActions::METADATA: | 
					
						
							| 
									
										
										
										
											2014-06-11 13:52:15 -07:00
										 |  |  |       case ConpherenceUpdateActions::LOAD: | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |         $need_transactions = true; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case ConpherenceUpdateActions::MESSAGE: | 
					
						
							|  |  |  |       case ConpherenceUpdateActions::ADD_PERSON: | 
					
						
							|  |  |  |         $need_transactions = true; | 
					
						
							|  |  |  |         $need_widget_data = true; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case ConpherenceUpdateActions::REMOVE_PERSON: | 
					
						
							|  |  |  |       case ConpherenceUpdateActions::NOTIFICATIONS: | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-03-15 23:41:36 -07:00
										 |  |  |     $user = $this->getRequest()->getUser(); | 
					
						
							|  |  |  |     $conpherence = id(new ConpherenceThreadQuery()) | 
					
						
							|  |  |  |       ->setViewer($user) | 
					
						
							| 
									
										
										
										
											2013-04-18 16:54:06 -07:00
										 |  |  |       ->setAfterTransactionID($latest_transaction_id) | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |       ->needWidgetData($need_widget_data) | 
					
						
							|  |  |  |       ->needTransactions($need_transactions) | 
					
						
							| 
									
										
										
										
											2013-03-15 23:41:36 -07:00
										 |  |  |       ->withIDs(array($conpherence_id)) | 
					
						
							|  |  |  |       ->executeOne(); | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |     if ($need_transactions) { | 
					
						
							|  |  |  |       $data = $this->renderConpherenceTransactions($conpherence); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       $data = array(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     $rendered_transactions = idx($data, 'transactions'); | 
					
						
							|  |  |  |     $new_latest_transaction_id = idx($data, 'latest_transaction_id'); | 
					
						
							| 
									
										
										
										
											2013-03-05 15:45:36 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-02 09:32:40 -07:00
										 |  |  |     $widget_uri = $this->getApplicationURI('update/'.$conpherence->getID().'/'); | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |     $nav_item = null; | 
					
						
							|  |  |  |     $header = null; | 
					
						
							|  |  |  |     $people_widget = null; | 
					
						
							|  |  |  |     $file_widget = null; | 
					
						
							|  |  |  |     switch ($action) { | 
					
						
							|  |  |  |       case ConpherenceUpdateActions::METADATA: | 
					
						
							|  |  |  |         $header = $this->buildHeaderPaneContent($conpherence); | 
					
						
							|  |  |  |         $nav_item = id(new ConpherenceThreadListView()) | 
					
						
							|  |  |  |           ->setUser($user) | 
					
						
							|  |  |  |           ->setBaseURI($this->getApplicationURI()) | 
					
						
							|  |  |  |           ->renderSingleThread($conpherence); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case ConpherenceUpdateActions::MESSAGE: | 
					
						
							|  |  |  |         $file_widget = id(new ConpherenceFileWidgetView()) | 
					
						
							|  |  |  |           ->setUser($this->getRequest()->getUser()) | 
					
						
							|  |  |  |           ->setConpherence($conpherence) | 
					
						
							|  |  |  |           ->setUpdateURI($widget_uri); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case ConpherenceUpdateActions::ADD_PERSON: | 
					
						
							|  |  |  |         $people_widget = id(new ConpherencePeopleWidgetView()) | 
					
						
							|  |  |  |           ->setUser($user) | 
					
						
							|  |  |  |           ->setConpherence($conpherence) | 
					
						
							|  |  |  |           ->setUpdateURI($widget_uri); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case ConpherenceUpdateActions::REMOVE_PERSON: | 
					
						
							|  |  |  |       case ConpherenceUpdateActions::NOTIFICATIONS: | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-11 15:07:53 -10:00
										 |  |  |     $people_html = null; | 
					
						
							|  |  |  |     if ($people_widget) { | 
					
						
							|  |  |  |       $people_html = hsprintf('%s', $people_widget->render()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-03-15 23:41:36 -07:00
										 |  |  |     $content = array( | 
					
						
							| 
									
										
										
										
											2013-05-30 12:42:55 -07:00
										 |  |  |       'transactions' => hsprintf('%s', $rendered_transactions), | 
					
						
							| 
									
										
										
										
											2013-03-15 23:41:36 -07:00
										 |  |  |       'latest_transaction_id' => $new_latest_transaction_id, | 
					
						
							| 
									
										
										
										
											2013-04-01 12:52:30 -07:00
										 |  |  |       'nav_item' => hsprintf('%s', $nav_item), | 
					
						
							| 
									
										
										
										
											2013-03-15 23:41:36 -07:00
										 |  |  |       'conpherence_phid' => $conpherence->getPHID(), | 
					
						
							| 
									
										
										
										
											2013-04-01 12:52:30 -07:00
										 |  |  |       'header' => hsprintf('%s', $header), | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  |       'file_widget' => $file_widget ? $file_widget->render() : null, | 
					
						
							| 
									
										
										
										
											2013-06-11 15:07:53 -10:00
										 |  |  |       'people_widget' => $people_html, | 
					
						
							| 
									
										
										
										
											2013-03-15 23:41:36 -07:00
										 |  |  |     ); | 
					
						
							| 
									
										
										
										
											2013-04-10 11:37:04 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-15 23:41:36 -07:00
										 |  |  |     return $content; | 
					
						
							| 
									
										
										
										
											2013-03-08 10:40:06 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-03-15 23:41:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |