1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 09:20:58 +01:00

Share feed building code

Summary:
I pretty much copy/pasted this code; rather than do that again now that I want
to add feeds to projects, share the code.

This "Builder" is a little weird -- I don't want to call it a "View" because it
does data access. "Builder" seemed okay. We don't really have much code that
does this sort of thing right now, elsewhere.

Test Plan:
  - Viewed public feed.
  - Viewed private feed.

Reviewers: btrahan, jungejason

Reviewed By: btrahan

CC: aran, btrahan

Maniphest Tasks: T681

Differential Revision: 1233
This commit is contained in:
epriestley 2011-12-17 15:50:37 -08:00
parent c93fc91e96
commit 0634009720
7 changed files with 94 additions and 54 deletions

View file

@ -429,6 +429,7 @@ phutil_register_library_map(array(
'PhabricatorEvent' => 'infrastructure/events/event', 'PhabricatorEvent' => 'infrastructure/events/event',
'PhabricatorEventEngine' => 'infrastructure/events/engine', 'PhabricatorEventEngine' => 'infrastructure/events/engine',
'PhabricatorEventType' => 'infrastructure/events/constant/type', 'PhabricatorEventType' => 'infrastructure/events/constant/type',
'PhabricatorFeedBuilder' => 'applications/feed/builder/feed',
'PhabricatorFeedConstants' => 'applications/feed/constants/base', 'PhabricatorFeedConstants' => 'applications/feed/constants/base',
'PhabricatorFeedController' => 'applications/feed/controller/base', 'PhabricatorFeedController' => 'applications/feed/controller/base',
'PhabricatorFeedDAO' => 'applications/feed/storage/base', 'PhabricatorFeedDAO' => 'applications/feed/storage/base',

View file

@ -0,0 +1,67 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorFeedBuilder {
private $stories;
public function __construct(array $stories) {
$this->stories = $stories;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function buildView() {
if (!$this->user) {
throw new Exception('Call setUser() before buildView()!');
}
$user = $this->user;
$stories = $this->stories;
$handles = array();
$objects = array();
if ($stories) {
$handle_phids = array_mergev(mpull($stories, 'getRequiredHandlePHIDs'));
$object_phids = array_mergev(mpull($stories, 'getRequiredObjectPHIDs'));
$handles = id(new PhabricatorObjectHandleData($handle_phids))
->loadHandles();
$objects = id(new PhabricatorObjectHandleData($object_phids))
->loadObjects();
}
$null_view = new AphrontNullView();
$views = array();
foreach ($stories as $story) {
$story->setHandles($handles);
$story->setObjects($objects);
$view = $story->renderView();
$view->setViewer($user);
$null_view->appendChild($view);
}
return $null_view;
}
}

View file

@ -0,0 +1,15 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'view/null');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorFeedBuilder.php');

View file

@ -36,34 +36,14 @@ final class PhabricatorFeedPublicStreamController
$query = new PhabricatorFeedQuery(); $query = new PhabricatorFeedQuery();
$stories = $query->execute(); $stories = $query->execute();
$handles = array(); $builder = new PhabricatorFeedBuilder($stories);
$objects = array(); $builder
if ($stories) { ->setUser($request->getUser());
$handle_phids = array_mergev(mpull($stories, 'getRequiredHandlePHIDs'));
$object_phids = array_mergev(mpull($stories, 'getRequiredObjectPHIDs'));
$handles = id(new PhabricatorObjectHandleData($handle_phids))
->loadHandles();
$objects = id(new PhabricatorObjectHandleData($object_phids))
->loadObjects();
}
// TODO: We need this for timezones but should develop some more general $view = $builder->buildView();
// solution for logged-out pages.
$dummy_user = new PhabricatorUser();
$views = array();
foreach ($stories as $story) {
$story->setHandles($handles);
$story->setObjects($objects);
$view = $story->renderView();
$view->setViewer($dummy_user);
$views[] = $view->render();
}
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
$views, $view,
array( array(
'title' => 'Public Feed', 'title' => 'Public Feed',
'public' => true, 'public' => true,

View file

@ -7,13 +7,10 @@
phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'aphront/response/404');
phutil_require_module('phabricator', 'applications/feed/builder/feed');
phutil_require_module('phabricator', 'applications/feed/controller/base'); phutil_require_module('phabricator', 'applications/feed/controller/base');
phutil_require_module('phabricator', 'applications/feed/query'); phutil_require_module('phabricator', 'applications/feed/query');
phutil_require_module('phabricator', 'applications/people/storage/user');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorFeedPublicStreamController.php'); phutil_require_source('PhabricatorFeedPublicStreamController.php');

View file

@ -42,29 +42,9 @@ final class PhabricatorFeedStreamController extends PhabricatorFeedController {
$query = new PhabricatorFeedQuery(); $query = new PhabricatorFeedQuery();
$stories = $query->execute(); $stories = $query->execute();
$handles = array(); $builder = new PhabricatorFeedBuilder($stories);
$objects = array(); $builder->setUser($request->getUser());
if ($stories) { $view = $builder->buildView();
$handle_phids = array_mergev(mpull($stories, 'getRequiredHandlePHIDs'));
$object_phids = array_mergev(mpull($stories, 'getRequiredObjectPHIDs'));
$handles = id(new PhabricatorObjectHandleData($handle_phids))
->loadHandles();
$objects = id(new PhabricatorObjectHandleData($object_phids))
->loadObjects();
}
$views = array();
foreach ($stories as $story) {
$story->setHandles($handles);
$story->setObjects($objects);
$view = $story->renderView();
$view->setViewer($viewer);
$views[] = $view->render();
}
$post_form = id(new AphrontFormView()) $post_form = id(new AphrontFormView())
->setUser($viewer) ->setUser($viewer)
@ -83,7 +63,7 @@ final class PhabricatorFeedStreamController extends PhabricatorFeedController {
$page = array(); $page = array();
$page[] = $post; $page[] = $post;
$page[] = $views; $page[] = $view;
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
$page, $page,

View file

@ -7,11 +7,11 @@
phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'aphront/response/redirect');
phutil_require_module('phabricator', 'applications/feed/builder/feed');
phutil_require_module('phabricator', 'applications/feed/constants/story'); phutil_require_module('phabricator', 'applications/feed/constants/story');
phutil_require_module('phabricator', 'applications/feed/controller/base'); phutil_require_module('phabricator', 'applications/feed/controller/base');
phutil_require_module('phabricator', 'applications/feed/publisher'); phutil_require_module('phabricator', 'applications/feed/publisher');
phutil_require_module('phabricator', 'applications/feed/query'); phutil_require_module('phabricator', 'applications/feed/query');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'view/form/base'); phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/control/textarea'); phutil_require_module('phabricator', 'view/form/control/textarea');