Skip to content

Feature/lar 28 forum improvment #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/Actions/Article/CreateArticleAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
use App\Models\Article;
use App\Notifications\PostArticleToTelegram;
use Carbon\Carbon;
use DateTimeInterface;
use Illuminate\Support\Facades\Auth;

final class CreateArticleAction
{
public function execute(CreateArticleData $articleData): Article
{
if ($articleData->publishedAt && ! ($articleData->publishedAt instanceof DateTimeInterface)) {
if ($articleData->publishedAt) {
$articleData->publishedAt = new Carbon(
time: $articleData->publishedAt,
tz: config('app.timezone')
Expand All @@ -41,12 +40,14 @@ public function execute(CreateArticleData $articleData): Article
}

if ($articleData->file) {
$article->addMedia($articleData->file->getRealPath())->toMediaCollection('media');
$article->addMedia($articleData->file->getRealPath())
->toMediaCollection('media');
}

if ($article->isAwaitingApproval()) {
// Envoi de la notification sur le channel Telegram pour la validation de l'article.
Auth::user()?->notify(new PostArticleToTelegram($article));

session()->flash('status', __('notifications.article.created'));
}

Expand Down
29 changes: 29 additions & 0 deletions app/Actions/Forum/CreateReplyAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace App\Actions\Forum;

use App\Contracts\ReplyInterface;
use App\Events\ReplyWasCreated;
use App\Gamify\Points\ReplyCreated;
use App\Models\Reply;
use App\Models\User;
use Illuminate\Support\Facades\Auth;

final class CreateReplyAction
{
public function execute(string $body, ReplyInterface $model): void
{
/** @var User $user */
$user = Auth::user();

$reply = new Reply(['body' => $body]);
$reply->authoredBy($user);
$reply->to($model);
$reply->save();

givePoint(new ReplyCreated($model, $user));
event(new ReplyWasCreated($reply));
}
}
23 changes: 23 additions & 0 deletions app/Actions/Forum/SubscribeToThreadAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Actions\Forum;

use App\Models\Subscribe;
use App\Models\Thread;
use Illuminate\Support\Facades\Auth;
use Ramsey\Uuid\Uuid;

final class SubscribeToThreadAction
{
public function execute(Thread $thread): void
{
$subscription = new Subscribe;
$subscription->uuid = Uuid::uuid4()->toString();
$subscription->user()->associate(Auth::user());
$subscription->subscribeAble()->associate($thread);

$thread->subscribes()->save($subscription);
}
}
6 changes: 4 additions & 2 deletions app/Console/Commands/UpdateUserBestRepliesPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Gamify\Points\BestReply;
use App\Models\Thread;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;

final class UpdateUserBestRepliesPoints extends Command
{
Expand All @@ -18,10 +19,11 @@ public function handle(): void
{
$this->info('Updating users bests replies reputations...');

$resolvedThread = Thread::resolved()->with('solutionReply')->get();
/** @var Collection | Thread[] $resolvedThread */
$resolvedThread = Thread::with('solutionReply')->scopes('resolved')->get();

foreach ($resolvedThread as $thread) {
givePoint(new BestReply($thread->solutionReply));
givePoint(new BestReply($thread->solutionReply)); // @phpstan-ignore-line
}

$this->info('All done!');
Expand Down
9 changes: 9 additions & 0 deletions app/Exceptions/UnverifiedUserException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace App\Exceptions;

use Exception;

final class UnverifiedUserException extends Exception {}
9 changes: 2 additions & 7 deletions app/Gamify/Points/ArticleCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
namespace App\Gamify\Points;

use App\Models\Article;
use App\Models\User;
use QCod\Gamify\PointType;

final class ArticleCreated extends PointType
{
public int $points = 50;

protected string $payee = 'user';

public function __construct(Article $subject)
{
$this->subject = $subject;
}

public function payee(): User
{
// @phpstan-ignore-next-line
return $this->getSubject()->user;
}
}
5 changes: 3 additions & 2 deletions app/Gamify/Points/BestReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

namespace App\Gamify\Points;

use App\Models\Reply;
use QCod\Gamify\PointType;

final class BestReply extends PointType
{
public int $points = 20;

protected string $payee = 'author';
protected string $payee = 'user';

public function __construct(mixed $subject)
public function __construct(Reply $subject)
{
$this->subject = $subject;
}
Expand Down
9 changes: 2 additions & 7 deletions app/Gamify/Points/DiscussionCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
namespace App\Gamify\Points;

use App\Models\Discussion;
use App\Models\User;
use QCod\Gamify\PointType;

final class DiscussionCreated extends PointType
{
public int $points = 20;

protected string $payee = 'user';

public function __construct(Discussion $subject)
{
$this->subject = $subject;
}

public function payee(): User
{
// @phpstan-ignore-next-line
return $this->getSubject()->user;
}
}
9 changes: 2 additions & 7 deletions app/Gamify/Points/PostCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
namespace App\Gamify\Points;

use App\Models\Article;
use App\Models\User;
use QCod\Gamify\PointType;

final class PostCreated extends PointType
{
public int $points = 50;

protected string $payee = 'user';

public function __construct(Article $subject)
{
$this->subject = $subject;
}

public function payee(): User
{
// @phpstan-ignore-next-line
return $this->getSubject()->user;
}
}
9 changes: 2 additions & 7 deletions app/Gamify/Points/ThreadCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
namespace App\Gamify\Points;

use App\Models\Thread;
use App\Models\User;
use QCod\Gamify\PointType;

final class ThreadCreated extends PointType
{
public int $points = 55;

protected string $payee = 'user';

public function __construct(Thread $subject)
{
$this->subject = $subject;
}

public function payee(): User
{
// @phpstan-ignore-next-line
return $this->getSubject()->user;
}
}
62 changes: 0 additions & 62 deletions app/Http/Controllers/ThreadController.php

This file was deleted.

2 changes: 0 additions & 2 deletions app/Listeners/SendNewCommentNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public function handle(CommentWasAdded $event): void

foreach ($discussion->subscribes as $subscription) {
/** @var Subscribe $subscription */
// @phpstan-ignore-next-line
if ($this->replyAuthorDoesNotMatchSubscriber(author: $event->reply->user, subscription: $subscription)) {
// @phpstan-ignore-next-line
$subscription->user->notify(new NewCommentNotification(
reply: $event->reply,
subscription: $subscription,
Expand Down
3 changes: 1 addition & 2 deletions app/Listeners/SendNewReplyNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ public function handle(ReplyWasCreated $event): void

foreach ($thread->subscribes as $subscription) {
/** @var Subscribe $subscription */
// @phpstan-ignore-next-line
if ($this->replyAuthorDoesNotMatchSubscriber(author: $event->reply->user, subscription: $subscription)) {
$subscription->user->notify(new NewReplyNotification($event->reply, $subscription)); // @phpstan-ignore-line
$subscription->user->notify(new NewReplyNotification($event->reply, $subscription));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/SendNewThreadNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function handle(ThreadWasCreated $event): void
{
$thread = $event->thread;

$thread->user->notify(new PostThreadToSlack($thread)); // @phpstan-ignore-line
$thread->user->notify(new PostThreadToSlack($thread));
}
}
50 changes: 50 additions & 0 deletions app/Livewire/Components/ChannelsSelector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace App\Livewire\Components;

use App\Models\Channel;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Cache;
use Livewire\Attributes\Computed;
use Livewire\Component;

/**
* @property Channel | null $currentChannel
*/
final class ChannelsSelector extends Component
{
public ?string $slug = null;

public function selectedChannel(int $channelId): void
{
$this->slug = Channel::query()->find($channelId)?->slug;

$this->dispatch('channelUpdated', channelId: $channelId);
}

public function resetChannel(): void
{
$this->slug = null;

$this->dispatch('channelUpdated', channelId: null);
}

#[Computed]
public function currentChannel(): ?Channel
{
return $this->slug ? Channel::findBySlug($this->slug) : null;
}

public function render(): View
{
return view('livewire.components.channels-selector', [
'channels' => Cache::remember(
'channels',
now()->addMonth(),
fn () => Channel::with('items')->whereNull('parent_id')->get()
),
]);
}
}
Loading
Loading