Skip to content

Commit

Permalink
Fix rendering feeds for discussions/posts with deleted users (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
rob006 committed Aug 12, 2022
1 parent 14d80ee commit 262d392
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Controller/DiscussionFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function getFeedContent(Request $request)
'content' => $this->summarize($this->stripHTML($post->attributes->contentHtml)),
'permalink' => $this->url->to('forum')->route('discussion', ['id' => $discussion->attributes->slug, 'near' => $post->attributes->number]),
'pubdate' => $this->parseDate($post->attributes->createdAt),
'author' => $this->getRelationship($posts, $post->relationships->user)->username,
'author' => isset($post->relationships->user) ? $this->getRelationship($posts, $post->relationships->user)->username : '[deleted]',
];

$modified = $this->parseDate(Arr::get($post->attributes, 'editedAt', $post->attributes->createdAt));
Expand Down
7 changes: 6 additions & 1 deletion src/Controller/DiscussionsActivityFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,18 @@ protected function getFeedContent(Request $request)
$content->contentHtml = '';
}

if ($this->lastTopics) {
$author = isset($discussion->relationships->user) ? $this->getRelationship($last_discussions, $discussion->relationships->user)->username : '[deleted]';
} else {
$author = isset($discussion->relationships->lastPostedUser) ? $this->getRelationship($last_discussions, $discussion->relationships->lastPostedUser)->username : '[deleted]';
}
$entries[] = [
'title' => $discussion->attributes->title,
'content' => $this->summarize($this->stripHTML($content->contentHtml)),
'id' => $this->url->to('forum')->route('discussion', ['id' => $discussion->id.'-'.$discussion->attributes->slug]),
'permalink' => $this->url->to('forum')->route('discussion', ['id' => $discussion->attributes->slug, 'near' => $content->number]),
'pubdate' => $this->parseDate($this->lastTopics ? $discussion->attributes->createdAt : $discussion->attributes->lastPostedAt),
'author' => $this->getRelationship($last_discussions, $this->lastTopics ? $discussion->relationships->user : $discussion->relationships->lastPostedUser)->username,
'author' => $author,
];

$modified = $this->parseDate($this->lastTopics ? $discussion->attributes->createdAt : $discussion->attributes->lastPostedAt);
Expand Down

0 comments on commit 262d392

Please sign in to comment.