@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.

UIEvents - add support for "subscribers property"

Summary: Fixes T3487 and reduces a bit of code duplication.

Test Plan: viewed legalpad, macro, and pholio and saw proper subscriber properties

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T3487

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

+48 -65
+2 -17
src/applications/legalpad/controller/LegalpadDocumentViewController.php
··· 68 68 ->setHeader($title); 69 69 70 70 $actions = $this->buildActionView($document); 71 - $properties = $this->buildPropertyView($document, $engine, $subscribers); 71 + $properties = $this->buildPropertyView($document, $engine); 72 72 73 73 $comment_form_id = celerity_generate_unique_node_id(); 74 74 ··· 146 146 147 147 private function buildPropertyView( 148 148 LegalpadDocument $document, 149 - PhabricatorMarkupEngine $engine, 150 - array $subscribers) { 149 + PhabricatorMarkupEngine $engine) { 151 150 152 151 $user = $this->getRequest()->getUser(); 153 152 ··· 184 183 $properties->addProperty( 185 184 pht('Visible To'), 186 185 $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); 187 - 188 - if ($subscribers) { 189 - $sub_view = array(); 190 - foreach ($subscribers as $subscriber) { 191 - $sub_view[] = $this->getHandle($subscriber)->renderLink(); 192 - } 193 - $sub_view = phutil_implode_html(', ', $sub_view); 194 - } else { 195 - $sub_view = phutil_tag('em', array(), pht('None')); 196 - } 197 - 198 - $properties->addProperty( 199 - pht('Subscribers'), 200 - $sub_view); 201 186 202 187 $properties->invokeWillRenderEvent(); 203 188
+6 -21
src/applications/macro/controller/PhabricatorMacroViewController.php
··· 26 26 $title_short = pht('Macro "%s"', $macro->getName()); 27 27 $title_long = pht('Image Macro "%s"', $macro->getName()); 28 28 29 - $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( 30 - $macro->getPHID()); 31 - 32 - $this->loadHandles($subscribers); 33 29 $actions = $this->buildActionView($macro); 34 30 35 31 $crumbs = $this->buildApplicationCrumbs(); ··· 39 35 ->setHref($this->getApplicationURI('/view/'.$macro->getID().'/')) 40 36 ->setName($title_short)); 41 37 42 - $properties = $this->buildPropertyView($macro, $file, $subscribers); 38 + $properties = $this->buildPropertyView($macro, $file); 43 39 44 40 $xactions = id(new PhabricatorMacroTransactionQuery()) 45 41 ->setViewer($request->getUser()) ··· 140 136 141 137 private function buildPropertyView( 142 138 PhabricatorFileImageMacro $macro, 143 - PhabricatorFile $file = null, 144 - array $subscribers) { 139 + PhabricatorFile $file = null) { 145 140 146 - $view = new PhabricatorPropertyListView(); 141 + $view = id(new PhabricatorPropertyListView()) 142 + ->setUser($this->getRequest()->getUser()) 143 + ->setObject($macro); 147 144 148 - if ($subscribers) { 149 - $sub_view = array(); 150 - foreach ($subscribers as $subscriber) { 151 - $sub_view[] = $this->getHandle($subscriber)->renderLink(); 152 - } 153 - $sub_view = phutil_implode_html(', ', $sub_view); 154 - } else { 155 - $sub_view = phutil_tag('em', array(), pht('None')); 156 - } 157 - 158 - $view->addProperty( 159 - pht('Subscribers'), 160 - $sub_view); 145 + $view->invokeWillRenderEvent(); 161 146 162 147 if ($file) { 163 148 $view->addImageContent(
+3 -26
src/applications/pholio/controller/PholioMockViewController.php
··· 37 37 ->withObjectPHIDs(array($mock->getPHID())) 38 38 ->execute(); 39 39 40 - $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( 41 - $mock->getPHID()); 42 - 43 - $phids = array(); 44 - $phids[] = $mock->getAuthorPHID(); 45 - foreach ($subscribers as $subscriber) { 46 - $phids[] = $subscriber; 47 - } 40 + $phids = array($mock->getAuthorPHID()); 48 41 $this->loadHandles($phids); 49 - 50 42 51 43 $engine = id(new PhabricatorMarkupEngine()) 52 44 ->setViewer($user); ··· 66 58 ->setHeader($title); 67 59 68 60 $actions = $this->buildActionView($mock); 69 - $properties = $this->buildPropertyView($mock, $engine, $subscribers); 61 + $properties = $this->buildPropertyView($mock, $engine); 70 62 71 63 require_celerity_resource('pholio-css'); 72 64 require_celerity_resource('pholio-inline-comments-css'); ··· 137 129 138 130 private function buildPropertyView( 139 131 PholioMock $mock, 140 - PhabricatorMarkupEngine $engine, 141 - array $subscribers) { 132 + PhabricatorMarkupEngine $engine) { 142 133 143 134 $user = $this->getRequest()->getUser(); 144 135 ··· 161 152 $properties->addProperty( 162 153 pht('Visible To'), 163 154 $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); 164 - 165 - if ($subscribers) { 166 - $sub_view = array(); 167 - foreach ($subscribers as $subscriber) { 168 - $sub_view[] = $this->getHandle($subscriber)->renderLink(); 169 - } 170 - $sub_view = phutil_implode_html(', ', $sub_view); 171 - } else { 172 - $sub_view = phutil_tag('em', array(), pht('None')); 173 - } 174 - 175 - $properties->addProperty( 176 - pht('Subscribers'), 177 - $sub_view); 178 155 179 156 $properties->invokeWillRenderEvent(); 180 157
+37 -1
src/applications/subscriptions/events/PhabricatorSubscriptionsUIEventListener.php
··· 5 5 6 6 public function register() { 7 7 $this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS); 8 + $this->listen(PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES); 8 9 } 9 10 10 11 public function handleEvent(PhutilEvent $event) { 11 12 switch ($event->getType()) { 12 13 case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS: 13 14 $this->handleActionEvent($event); 14 - break; 15 + break; 16 + case PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES: 17 + $this->handlePropertyEvent($event); 18 + break; 15 19 } 16 20 } 17 21 ··· 79 83 $actions = $event->getValue('actions'); 80 84 $actions[] = $sub_action; 81 85 $event->setValue('actions', $actions); 86 + } 87 + 88 + private function handlePropertyEvent($event) { 89 + $user = $event->getUser(); 90 + $object = $event->getValue('object'); 91 + 92 + if (!$object || !$object->getPHID()) { 93 + // No object, or the object has no PHID yet.. 94 + return; 95 + } 96 + 97 + if (!($object instanceof PhabricatorSubscribableInterface)) { 98 + // This object isn't subscribable. 99 + return; 100 + } 101 + $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( 102 + $object->getPHID()); 103 + if ($subscribers) { 104 + $handles = id(new PhabricatorObjectHandleData($subscribers)) 105 + ->setViewer($user) 106 + ->loadHandles(); 107 + $sub_view = array(); 108 + foreach ($subscribers as $subscriber) { 109 + $sub_view[] = $handles[$subscriber]->renderLink(); 110 + } 111 + $sub_view = phutil_implode_html(', ', $sub_view); 112 + } else { 113 + $sub_view = phutil_tag('em', array(), pht('None')); 114 + } 115 + 116 + $view = $event->getValue('view'); 117 + $view->addProperty(pht('Subscribers'), $sub_view); 82 118 } 83 119 84 120 }