@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 139 lines 3.6 kB view raw
1<?php 2 3final class PhabricatorNotificationSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Notifications'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorNotificationsApplication::class; 12 } 13 14 public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 $saved = new PhabricatorSavedQuery(); 16 17 $saved->setParameter( 18 'unread', 19 $this->readBoolFromRequest($request, 'unread')); 20 21 return $saved; 22 } 23 24 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 25 $query = id(new PhabricatorNotificationQuery()) 26 ->withUserPHIDs(array($this->requireViewer()->getPHID())); 27 28 if ($saved->getParameter('unread')) { 29 $query->withUnread(true); 30 } 31 32 return $query; 33 } 34 35 public function buildSearchForm( 36 AphrontFormView $form, 37 PhabricatorSavedQuery $saved) { 38 39 $unread = $saved->getParameter('unread'); 40 41 $form->appendChild( 42 id(new AphrontFormCheckboxControl()) 43 ->setLabel(pht('Unread')) 44 ->addCheckbox( 45 'unread', 46 1, 47 pht('Show only unread notifications.'), 48 $unread)); 49 } 50 51 protected function getURI($path) { 52 return '/notification/'.$path; 53 } 54 55 protected function getBuiltinQueryNames() { 56 57 $names = array( 58 'all' => pht('All Notifications'), 59 'unread' => pht('Unread Notifications'), 60 ); 61 62 return $names; 63 } 64 65 public function buildSavedQueryFromBuiltin($query_key) { 66 $query = $this->newSavedQuery(); 67 $query->setQueryKey($query_key); 68 69 switch ($query_key) { 70 case 'all': 71 return $query; 72 case 'unread': 73 return $query->setParameter('unread', true); 74 } 75 76 return parent::buildSavedQueryFromBuiltin($query_key); 77 } 78 79 /** 80 * @param array<PhabricatorFeedStory> $notifications 81 * @param PhabricatorSavedQuery $query 82 * @param array<PhabricatorObjectHandle> $handles 83 */ 84 protected function renderResultList( 85 array $notifications, 86 PhabricatorSavedQuery $query, 87 array $handles) { 88 assert_instances_of($notifications, PhabricatorFeedStory::class); 89 90 $viewer = $this->requireViewer(); 91 92 $button = id(new PHUIButtonView()) 93 ->setTag('a') 94 ->addSigil('workflow') 95 ->setColor(PHUIButtonView::GREY) 96 ->setIcon('fa-bell-o') 97 ->setText(pht('Mark All Read')); 98 99 switch ($query->getQueryKey()) { 100 case 'unread': 101 $header = pht('Unread Notifications'); 102 $no_data = pht('You have no unread notifications.'); 103 break; 104 default: 105 $header = pht('Notifications'); 106 $no_data = pht('You have no notifications.'); 107 break; 108 } 109 110 $clear_uri = new PhutilURI('/notification/clear/'); 111 if ($notifications) { 112 $builder = id(new PhabricatorNotificationBuilder($notifications)) 113 ->setUser($viewer); 114 115 $view = $builder->buildView(); 116 $clear_uri->replaceQueryParam( 117 'chronoKey', 118 head($notifications)->getChronologicalKey()); 119 } else { 120 $view = phutil_tag_div( 121 'phabricator-notification no-notifications', 122 $no_data); 123 $button->setDisabled(true); 124 } 125 $button->setHref((string)$clear_uri); 126 127 $view = id(new PHUIBoxView()) 128 ->addPadding(PHUI::PADDING_MEDIUM) 129 ->addClass('phabricator-notification-list') 130 ->appendChild($view); 131 132 $result = new PhabricatorApplicationSearchResultView(); 133 $result->addAction($button); 134 $result->setContent($view); 135 136 return $result; 137 } 138 139}