@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Show badges on timelines

Summary: Ref T8941.

Test Plan: {F659486}

Reviewers: chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T8941

Differential Revision: https://secure.phabricator.com/D13708

+105 -13
+9 -4
src/applications/transactions/view/PhabricatorApplicationTransactionView.php
··· 211 211 throw new PhutilInvalidStateException('setObjectPHID'); 212 212 } 213 213 214 - $view = new PHUITimelineView(); 215 - $view->setShouldTerminate($this->shouldTerminate); 216 - $view->setQuoteTargetID($this->getQuoteTargetID()); 217 - $view->setQuoteRef($this->getQuoteRef()); 214 + $view = id(new PHUITimelineView()) 215 + ->setUser($this->getUser()) 216 + ->setShouldTerminate($this->shouldTerminate) 217 + ->setQuoteTargetID($this->getQuoteTargetID()) 218 + ->setQuoteRef($this->getQuoteRef()); 219 + 218 220 $events = $this->buildEvents($with_hiding); 219 221 foreach ($events as $event) { 220 222 $view->addEvent($event); 221 223 } 224 + 222 225 if ($this->getPager()) { 223 226 $view->setPager($this->getPager()); 224 227 } 228 + 225 229 if ($this->getRenderData()) { 226 230 $view->setRenderData($this->getRenderData()); 227 231 } ··· 394 398 395 399 $event = id(new PHUITimelineEventView()) 396 400 ->setUser($viewer) 401 + ->setAuthorPHID($xaction->getAuthorPHID()) 397 402 ->setTransactionPHID($xaction->getPHID()) 398 403 ->setUserHandle($xaction->getHandle($xaction->getAuthorPHID())) 399 404 ->setIcon($xaction->getIcon())
+7 -9
src/view/phui/PHUIBadgeMiniView.php
··· 46 46 } 47 47 48 48 return array( 49 - 'class' => implode(' ', $classes), 50 - 'sigil' => 'has-tooltip', 51 - 'href' => $this->href, 52 - 'meta' => array( 53 - 'tip' => $this->header, 54 - ), 55 - ); 49 + 'class' => implode(' ', $classes), 50 + 'sigil' => 'has-tooltip', 51 + 'href' => $this->href, 52 + 'meta' => array( 53 + 'tip' => $this->header, 54 + ), 55 + ); 56 56 } 57 57 58 58 protected function getTagContent() { 59 - 60 59 return id(new PHUIIconView()) 61 60 ->setIconFont($this->icon); 62 - 63 61 } 64 62 65 63 }
+10
src/view/phui/PHUITimelineEventView.php
··· 26 26 private $quoteRef; 27 27 private $reallyMajorEvent; 28 28 private $hideCommentOptions = false; 29 + private $authorPHID; 29 30 private $badges = array(); 31 + 32 + public function setAuthorPHID($author_phid) { 33 + $this->authorPHID = $author_phid; 34 + return $this; 35 + } 36 + 37 + public function getAuthorPHID() { 38 + return $this->authorPHID; 39 + } 30 40 31 41 public function setQuoteRef($quote_ref) { 32 42 $this->quoteRef = $quote_ref;
+79
src/view/phui/PHUITimelineView.php
··· 145 145 } 146 146 147 147 if ($show) { 148 + $this->prepareBadgeData($show); 148 149 $events[] = phutil_implode_html($spacer, $show); 149 150 } 150 151 ··· 181 182 'the-worlds-end', 182 183 ), 183 184 ''); 185 + } 186 + 187 + private function prepareBadgeData(array $events) { 188 + assert_instances_of($events, 'PHUITimelineEventView'); 189 + 190 + $viewer = $this->getUser(); 191 + $can_use_badges = PhabricatorApplication::isClassInstalledForViewer( 192 + 'PhabricatorBadgesApplication', 193 + $viewer); 194 + if (!$can_use_badges) { 195 + return; 196 + } 197 + 198 + $user_phid_type = PhabricatorPeopleUserPHIDType::TYPECONST; 199 + $badge_edge_type = PhabricatorRecipientHasBadgeEdgeType::EDGECONST; 200 + 201 + $user_phids = array(); 202 + foreach ($events as $key => $event) { 203 + if (!$event->hasChildren()) { 204 + // This is a minor event, so we don't have space to show badges. 205 + unset($events[$key]); 206 + continue; 207 + } 208 + 209 + $author_phid = $event->getAuthorPHID(); 210 + if (!$author_phid) { 211 + unset($events[$key]); 212 + continue; 213 + } 214 + 215 + if (phid_get_type($author_phid) != $user_phid_type) { 216 + // This is likely an application actor, like "Herald" or "Harbormaster". 217 + // They can't have badges. 218 + unset($events[$key]); 219 + continue; 220 + } 221 + 222 + $user_phids[$author_phid] = $author_phid; 223 + } 224 + 225 + if (!$user_phids) { 226 + return; 227 + } 228 + 229 + $edges = id(new PhabricatorEdgeQuery()) 230 + ->withSourcePHIDs($user_phids) 231 + ->withEdgeTypes(array($badge_edge_type)); 232 + $edges->execute(); 233 + 234 + $badge_phids = $edges->getDestinationPHIDs(); 235 + if (!$badge_phids) { 236 + return; 237 + } 238 + 239 + $all_badges = id(new PhabricatorBadgesQuery()) 240 + ->setViewer($viewer) 241 + ->withPHIDs($badge_phids) 242 + ->execute(); 243 + $all_badges = mpull($all_badges, null, 'getPHID'); 244 + 245 + foreach ($events as $event) { 246 + $author_phid = $event->getAuthorPHID(); 247 + $event_phids = $edges->getDestinationPHIDs(array($author_phid)); 248 + $badges = array_select_keys($all_badges, $event_phids); 249 + 250 + // TODO: Pick the "best" badges in some smart way. For now, just pick 251 + // the first two. 252 + $badges = array_slice($badges, 0, 2); 253 + foreach ($badges as $badge) { 254 + $badge_view = id(new PHUIBadgeMiniView()) 255 + ->setIcon($badge->getIcon()) 256 + ->setQuality($badge->getQuality()) 257 + ->setHeader($badge->getName()) 258 + ->setHref('/badges/view/'.$badge->getID()); 259 + 260 + $event->addBadge($badge_view); 261 + } 262 + } 184 263 } 185 264 186 265 }