mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-12 11:16:43 +02:00
feat(comments): add comments to episodes + update naming of status to post
- remove confusing counts for episode (total favourites, total reblogs) - add comments section to episode page to display episode comments + post replies linked to the episode
This commit is contained in:
parent
3ff1364906
commit
bb4752c35e
86 changed files with 1667 additions and 1152 deletions
|
|
@ -15,8 +15,10 @@ use ActivityPub\Objects\OrderedCollectionPage;
|
|||
use Analytics\AnalyticsTrait;
|
||||
use App\Entities\Episode;
|
||||
use App\Entities\Podcast;
|
||||
use App\Libraries\CommentObject;
|
||||
use App\Libraries\NoteObject;
|
||||
use App\Libraries\PodcastEpisode;
|
||||
use App\Models\CommentModel;
|
||||
use App\Models\EpisodeModel;
|
||||
use App\Models\PodcastModel;
|
||||
use CodeIgniter\Database\BaseBuilder;
|
||||
|
|
@ -219,10 +221,10 @@ class EpisodeController extends BaseController
|
|||
/**
|
||||
* get comments: aggregated replies from posts referring to the episode
|
||||
*/
|
||||
$episodeComments = model('StatusModel')
|
||||
$episodeComments = model('PostModel')
|
||||
->whereIn('in_reply_to_id', function (BaseBuilder $builder): BaseBuilder {
|
||||
return $builder->select('id')
|
||||
->from('activitypub_statuses')
|
||||
->from('activitypub_posts')
|
||||
->where('episode_id', $this->episode->id);
|
||||
})
|
||||
->where('`published_at` <= NOW()', null, false)
|
||||
|
|
@ -254,4 +256,57 @@ class EpisodeController extends BaseController
|
|||
->setHeader('Access-Control-Allow-Origin', '*')
|
||||
->setBody($collection->toJSON());
|
||||
}
|
||||
|
||||
/**
|
||||
* @noRector ReturnTypeDeclarationRector
|
||||
*/
|
||||
public function comment(string $commentId): Response
|
||||
{
|
||||
if (
|
||||
($comment = (new CommentModel())->getCommentById($commentId)) === null
|
||||
) {
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
$commentObject = new CommentObject($comment);
|
||||
|
||||
return $this->response
|
||||
->setContentType('application/json')
|
||||
->setBody($commentObject->toJSON());
|
||||
}
|
||||
|
||||
public function commentReplies(string $commentId): Response
|
||||
{
|
||||
/**
|
||||
* get comment replies
|
||||
*/
|
||||
$commentReplies = model('CommentModel', false)
|
||||
->where('in_reply_to_id', service('uuid')->fromString($commentId)->getBytes())
|
||||
->orderBy('created_at', 'ASC');
|
||||
|
||||
$pageNumber = (int) $this->request->getGet('page');
|
||||
|
||||
if ($pageNumber < 1) {
|
||||
$commentReplies->paginate(12);
|
||||
$pager = $commentReplies->pager;
|
||||
$collection = new OrderedCollectionObject(null, $pager);
|
||||
} else {
|
||||
$paginatedReplies = $commentReplies->paginate(12, 'default', $pageNumber);
|
||||
$pager = $commentReplies->pager;
|
||||
|
||||
$orderedItems = [];
|
||||
if ($paginatedReplies !== null) {
|
||||
foreach ($paginatedReplies as $reply) {
|
||||
$replyObject = new CommentObject($reply);
|
||||
$orderedItems[] = $replyObject;
|
||||
}
|
||||
}
|
||||
|
||||
$collection = new OrderedCollectionPage($pager, $orderedItems);
|
||||
}
|
||||
|
||||
return $this->response
|
||||
->setContentType('application/activity+json')
|
||||
->setBody($collection->toJSON());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue