@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 179 lines 5.6 kB view raw
1<?php 2 3final class ConpherenceListController extends ConpherenceController { 4 5 const SELECTED_MODE = 'selected'; 6 const UNSELECTED_MODE = 'unselected'; 7 8 /** 9 * Two main modes of operation... 10 * 11 * 1 - /conpherence/ - UNSELECTED_MODE 12 * 2 - /conpherence/<id>/ - SELECTED_MODE 13 * 14 * UNSELECTED_MODE is not an Ajax request while the other two are Ajax 15 * requests. 16 */ 17 private function determineMode() { 18 $request = $this->getRequest(); 19 20 $mode = self::UNSELECTED_MODE; 21 if ($request->isAjax()) { 22 $mode = self::SELECTED_MODE; 23 } 24 25 return $mode; 26 } 27 28 public function shouldAllowPublic() { 29 return true; 30 } 31 32 public function handleRequest(AphrontRequest $request) { 33 $user = $request->getUser(); 34 $title = pht('Conpherence'); 35 $conpherence = null; 36 37 $limit = ConpherenceThreadListView::SEE_ALL_LIMIT + 1; 38 $all_participation = array(); 39 40 $mode = $this->determineMode(); 41 switch ($mode) { 42 case self::SELECTED_MODE: 43 $conpherence_id = $request->getURIData('id'); 44 $conpherence = id(new ConpherenceThreadQuery()) 45 ->setViewer($user) 46 ->withIDs(array($conpherence_id)) 47 ->executeOne(); 48 if (!$conpherence) { 49 return new Aphront404Response(); 50 } 51 if ($conpherence->getTitle()) { 52 $title = $conpherence->getTitle(); 53 } 54 $cursor = $conpherence->getParticipantIfExists($user->getPHID()); 55 $data = $this->loadDefaultParticipation($limit); 56 $all_participation = $data['all_participation']; 57 if (!$cursor) { 58 $menu_participation = id(new ConpherenceParticipant()) 59 ->makeEphemeral() 60 ->setConpherencePHID($conpherence->getPHID()) 61 ->setParticipantPHID($user->getPHID()); 62 } else { 63 $menu_participation = $cursor; 64 } 65 66 // check to see if the loaded conpherence is going to show up 67 // within the SEE_ALL_LIMIT amount of conpherences. 68 // If its not there, then we just pre-pend it as the "first" 69 // conpherence so folks have a navigation item in the menu. 70 $count = 0; 71 $found = false; 72 foreach ($all_participation as $phid => $curr_participation) { 73 if ($conpherence->getPHID() == $phid) { 74 $found = true; 75 break; 76 } 77 $count++; 78 if ($count > ConpherenceThreadListView::SEE_ALL_LIMIT) { 79 break; 80 } 81 } 82 if (!$found) { 83 $all_participation = 84 array($conpherence->getPHID() => $menu_participation) + 85 $all_participation; 86 } 87 break; 88 case self::UNSELECTED_MODE: 89 default: 90 $data = $this->loadDefaultParticipation($limit); 91 $all_participation = $data['all_participation']; 92 if ($all_participation) { 93 $conpherence_id = head($all_participation)->getConpherencePHID(); 94 $conpherence = id(new ConpherenceThreadQuery()) 95 ->setViewer($user) 96 ->withPHIDs(array($conpherence_id)) 97 ->needProfileImage(true) 98 ->executeOne(); 99 } 100 // If $conpherence is null, NUX state will render 101 break; 102 } 103 104 $threads = $this->loadConpherenceThreadData($all_participation); 105 106 $thread_view = id(new ConpherenceThreadListView()) 107 ->setViewer($user) 108 ->setBaseURI($this->getApplicationURI()) 109 ->setThreads($threads); 110 111 switch ($mode) { 112 case self::SELECTED_MODE: 113 $response = id(new AphrontAjaxResponse())->setContent($thread_view); 114 break; 115 case self::UNSELECTED_MODE: 116 default: 117 $layout = id(new ConpherenceLayoutView()) 118 ->setUser($user) 119 ->setBaseURI($this->getApplicationURI()) 120 ->setThreadView($thread_view) 121 ->setRole('list'); 122 if ($conpherence) { 123 $layout->setThread($conpherence); 124 } else { 125 // make a dummy conpherence so we can render something 126 $conpherence = ConpherenceThread::initializeNewRoom($user); 127 $conpherence->attachHandles(array()); 128 $conpherence->attachTransactions(array()); 129 $conpherence->makeEphemeral(); 130 } 131 $policy_objects = id(new PhabricatorPolicyQuery()) 132 ->setViewer($user) 133 ->setObject($conpherence) 134 ->execute(); 135 $layout->setHeader($this->buildHeaderPaneContent( 136 $conpherence)); 137 $response = $this->newPage() 138 ->setTitle($title) 139 ->appendChild($layout); 140 break; 141 } 142 143 return $response; 144 145 } 146 147 private function loadDefaultParticipation($limit) { 148 $viewer = $this->getRequest()->getUser(); 149 150 $all_participation = id(new ConpherenceParticipantQuery()) 151 ->withParticipantPHIDs(array($viewer->getPHID())) 152 ->setLimit($limit) 153 ->execute(); 154 $all_participation = mpull($all_participation, null, 'getConpherencePHID'); 155 156 return array( 157 'all_participation' => $all_participation, 158 ); 159 } 160 161 private function loadConpherenceThreadData($participation) { 162 $user = $this->getRequest()->getUser(); 163 $conpherence_phids = array_keys($participation); 164 $conpherences = array(); 165 if ($conpherence_phids) { 166 $conpherences = id(new ConpherenceThreadQuery()) 167 ->setViewer($user) 168 ->withPHIDs($conpherence_phids) 169 ->needProfileImage(true) 170 ->execute(); 171 172 // this will re-sort by participation data 173 $conpherences = array_select_keys($conpherences, $conpherence_phids); 174 } 175 176 return $conpherences; 177 } 178 179}