Skip to content

Commit

Permalink
Fixed feed content empty when user logged in (#6)
Browse files Browse the repository at this point in the history
* Fixed feed content empty when user logged in

* Apply fixes from StyleCI
  • Loading branch information
zgq354 committed Jul 6, 2021
1 parent ad59c74 commit 603f900
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
20 changes: 11 additions & 9 deletions src/Controller/AbstractFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,19 @@ protected function getActor(ServerRequestInterface $request): User
/**
* Retrieves an API response from the given endpoint.
*
* @param string $endpoint The API endpoint.
* @param User $actor The request actor.
* @param array $params The API request parameters (if any).
* @param array $body The API request body (if any).
* @param Request $request
* @param string $endpoint The API endpoint.
* @param User $actor The request actor.
* @param array $params The API request parameters (if any).
* @param array $body The API request body (if any).
*
* @throws RouteNotFoundException If the API endpoint cannot be found, or if it cannot find what requested.
*
* @return \stdClass API response.
*/
protected function getAPIDocument(string $endpoint, User $actor, array $params = [], array $body = [])
protected function getAPIDocument(Request $request, string $endpoint, User $actor, array $params = [], array $body = [])
{
$response = $this->api->withQueryParams($params)->withBody($body)->withActor($actor)->get($endpoint);
$response = $this->api->withParentRequest($request)->withQueryParams($params)->withBody($body)->withActor($actor)->get($endpoint);

if ($response->getStatusCode() === 404) {
throw new RouteNotFoundException();
Expand All @@ -191,13 +192,14 @@ protected function getAPIDocument(string $endpoint, User $actor, array $params =
/**
* Get the result of an API request to show the forum.
*
* @param User $actor
* @param Request $request
* @param User $actor
*
* @return \stdClass
*/
protected function getForumDocument(User $actor)
protected function getForumDocument(Request $request, User $actor)
{
return $this->getAPIDocument('/', $actor)->data;
return $this->getAPIDocument($request, '/', $actor)->data;
}

/**
Expand Down
22 changes: 12 additions & 10 deletions src/Controller/DiscussionFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ protected function getFeedContent(Request $request)

$actor = $this->getActor($request);

$discussion = $this->getDiscussionsDocument($actor, [
$discussion = $this->getDiscussionsDocument($request, $actor, [
'id' => $discussion_id,
'page' => [
'limit' => 1,
],
])->data;

$posts = $this->getPostsDocument($actor, [
$posts = $this->getPostsDocument($request, $actor, [
'filter' => [
'discussion' => $discussion_id,
],
Expand Down Expand Up @@ -124,30 +124,32 @@ protected function getFeedContent(Request $request)
/**
* Get the result of an API request to show a discussion.
*
* @param User $actor
* @param array $params
* @param Request $request
* @param User $actor
* @param array $params
*
* @throws RouteNotFoundException
*
* @return object
*/
protected function getDiscussionsDocument(User $actor, array $params)
protected function getDiscussionsDocument(Request $request, User $actor, array $params)
{
return $this->getAPIDocument('/discussions/'.$params['id'], $actor, $params);
return $this->getAPIDocument($request, '/discussions/'.$params['id'], $actor, $params);
}

/**
* Get the result of an API request to list a discussion posts.
*
* @param User $actor
* @param array $params
* @param Request $request
* @param User $actor
* @param array $params
*
* @throws RouteNotFoundException
*
* @return object
*/
protected function getPostsDocument(User $actor, array $params)
protected function getPostsDocument(Request $request, User $actor, array $params)
{
return $this->getAPIDocument('/posts', $actor, $params);
return $this->getAPIDocument($request, '/posts', $actor, $params);
}
}
15 changes: 8 additions & 7 deletions src/Controller/DiscussionsActivityFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ protected function getFeedContent(Request $request)
];

$actor = $this->getActor($request);
$forum = $this->getForumDocument($actor);
$last_discussions = $this->getDocument($actor, $params);
$forum = $this->getForumDocument($request, $actor);
$last_discussions = $this->getDocument($request, $actor, $params);

$entries = [];
$lastModified = null;

foreach ($last_discussions->data as $discussion) {
foreach ((array) $last_discussions->data as $discussion) {
if ($discussion->type != 'discussions') {
continue;
}
Expand Down Expand Up @@ -183,14 +183,15 @@ protected function getFeedContent(Request $request)
/**
* Get the result of an API request to list discussions.
*
* @param User $actor
* @param array $params
* @param Request $request
* @param User $actor
* @param array $params
*
* @return object
*/
private function getDocument(User $actor, array $params)
private function getDocument(Request $request, User $actor, array $params)
{
return $this->getAPIDocument('/discussions', $actor, $params);
return $this->getAPIDocument($request, '/discussions', $actor, $params);
}

/**
Expand Down

0 comments on commit 603f900

Please sign in to comment.