@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 180 lines 4.8 kB view raw
1<?php 2 3final class ConpherenceThreadListView extends AphrontView { 4 5 const SEE_ALL_LIMIT = 16; 6 7 private $baseURI; 8 private $threads; 9 10 /** 11 * @param array<ConpherenceThread> $threads 12 */ 13 public function setThreads(array $threads) { 14 assert_instances_of($threads, ConpherenceThread::class); 15 $this->threads = $threads; 16 return $this; 17 } 18 19 public function setBaseURI($base_uri) { 20 $this->baseURI = $base_uri; 21 return $this; 22 } 23 24 public function render() { 25 require_celerity_resource('conpherence-menu-css'); 26 27 $viewer = $this->getViewer(); 28 $can_create_room = PhabricatorPolicyFilter::hasCapability( 29 $viewer, 30 PhabricatorApplication::getByClass( 31 PhabricatorConpherenceApplication::class), 32 ConpherenceCreateRoomCapability::CAPABILITY); 33 34 $menu = id(new PHUIListView()) 35 ->addClass('conpherence-menu') 36 ->setID('conpherence-menu'); 37 38 $header = $this->buildHeaderItemView(); 39 $menu->addMenuItem($header); 40 41 // Blank State NUX 42 if (empty($this->threads)) { 43 $join_item = id(new PHUIListItemView()) 44 ->setType(PHUIListItemView::TYPE_LINK) 45 ->setHref('/conpherence/search/') 46 ->setName(pht('Join a Room')); 47 $menu->addMenuItem($join_item); 48 49 $create_item = id(new PHUIListItemView()) 50 ->setType(PHUIListItemView::TYPE_LINK) 51 ->setHref('/conpherence/new/') 52 ->setWorkflow(true) 53 ->setDisabled(!$can_create_room) 54 ->setName(pht('Create a Room')); 55 $menu->addMenuItem($create_item); 56 } 57 58 $rooms = $this->buildRoomItems($this->threads); 59 foreach ($rooms as $room) { 60 $menu->addMenuItem($room); 61 } 62 63 $menu = phutil_tag_div('phabricator-side-menu', $menu); 64 $menu = phutil_tag_div('phui-basic-nav', $menu); 65 66 return $menu; 67 } 68 69 private function renderThreadItem( 70 ConpherenceThread $thread) { 71 72 $user = $this->getUser(); 73 $data = $thread->getDisplayData($user); 74 $dom_id = $thread->getPHID().'-nav-item'; 75 76 return id(new PHUIListItemView()) 77 ->setName($data['title']) 78 ->setHref('/'.$thread->getMonogram()) 79 ->setProfileImage($data['image']) 80 ->setCount($data['unread_count']) 81 ->setType(PHUIListItemView::TYPE_CUSTOM) 82 ->setID($thread->getPHID().'-nav-item') 83 ->addSigil('conpherence-menu-click') 84 ->setMetadata( 85 array( 86 'title' => $data['title'], 87 'id' => $dom_id, 88 'threadID' => $thread->getID(), 89 'theme' => $data['theme'], 90 )); 91 } 92 93 private function buildRoomItems(array $threads) { 94 95 $items = array(); 96 $show_threads = $threads; 97 $all_threads = false; 98 if (count($threads) > self::SEE_ALL_LIMIT) { 99 $show_threads = array_slice($threads, 0, self::SEE_ALL_LIMIT); 100 $all_threads = true; 101 } 102 103 foreach ($show_threads as $thread) { 104 $items[] = $this->renderThreadItem($thread); 105 } 106 107 // Send them to application search here 108 if ($all_threads) { 109 $items[] = id(new PHUIListItemView()) 110 ->setType(PHUIListItemView::TYPE_LINK) 111 ->setHref('/conpherence/search/query/participant/') 112 ->setIcon('fa-external-link') 113 ->setName(pht('See All Joined')); 114 } 115 116 return $items; 117 } 118 119 private function buildHeaderItemView() { 120 $viewer = $this->getViewer(); 121 $can_create_room = PhabricatorPolicyFilter::hasCapability( 122 $viewer, 123 PhabricatorApplication::getByClass( 124 PhabricatorConpherenceApplication::class), 125 ConpherenceCreateRoomCapability::CAPABILITY); 126 127 $rooms = phutil_tag( 128 'a', 129 array( 130 'class' => 'room-list-href', 131 'href' => '/conpherence/search/', 132 ), 133 pht('Rooms')); 134 135 $new_icon = id(new PHUIIconView()) 136 ->setIcon('fa-plus-square') 137 ->addSigil('has-tooltip') 138 ->setHref('/conpherence/edit/') 139 ->setWorkflow(true) 140 ->setMetaData(array( 141 'tip' => pht('New Room'), 142 )); 143 144 if (!$can_create_room) { 145 $new_icon->setColor('lightgreytext'); 146 } 147 148 $search_icon = id(new PHUIIconView()) 149 ->setIcon('fa-search') 150 ->addSigil('has-tooltip') 151 ->setHref('/conpherence/search/') 152 ->setMetaData(array( 153 'tip' => pht('Search Rooms'), 154 )); 155 156 $icons = phutil_tag( 157 'span', 158 array( 159 'class' => 'room-list-icons', 160 ), 161 array( 162 $new_icon, 163 $search_icon, 164 )); 165 166 $new_icon = id(new PHUIIconView()) 167 ->setIcon('fa-plus-square') 168 ->setHref('/conpherence/new/') 169 ->setWorkflow(true); 170 171 $custom = phutil_tag_div('grouped', array($rooms, $icons)); 172 173 $item = id(new PHUIListItemView()) 174 ->setType(PHUIListItemView::TYPE_CUSTOM) 175 ->setName($custom) 176 ->addClass('conpherence-room-list-header'); 177 return $item; 178 } 179 180}