Skip to content

Commit

Permalink
refactor: refcator notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
NishaSharma14 committed Sep 22, 2023
1 parent fc2ee96 commit 359cd87
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 105 deletions.
1 change: 0 additions & 1 deletion app/Actions/Project/ArchiveProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function toggle($project)
$project->save();
if ($project->is_archived) {
$project->sendNotification('archival', $this->prepareSendList($project));
$project->sendNotification('archivalAdmin', User::role(['super-admin'])->get());
}
}

Expand Down
17 changes: 9 additions & 8 deletions app/Actions/Project/InviteProjectMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

namespace App\Actions\Project;

use App\Events\InvitingProjectMember;
use App\Mail\ProjectInvitation;
use App\Models\User;
use App\Notifications\ProjectInviteNotification;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;
use App\Events\ProjectInvite;
use App\Mail\ProjectInvitation;
use Illuminate\Validation\Rule;
use Laravel\Jetstream\Jetstream;
use Laravel\Jetstream\Rules\Role;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Mail;
use App\Events\InvitingProjectMember;
use Illuminate\Support\Facades\Validator;
use App\Notifications\ProjectInviteNotification;

class InviteProjectMember
{
Expand All @@ -28,7 +29,7 @@ public function invite($user, $project, string $email, string $role = null, stri

$this->validate($project, $email, $role, $message);

InvitingProjectMember::dispatch($project, $email, $role, $message);
//InvitingProjectMember::dispatch($project, $email, $role, $message);

$invitation = $project->projectInvitations()->create([
'email' => $email,
Expand All @@ -42,7 +43,7 @@ public function invite($user, $project, string $email, string $role = null, stri
$invitedUser = User::where('email', $invitation->email)->first();

if ($invitedUser) {
$invitedUser->notify(new ProjectInviteNotification($invitation));
event(new ProjectInvite($invitedUser, $invitation));
}
}

Expand Down
18 changes: 10 additions & 8 deletions app/Actions/Study/InviteStudyMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

namespace App\Actions\Study;

use App\Events\InvitingStudyMember;
use App\Mail\StudyInvitation;
use App\Models\User;
use App\Notifications\StudyInviteNotification;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;
use App\Events\StudyInvite;
use App\Mail\StudyInvitation;
use Illuminate\Validation\Rule;
use Laravel\Jetstream\Jetstream;
use Laravel\Jetstream\Rules\Role;
use App\Events\InvitingStudyMember;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;
use App\Notifications\StudyInviteNotification;

class InviteStudyMember
{
Expand All @@ -28,7 +29,7 @@ public function invite($user, $study, string $email, string $role = null, string

$this->validate($study, $email, $role, $message);

InvitingStudyMember::dispatch($study, $email, $role, $message);
//InvitingStudyMember::dispatch($study, $email, $role, $message);

$invitation = $study->studyInvitations()->create([
'email' => $email,
Expand All @@ -42,7 +43,8 @@ public function invite($user, $study, string $email, string $role = null, string
$invitedUser = User::where('email', $invitation->email)->first();

if ($invitedUser) {
$invitedUser->notify(new StudyInviteNotification($invitation));
//$invitedUser->notify(new StudyInviteNotification($invitation));
event(new StudyInvite($invitedUser, $invitation));
}
}

Expand Down
33 changes: 0 additions & 33 deletions app/Events/InvitingProjectMember.php

This file was deleted.

33 changes: 0 additions & 33 deletions app/Events/InvitingStudyMember.php

This file was deleted.

35 changes: 35 additions & 0 deletions app/Events/ProjectArchival.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;

class ProjectArchival implements ShouldBroadcastNow
{
use Dispatchable;
public $project;
public $sendTo;

/**
* Create a new event instance.
*/
public function __construct($project, $sendTo)
{
$this->project = $project;
$this->sendTo = $sendTo;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}
35 changes: 35 additions & 0 deletions app/Events/ProjectDeletion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;

class ProjectDeletion implements ShouldBroadcastNow
{
use Dispatchable;
public $project;
public $sendTo;

/**
* Create a new event instance.
*/
public function __construct($project, $sendTo)
{
$this->project = $project;
$this->sendTo = $sendTo;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}
39 changes: 39 additions & 0 deletions app/Events/ProjectInvite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ProjectInvite implements ShouldBroadcastNow
{
use Dispatchable;
public $invitedUser;
public $invitation;

/**
* Create a new event instance.
*/
public function __construct($invitedUser, $invitation)
{
$this->invitedUser = $invitedUser;
$this->invitation = $invitation;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}
39 changes: 39 additions & 0 deletions app/Events/StudyInvite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class StudyInvite implements ShouldBroadcastNow
{
use Dispatchable;
public $invitedUser;
public $invitation;

/**
* Create a new event instance.
*/
public function __construct($invitedUser, $invitation)
{
$this->invitedUser = $invitedUser;
$this->invitation = $invitation;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}
30 changes: 30 additions & 0 deletions app/Listeners/ProjectArchival.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Listeners;

use App\Models\User;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification;
use App\Notifications\ProjectArchivalNotification;
use App\Notifications\ProjectArchivalNotificationToAdmins;

class ProjectArchival
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}

/**
* Handle the event.
*/
public function handle(object $event): void
{
Notification::send($event->$sendTo, new ProjectArchivalNotification($event->project));
Notification::send(User::role(['super-admin'])->get(), new ProjectArchivalNotificationToAdmins($this));
}
}
27 changes: 27 additions & 0 deletions app/Listeners/ProjectDeletion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Listeners;

use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification;
use App\Notifications\ProjectDeletionNotification;

class ProjectDeletion
{
/**
* Create the event listener.
*/
public function __construct()
{

}

/**
* Handle the event.
*/
public function handle(object $event): void
{
Notification::send($event->sendTo, new ProjectDeletionNotification($event->project));
}
}
27 changes: 27 additions & 0 deletions app/Listeners/ProjectInvite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Listeners;

use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification;
use App\Notifications\ProjectInviteNotification;

class ProjectInvite
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}

/**
* Handle the event.
*/
public function handle(object $event): void
{
Notification::send($event->$invitedUser, new ProjectInviteNotification($event->$invitation));
}
}
Loading

0 comments on commit 359cd87

Please sign in to comment.