Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / feed / builder / PhabricatorFeedBuilder.php
blob335889df9d66bf888215412696a37cef1b2da6c8
1 <?php
3 final class PhabricatorFeedBuilder extends Phobject {
5 private $user;
6 private $stories;
7 private $hovercards = false;
8 private $noDataString;
10 public function __construct(array $stories) {
11 assert_instances_of($stories, 'PhabricatorFeedStory');
12 $this->stories = $stories;
15 public function setUser(PhabricatorUser $user) {
16 $this->user = $user;
17 return $this;
20 public function setShowHovercards($hover) {
21 $this->hovercards = $hover;
22 return $this;
25 public function setNoDataString($string) {
26 $this->noDataString = $string;
27 return $this;
30 public function buildView() {
31 if (!$this->user) {
32 throw new PhutilInvalidStateException('setUser');
35 $user = $this->user;
36 $stories = $this->stories;
38 $null_view = new AphrontNullView();
40 require_celerity_resource('phabricator-feed-css');
42 $last_date = null;
43 foreach ($stories as $story) {
44 $story->setHovercard($this->hovercards);
46 $date = ucfirst(phabricator_relative_date($story->getEpoch(), $user));
48 if ($date !== $last_date) {
49 if ($last_date !== null) {
50 $null_view->appendChild(
51 phutil_tag_div('phabricator-feed-story-date-separator'));
53 $last_date = $date;
54 $header = new PHUIHeaderView();
55 $header->setHeader($date);
56 $header->setHeaderIcon('fa-calendar msr');
58 $null_view->appendChild($header);
61 try {
62 $view = $story->renderView();
63 $view->setUser($user);
64 $view = $view->render();
65 } catch (Exception $ex) {
66 // If rendering failed for any reason, don't fail the entire feed,
67 // just this one story.
68 $view = id(new PHUIFeedStoryView())
69 ->setUser($user)
70 ->setChronologicalKey($story->getChronologicalKey())
71 ->setEpoch($story->getEpoch())
72 ->setTitle(
73 pht('Feed Story Failed to Render (%s)', get_class($story)))
74 ->appendChild(pht('%s: %s', get_class($ex), $ex->getMessage()));
77 $null_view->appendChild($view);
80 $box = id(new PHUIObjectBoxView())
81 ->appendChild($null_view);
83 if (empty($stories)) {
84 $nodatastring = pht('No Stories.');
85 if ($this->noDataString) {
86 $nodatastring = $this->noDataString;
89 $view = id(new PHUIBoxView())
90 ->addClass('mlt mlb msr msl')
91 ->appendChild($nodatastring);
92 $box->appendChild($view);
95 return $box;