add: comments to similar page

- closes #4491
This commit is contained in:
HDVinnie
2026-01-22 01:07:32 -05:00
parent 4e9c709c0b
commit 3acd1bcb4e
9 changed files with 126 additions and 4 deletions
+27
View File
@@ -93,6 +93,33 @@ if (!\function_exists('href_collection')) {
}
}
if (!\function_exists('href_movie')) {
function href_movie(App\Models\TmdbMovie $movie, App\Models\Category $category): string
{
$appurl = appurl();
return \sprintf('%s/torrents/similar/%s.%s', $appurl, $category->id, $movie->id);
}
}
if (!\function_exists('href_tv')) {
function href_tv(App\Models\TmdbTv $tv, App\Models\Category $category): string
{
$appurl = appurl();
return \sprintf('%s/torrents/similar/%s.%s', $appurl, $category->id, $tv->id);
}
}
if (!\function_exists('href_game')) {
function href_game(App\Models\IgdbGame $game, App\Models\Category $category): string
{
$appurl = appurl();
return \sprintf('%s/torrents/similar/%s.%s', $appurl, $category->id, $game->id);
}
}
if (!\function_exists('tmdb_image')) {
function tmdb_image(string $type, ?string $original): string
{
+19 -1
View File
@@ -30,7 +30,11 @@ use App\Achievements\UserMadeComment;
use App\Achievements\UserMadeTenComments;
use App\Enums\ModerationStatus;
use App\Models\Article;
use App\Models\Category;
use App\Models\IgdbGame;
use App\Models\TmdbCollection;
use App\Models\TmdbMovie;
use App\Models\TmdbTv;
use App\Models\Playlist;
use App\Models\Ticket;
use App\Models\Torrent;
@@ -49,10 +53,12 @@ class Comment extends Component
protected ChatRepository $chatRepository;
public null|Article|TmdbCollection|Playlist|Ticket|Torrent|TorrentRequest $model;
public null|Article|IgdbGame|Playlist|Ticket|TmdbCollection|TmdbMovie|TmdbTv|Torrent|TorrentRequest $model;
public \App\Models\Comment $comment;
public ?Category $category = null;
public bool $anon = false;
public ?User $user;
@@ -214,6 +220,18 @@ class Comment extends Component
case Torrent::class:
$this->chatRepository->systemMessage($username.' has left a comment on Torrent [url='.href_torrent($this->model).']'.$this->model->name.'[/url]');
break;
case TmdbMovie::class:
$this->chatRepository->systemMessage($username.' has left a comment on Movie [url='.href_movie($this->model, $this->category).']'.$this->model->title.' ('.($this->model->release_date?->format('Y') ?? '').')'.'[/url]');
break;
case TmdbTv::class:
$this->chatRepository->systemMessage($username.' has left a comment on TV Show [url='.href_tv($this->model, $this->category).']'.$this->model->name.' ('.($this->model->first_air_date?->format('Y') ?? '').')'.'[/url]');
break;
case IgdbGame::class:
$this->chatRepository->systemMessage($username.' has left a comment on Game [url='.href_game($this->model, $this->category).']'.$this->model->name.' ('.($this->model->first_release_date?->format('Y') ?? '').')'.'[/url]');
break;
}
+19 -1
View File
@@ -30,7 +30,11 @@ use App\Achievements\UserMadeComment;
use App\Achievements\UserMadeTenComments;
use App\Enums\ModerationStatus;
use App\Models\Article;
use App\Models\Category;
use App\Models\IgdbGame;
use App\Models\TmdbCollection;
use App\Models\TmdbMovie;
use App\Models\TmdbTv;
use App\Models\Playlist;
use App\Models\Ticket;
use App\Models\Torrent;
@@ -55,7 +59,9 @@ class Comments extends Component
public ?User $user;
public null|Article|TmdbCollection|Playlist|Ticket|Torrent|TorrentRequest $model;
public null|Article|IgdbGame|Playlist|Ticket|TmdbCollection|TmdbMovie|TmdbTv|Torrent|TorrentRequest $model;
public ?Category $category = null;
public bool $anon = false;
@@ -172,6 +178,18 @@ class Comments extends Component
case Torrent::class:
$this->chatRepository->systemMessage($username.' has left a comment on Torrent [url='.href_torrent($this->model).']'.$this->model->name.'[/url]');
break;
case TmdbMovie::class:
$this->chatRepository->systemMessage($username.' has left a comment on Movie [url='.href_movie($this->model, $this->category).']'.$this->model->title.' ('.($this->model->release_date?->format('Y') ?? 'Unknown').')'.'[/url]');
break;
case TmdbTv::class:
$this->chatRepository->systemMessage($username.' has left a comment on TV Show [url='.href_tv($this->model, $this->category).']'.$this->model->name.' ('.($this->model->first_air_date?->format('Y') ?? 'Unknown').')'.'[/url]');
break;
case IgdbGame::class:
$this->chatRepository->systemMessage($username.' has left a comment on Game [url='.href_game($this->model, $this->category).']'.$this->model->name.' ('.($this->model->first_release_date?->format('Y') ?? 'Unknown').')'.'[/url]');
break;
}
+11
View File
@@ -18,6 +18,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use AllowDynamicProperties;
/**
@@ -87,4 +88,14 @@ final class IgdbGame extends Model
{
return $this->belongsToMany(IgdbGenre::class);
}
/**
* Get the comments for the game.
*
* @return MorphMany<Comment, $this>
*/
public function comments(): MorphMany
{
return $this->morphMany(Comment::class, 'commentable');
}
}
+11
View File
@@ -21,6 +21,7 @@ use App\Enums\Occupation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use AllowDynamicProperties;
/**
@@ -183,4 +184,14 @@ final class TmdbMovie extends Model
{
return $this->hasMany(Wish::class);
}
/**
* Get the comments for the movie.
*
* @return MorphMany<Comment, $this>
*/
public function comments(): MorphMany
{
return $this->morphMany(Comment::class, 'commentable');
}
}
+11
View File
@@ -21,6 +21,7 @@ use App\Enums\Occupation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use AllowDynamicProperties;
/**
@@ -186,4 +187,14 @@ final class TmdbTv extends Model
{
return $this->hasMany(Wish::class);
}
/**
* Get the comments for the tv show.
*
* @return MorphMany<Comment, $this>
*/
public function comments(): MorphMany
{
return $this->morphMany(Comment::class, 'commentable');
}
}
+26 -1
View File
@@ -17,7 +17,10 @@ declare(strict_types=1);
namespace App\Notifications;
use App\Models\Article;
use App\Models\IgdbGame;
use App\Models\TmdbCollection;
use App\Models\TmdbMovie;
use App\Models\TmdbTv;
use App\Models\Comment;
use App\Models\Playlist;
use App\Models\Ticket;
@@ -35,7 +38,7 @@ class NewCommentTag extends Notification implements ShouldQueue
/**
* NewCommentTag Constructor.
*/
public function __construct(public Torrent|TorrentRequest|Ticket|Playlist|TmdbCollection|Article $model, public Comment $comment)
public function __construct(public Torrent|TorrentRequest|Ticket|Playlist|TmdbCollection|TmdbMovie|TmdbTv|IgdbGame|Article $model, public Comment $comment)
{
}
@@ -96,6 +99,13 @@ class NewCommentTag extends Notification implements ShouldQueue
return false;
}
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->comment->user->group_id, $notifiable->notification?->json_mention_groups ?? [], true);
case TmdbCollection::class:
case TmdbMovie::class:
case TmdbTv::class:
case IgdbGame::class:
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->comment->user->group_id, $notifiable->notification?->json_mention_groups ?? [], true);
@@ -140,6 +150,21 @@ class NewCommentTag extends Notification implements ShouldQueue
'body' => $username.' has tagged you in an comment on Collection '.$this->model->name,
'url' => '/mediahub/collections/'.$this->model->id,
],
TmdbMovie::class => [
'title' => $title,
'body' => $username.' has tagged you in a comment on Movie '.$this->model->title,
'url' => '/torrents/similar/'.($this->model->torrents()->value('category_id') ?? 1).'.'.$this->model->id,
],
TmdbTv::class => [
'title' => $title,
'body' => $username.' has tagged you in a comment on TV Show '.$this->model->name,
'url' => '/torrents/similar/'.($this->model->torrents()->value('category_id') ?? 2).'.'.$this->model->id,
],
IgdbGame::class => [
'title' => $title,
'body' => $username.' has tagged you in a comment on Game '.$this->model->name,
'url' => '/torrents/similar/'.Torrent::query()->where('igdb', '=', $this->model->id)->value('category_id').'.'.$this->model->id,
],
Article::class => [
'title' => $title,
'body' => $username.' has tagged you in an comment on Article '.$this->model->title,
+1 -1
View File
@@ -43,7 +43,7 @@
</form>
<ol class="comment-list">
@forelse ($comments as $comment)
<livewire:comment :model="$model" :comment="$comment" :key="$comment->id" />
<livewire:comment :model="$model" :comment="$comment" :category="$category" :key="$comment->id" />
@empty
<li>
<i class="{{ config('other.font-awesome') }} fa-frown"></i>
@@ -49,4 +49,5 @@
@break
@endswitch
@livewire('similar-torrent', ['category' => $category, 'tmdbId' => $tmdb, 'igdbId' => $igdb, 'work' => $meta])
<livewire:comments :model="$meta" :category="$category" />
@endsection