Skip to content

Commit

Permalink
Merge pull request #3594 from Roardom/typed-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
HDVinnie committed Mar 2, 2024
2 parents f279908 + c7408be commit 7160ae0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/ApprovedRequestFillController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function store(Request $request, TorrentRequest $torrentRequest): \Illumi
}

if ($filler->acceptsNotification($approver, $filler, 'request', 'show_request_fill_approve')) {
$filler->notify(new NewRequestFillApprove('torrent', $approver->username, $torrentRequest));
$filler->notify(new NewRequestFillApprove($torrentRequest));
}

return to_route('requests.show', ['torrentRequest' => $torrentRequest])
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/BountyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function store(StoreTorrentRequestBountyRequest $request, TorrentRequest

$user->decrement('seedbonus', $request->integer('seedbonus'));

$torrentRequest->bounties()->create(['user_id' => $user->id] + $request->validated());
$bounty = $torrentRequest->bounties()->create(['user_id' => $user->id] + $request->validated());

$torrentRequest->votes++;
$torrentRequest->bounty += $request->integer('seedbonus');
Expand Down Expand Up @@ -74,11 +74,10 @@ public function store(StoreTorrentRequestBountyRequest $request, TorrentRequest
);
}

$sender = $request->boolean('anon') ? 'Anonymous' : $request->user()->username;
$requester = $torrentRequest->user;

if ($requester->acceptsNotification($request->user(), $requester, 'request', 'show_request_bounty')) {
$requester->notify(new NewRequestBounty('torrent', $sender, $request->integer('seedbonus'), $torrentRequest));
$requester->notify(new NewRequestBounty($bounty));
}

return to_route('requests.show', ['torrentRequest' => $torrentRequest])
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/ClaimController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,16 @@ public function store(StoreTorrentRequestClaimRequest $request, TorrentRequest $
->withErrors(trans('request.already-claimed'));
}

$torrentRequest->claim()->create(['user_id' => $request->user()->id] + $request->validated());
$claim = $torrentRequest->claim()->create(['user_id' => $request->user()->id] + $request->validated());

$torrentRequest->update([
'claimed' => true,
]);

$claimer = $request->boolean('anon') ? 'Anonymous' : $request->user()->username;
$requester = $torrentRequest->user;

if ($requester->acceptsNotification($request->user(), $requester, 'request', 'show_request_claim')) {
$requester->notify(new NewRequestClaim('torrent', $claimer, $torrentRequest));
$requester->notify(new NewRequestClaim($claim));
}

return to_route('requests.show', ['torrentRequest' => $torrentRequest])
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/RequestFillController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function store(StoreRequestFillRequest $request, TorrentRequest $torrentR
$requester = $torrentRequest->user;

if ($requester->acceptsNotification($request->user(), $requester, 'request', 'show_request_fill')) {
$requester->notify(new NewRequestFill('torrent', $sender, $torrentRequest));
$requester->notify(new NewRequestFill($torrentRequest));
}

return to_route('requests.show', ['torrentRequest' => $torrentRequest])
Expand Down
12 changes: 7 additions & 5 deletions app/Notifications/NewRequestBounty.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace App\Notifications;

use App\Models\TorrentRequest;
use App\Models\TorrentRequestBounty;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
Expand All @@ -25,7 +25,7 @@ class NewRequestBounty extends Notification implements ShouldQueue
/**
* NewRequestBounty Constructor.
*/
public function __construct(public string $type, public string $sender, public int $amount, public TorrentRequest $torrentRequest)
public function __construct(public TorrentRequestBounty $bounty)
{
}

Expand All @@ -46,10 +46,12 @@ public function via(object $notifiable): array
*/
public function toArray(object $notifiable): array
{
$this->bounty->load('user');

return [
'title' => $this->sender.' Has Added A Bounty Of '.$this->amount.' To A Requested Torrent',
'body' => $this->sender.' has added a bounty to one of your Requested Torrents '.$this->torrentRequest->name,
'url' => sprintf('/requests/%s', $this->torrentRequest->id),
'title' => ($this->bounty->anon ? 'Anonymous' : $this->bounty->user->username).' Has Added A Bounty Of '.$this->bounty->seedbonus.' To A Requested Torrent',
'body' => ($this->bounty->anon ? 'Anonymous' : $this->bounty->user->username).' has added a bounty to one of your Requested Torrents '.$this->bounty->request->name,
'url' => sprintf('/requests/%s', $this->bounty->requests_id),
];
}
}
12 changes: 7 additions & 5 deletions app/Notifications/NewRequestClaim.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace App\Notifications;

use App\Models\TorrentRequest;
use App\Models\TorrentRequestClaim;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
Expand All @@ -25,7 +25,7 @@ class NewRequestClaim extends Notification implements ShouldQueue
/**
* NewRequestClaim Constructor.
*/
public function __construct(public string $type, public string $sender, public TorrentRequest $torrentRequest)
public function __construct(public TorrentRequestClaim $claim)
{
}

Expand All @@ -46,10 +46,12 @@ public function via(object $notifiable): array
*/
public function toArray(object $notifiable): array
{
$this->claim->load('user');

return [
'title' => $this->sender.' Has Claimed One Of Your Requested Torrents',
'body' => $this->sender.' has claimed your Requested Torrent '.$this->torrentRequest->name,
'url' => sprintf('/requests/%s', $this->torrentRequest->id),
'title' => ($this->claim->anon ? 'Anonymous' : $this->claim->user->username).' Has Claimed One Of Your Requested Torrents',
'body' => ($this->claim->anon ? 'Anonymous' : $this->claim->user->username).' has claimed your Requested Torrent '.$this->claim->request->name,
'url' => sprintf('/requests/%s', $this->claim->request_id),
];
}
}
8 changes: 5 additions & 3 deletions app/Notifications/NewRequestFill.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NewRequestFill extends Notification implements ShouldQueue
/**
* NewRequestFill Constructor.
*/
public function __construct(public string $type, public string $sender, public TorrentRequest $torrentRequest)
public function __construct(public TorrentRequest $torrentRequest)
{
}

Expand All @@ -46,9 +46,11 @@ public function via(object $notifiable): array
*/
public function toArray(object $notifiable): array
{
$this->torrentRequest->load('filler');

return [
'title' => $this->sender.' Has Filled One Of Your Torrent Requests',
'body' => $this->sender.' has filled one of your Requested Torrents '.$this->torrentRequest->name,
'title' => ($this->torrentRequest->filled_anon ? 'Anonymous' : $this->torrentRequest->filler->username).' Has Filled One Of Your Torrent Requests',
'body' => ($this->torrentRequest->filled_anon ? 'Anonymous' : $this->torrentRequest->filler->username).' has filled one of your Requested Torrents '.$this->torrentRequest->name,
'url' => sprintf('/requests/%s', $this->torrentRequest->id),
];
}
Expand Down
8 changes: 5 additions & 3 deletions app/Notifications/NewRequestFillApprove.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NewRequestFillApprove extends Notification implements ShouldQueue
/**
* NewRequestFillApprove Constructor.
*/
public function __construct(public string $type, public string $sender, public TorrentRequest $torrentRequest)
public function __construct(public TorrentRequest $torrentRequest)
{
}

Expand All @@ -47,9 +47,11 @@ public function via(object $notifiable): array
public function toArray(object $notifiable): array
{
if ($this->torrentRequest->anon == 0) {
$this->torrentRequest->load('approver');

return [
'title' => $this->sender.' Has Approved Your Fill Of A Requested Torrent',
'body' => $this->sender.' has approved your fill of Requested Torrent '.$this->torrentRequest->name,
'title' => $this->torrentRequest->approver->username.' Has Approved Your Fill Of A Requested Torrent',
'body' => $this->torrentRequest->approver->username.' has approved your fill of Requested Torrent '.$this->torrentRequest->name,
'url' => sprintf('/requests/%s', $this->torrentRequest->id),
];
}
Expand Down

0 comments on commit 7160ae0

Please sign in to comment.