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

Modernize FeedSearchEngine a little bit

Summary:
Ref T12762. This updates FeedSeachEngine to user modern construction.

I've tried to retain behavior exactly, although the "Include stories about projects I'm a member of" checkbox is now nonstandard/obsolete. We could likely fold that into "Include Projects" in a future change which does a backward compatibility break.

Test Plan:
- Queried feed without constraints.
- Queried feed by user, project, "stuff I'm a member of", prebuilt "Tags" query.
- Viewed user profile / project profile feeds.
- Used function tokens (`viewer()`, etc).

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12762

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

+52 -56
+14
src/applications/feed/query/PhabricatorFeedQuery.php
··· 89 89 return array('key'); 90 90 } 91 91 92 + public function getBuiltinOrders() { 93 + return array( 94 + 'newest' => array( 95 + 'vector' => array('key'), 96 + 'name' => pht('Creation (Newest First)'), 97 + 'aliases' => array('created'), 98 + ), 99 + 'oldest' => array( 100 + 'vector' => array('-key'), 101 + 'name' => pht('Creation (Oldest First)'), 102 + ), 103 + ); 104 + } 105 + 92 106 public function getOrderableColumns() { 93 107 $table = ($this->filterPHIDs ? 'ref' : 'story'); 94 108 return array(
+38 -56
src/applications/feed/query/PhabricatorFeedSearchEngine.php
··· 11 11 return 'PhabricatorFeedApplication'; 12 12 } 13 13 14 - public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 - $saved = new PhabricatorSavedQuery(); 14 + public function newQuery() { 15 + return new PhabricatorFeedQuery(); 16 + } 16 17 17 - $saved->setParameter( 18 - 'userPHIDs', 19 - $this->readUsersFromRequest($request, 'users')); 18 + protected function shouldShowOrderField() { 19 + return false; 20 + } 20 21 21 - $saved->setParameter( 22 - 'projectPHIDs', 23 - array_values($request->getArr('projectPHIDs'))); 22 + protected function buildCustomSearchFields() { 23 + return array( 24 + id(new PhabricatorUsersSearchField()) 25 + ->setLabel(pht('Include Users')) 26 + ->setKey('userPHIDs'), 27 + // NOTE: This query is not executed with EdgeLogic, so we can't use 28 + // a fancy logical datasource. 29 + id(new PhabricatorSearchDatasourceField()) 30 + ->setDatasource(new PhabricatorProjectDatasource()) 31 + ->setLabel(pht('Include Projects')) 32 + ->setKey('projectPHIDs'), 24 33 25 - $saved->setParameter( 26 - 'viewerProjects', 27 - $request->getBool('viewerProjects')); 28 - 29 - return $saved; 34 + // NOTE: This is a legacy field retained only for backward 35 + // compatibility. If the projects field used EdgeLogic, we could use 36 + // `viewerprojects()` to execute an equivalent query. 37 + id(new PhabricatorSearchCheckboxesField()) 38 + ->setKey('viewerProjects') 39 + ->setOptions( 40 + array( 41 + 'self' => pht('Include stories about projects I am a member of.'), 42 + )), 43 + ); 30 44 } 31 45 32 - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 33 - $query = id(new PhabricatorFeedQuery()); 46 + protected function buildQueryFromParameters(array $map) { 47 + $query = $this->newQuery(); 34 48 35 49 $phids = array(); 36 - 37 - $user_phids = $saved->getParameter('userPHIDs'); 38 - if ($user_phids) { 39 - $phids[] = $user_phids; 50 + if ($map['userPHIDs']) { 51 + $phids += array_fuse($map['userPHIDs']); 40 52 } 41 53 42 - $proj_phids = $saved->getParameter('projectPHIDs'); 43 - if ($proj_phids) { 44 - $phids[] = $proj_phids; 54 + if ($map['projectPHIDs']) { 55 + $phids += array_fuse($map['projectPHIDs']); 45 56 } 46 57 47 - $viewer_projects = $saved->getParameter('viewerProjects'); 58 + // NOTE: This value may be `true` for older saved queries, or 59 + // `array('self')` for newer ones. 60 + $viewer_projects = $map['viewerProjects']; 48 61 if ($viewer_projects) { 49 62 $viewer = $this->requireViewer(); 50 63 $projects = id(new PhabricatorProjectQuery()) 51 64 ->setViewer($viewer) 52 65 ->withMemberPHIDs(array($viewer->getPHID())) 53 66 ->execute(); 54 - $phids[] = mpull($projects, 'getPHID'); 67 + $phids += array_fuse(mpull($projects, 'getPHID')); 55 68 } 56 69 57 - $phids = array_mergev($phids); 58 70 if ($phids) { 59 71 $query->withFilterPHIDs($phids); 60 72 } ··· 62 74 return $query; 63 75 } 64 76 65 - public function buildSearchForm( 66 - AphrontFormView $form, 67 - PhabricatorSavedQuery $saved_query) { 68 - 69 - $user_phids = $saved_query->getParameter('userPHIDs', array()); 70 - $proj_phids = $saved_query->getParameter('projectPHIDs', array()); 71 - $viewer_projects = $saved_query->getParameter('viewerProjects'); 72 - 73 - $form 74 - ->appendControl( 75 - id(new AphrontFormTokenizerControl()) 76 - ->setDatasource(new PhabricatorPeopleDatasource()) 77 - ->setName('users') 78 - ->setLabel(pht('Include Users')) 79 - ->setValue($user_phids)) 80 - ->appendControl( 81 - id(new AphrontFormTokenizerControl()) 82 - ->setDatasource(new PhabricatorProjectDatasource()) 83 - ->setName('projectPHIDs') 84 - ->setLabel(pht('Include Projects')) 85 - ->setValue($proj_phids)) 86 - ->appendChild( 87 - id(new AphrontFormCheckboxControl()) 88 - ->addCheckbox( 89 - 'viewerProjects', 90 - 1, 91 - pht('Include stories about projects I am a member of.'), 92 - $viewer_projects)); 93 - } 94 - 95 77 protected function getURI($path) { 96 78 return '/feed/'.$path; 97 79 } ··· 117 99 case 'all': 118 100 return $query; 119 101 case 'projects': 120 - return $query->setParameter('viewerProjects', true); 102 + return $query->setParameter('viewerProjects', array('self')); 121 103 } 122 104 123 105 return parent::buildSavedQueryFromBuiltin($query_key);