diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f6aa7a6666..03de550fb9 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -429,6 +429,7 @@ phutil_register_library_map(array( 'PhabricatorEvent' => 'infrastructure/events/event', 'PhabricatorEventEngine' => 'infrastructure/events/engine', 'PhabricatorEventType' => 'infrastructure/events/constant/type', + 'PhabricatorFeedBuilder' => 'applications/feed/builder/feed', 'PhabricatorFeedConstants' => 'applications/feed/constants/base', 'PhabricatorFeedController' => 'applications/feed/controller/base', 'PhabricatorFeedDAO' => 'applications/feed/storage/base', diff --git a/src/applications/feed/builder/feed/PhabricatorFeedBuilder.php b/src/applications/feed/builder/feed/PhabricatorFeedBuilder.php new file mode 100644 index 0000000000..3de6204571 --- /dev/null +++ b/src/applications/feed/builder/feed/PhabricatorFeedBuilder.php @@ -0,0 +1,67 @@ +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; + } + +} diff --git a/src/applications/feed/builder/feed/__init__.php b/src/applications/feed/builder/feed/__init__.php new file mode 100644 index 0000000000..914e738afd --- /dev/null +++ b/src/applications/feed/builder/feed/__init__.php @@ -0,0 +1,15 @@ +execute(); - $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(); - } + $builder = new PhabricatorFeedBuilder($stories); + $builder + ->setUser($request->getUser()); - // TODO: We need this for timezones but should develop some more general - // 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(); - } + $view = $builder->buildView(); return $this->buildStandardPageResponse( - $views, + $view, array( 'title' => 'Public Feed', 'public' => true, diff --git a/src/applications/feed/controller/publicstream/__init__.php b/src/applications/feed/controller/publicstream/__init__.php index 0227a49c7b..12a51d0fd0 100644 --- a/src/applications/feed/controller/publicstream/__init__.php +++ b/src/applications/feed/controller/publicstream/__init__.php @@ -7,13 +7,10 @@ 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/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('phutil', 'utils'); - phutil_require_source('PhabricatorFeedPublicStreamController.php'); diff --git a/src/applications/feed/controller/stream/PhabricatorFeedStreamController.php b/src/applications/feed/controller/stream/PhabricatorFeedStreamController.php index 88564b6c1e..6dafd5fd9c 100644 --- a/src/applications/feed/controller/stream/PhabricatorFeedStreamController.php +++ b/src/applications/feed/controller/stream/PhabricatorFeedStreamController.php @@ -42,29 +42,9 @@ final class PhabricatorFeedStreamController extends PhabricatorFeedController { $query = new PhabricatorFeedQuery(); $stories = $query->execute(); - $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(); - } - - $views = array(); - foreach ($stories as $story) { - $story->setHandles($handles); - $story->setObjects($objects); - - $view = $story->renderView(); - $view->setViewer($viewer); - - $views[] = $view->render(); - } + $builder = new PhabricatorFeedBuilder($stories); + $builder->setUser($request->getUser()); + $view = $builder->buildView(); $post_form = id(new AphrontFormView()) ->setUser($viewer) @@ -83,7 +63,7 @@ final class PhabricatorFeedStreamController extends PhabricatorFeedController { $page = array(); $page[] = $post; - $page[] = $views; + $page[] = $view; return $this->buildStandardPageResponse( $page, diff --git a/src/applications/feed/controller/stream/__init__.php b/src/applications/feed/controller/stream/__init__.php index 78489305b4..2becac7d1d 100644 --- a/src/applications/feed/controller/stream/__init__.php +++ b/src/applications/feed/controller/stream/__init__.php @@ -7,11 +7,11 @@ 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/controller/base'); phutil_require_module('phabricator', 'applications/feed/publisher'); 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/control/submit'); phutil_require_module('phabricator', 'view/form/control/textarea');