Skip to content
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

feat: Add notifications for inline and overall comments #2127

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions backend/app/Events/InlineCommentAdded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

namespace App\Events;

use App\Models\InlineComment;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class InlineCommentAdded
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/**
* @var \App\Models\InlineComment $inline_comment
*/
public $inline_comment;

/**
* @param \App\Models\InlineComment $inline_comment
*/
public function __construct(InlineComment $inline_comment)
{
$this->inline_comment = $inline_comment;
}

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

namespace App\Events;

use App\Models\InlineComment;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class InlineCommentReplyAdded
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/**
* @var \App\Models\InlineComment $inline_comment
*/
public $inline_comment;

/**
* @param \App\Models\InlineComment $inline_comment
*/
public function __construct(InlineComment $inline_comment)
{
$this->inline_comment = $inline_comment;
}

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

namespace App\Events;

use App\Models\OverallComment;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class OverallCommentAdded
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/**
* @var \App\Models\OverallComment $overall_comment
*/
public $overall_comment;

/**
* @param \App\Models\OverallComment $overall_comment
*/
public function __construct(OverallComment $overall_comment)
{
$this->overall_comment = $overall_comment;
}

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

namespace App\Events;

use App\Models\OverallComment;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class OverallCommentReplyAdded
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/**
* @var \App\Models\OverallComment $overall_comment
*/
public $overall_comment;

/**
* @param \App\Models\OverallComment $overall_comment
*/
public function __construct(OverallComment $overall_comment)
{
$this->overall_comment = $overall_comment;
}

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

namespace App\Listeners;

use App\Events\InlineCommentAdded as EventsInlineCommentAdded;
use App\Notifications\InlineCommentAdded;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification;

class NotifyUsersAboutInlineComment extends Notification implements ShouldQueue
{
use Queueable;

/**
* Handle the event.
*
* @param \App\Events\EventsInlineCommentAdded $event
* @return void
*/
public function handle(EventsInlineCommentAdded $event): void
{
$submission = $event->inline_comment->submission;
$submitters = $submission->submitters()->get();
$review_coordinators = $submission->reviewCoordinators()->get();
$notification_data = [
'submission' => [
'id' => $submission->id,
'title' => $submission->title,
],
'commentor' => [
'display_label' => $event->inline_comment->createdBy->displayLabel,
],
'type' => 'submission.inline_comment.added',
];
$recipients = $submitters
->merge($review_coordinators)
->unique()
->filter(function ($user) use ($event) {
return $user->id !== $event->inline_comment->createdBy->id;
});

Notification::send($recipients, new InlineCommentAdded($notification_data));
}
}
50 changes: 50 additions & 0 deletions backend/app/Listeners/NotifyUsersAboutInlineCommentReply.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace App\Listeners;

use App\Events\InlineCommentReplyAdded as EventsInlineCommentReplyAdded;
use App\Notifications\InlineCommentReplyAdded;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification;

class NotifyUsersAboutInlineCommentReply extends Notification implements ShouldQueue
{
use Queueable;

/**
* Handle the event.
*
* @param \App\Events\InlineCommentReplyAdded $event
* @return void
*/
public function handle(EventsInlineCommentReplyAdded $event): void
{
$submission = $event->inline_comment->submission;
$submitters = $submission->submitters()->get();
$parent_commentor = $event->inline_comment->parent->createdBy()->get();
$commentors = $event->inline_comment->parent->commentors()->get();
$review_coordinators = $submission->reviewCoordinators()->get();
$notification_data = [
'submission' => [
'id' => $submission->id,
'title' => $submission->title,
],
'commentor' => [
'display_label' => $event->inline_comment->createdBy->displayLabel,
],
'type' => 'submission.inline_comment_reply.added',
];
$recipients = $submitters
->merge($commentors)
->merge($parent_commentor)
->merge($review_coordinators)
->unique()
->filter(function ($user) use ($event) {
return $user->id !== $event->inline_comment->createdBy->id;
});

Notification::send($recipients, new InlineCommentReplyAdded($notification_data));
}
}
46 changes: 46 additions & 0 deletions backend/app/Listeners/NotifyUsersAboutOverallComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);

namespace App\Listeners;

use App\Events\OverallCommentAdded as EventsOverallCommentAdded;
use App\Notifications\OverallCommentAdded;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification;

class NotifyUsersAboutOverallComment extends Notification implements ShouldQueue
{
use Queueable;

/**
* Handle the event.
*
* @param \App\Events\EventsOverallCommentAdded $event
* @return void
*/
public function handle(EventsOverallCommentAdded $event): void
{
$submission = $event->overall_comment->submission;
$submitters = $submission->submitters()->get();
$review_coordinators = $submission->reviewCoordinators()->get();
$notification_data = [
'submission' => [
'id' => $submission->id,
'title' => $submission->title,
],
'commentor' => [
'display_label' => $event->overall_comment->createdBy->displayLabel,
],
'type' => 'submission.overall_comment.added',
];
$recipients = $submitters
->merge($review_coordinators)
->unique()
->filter(function ($user) use ($event) {
return $user->id !== $event->overall_comment->createdBy->id;
});

Notification::send($recipients, new OverallCommentAdded($notification_data));
}
}
50 changes: 50 additions & 0 deletions backend/app/Listeners/NotifyUsersAboutOverallCommentReply.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace App\Listeners;

use App\Events\OverallCommentReplyAdded as EventsOverallCommentReplyAdded;
use App\Notifications\OverallCommentReplyAdded;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification;

class NotifyUsersAboutOverallCommentReply extends Notification implements ShouldQueue
{
use Queueable;

/**
* Handle the event.
*
* @param \App\Events\OverallCommentReplyAdded $event
* @return void
*/
public function handle(EventsOverallCommentReplyAdded $event): void
{
$submission = $event->overall_comment->submission;
$submitters = $submission->submitters()->get();
$parent_commentor = $event->overall_comment->parent->createdBy()->get();
$commentors = $event->overall_comment->parent->commentors()->get();
$review_coordinators = $submission->reviewCoordinators()->get();
$notification_data = [
'submission' => [
'id' => $submission->id,
'title' => $submission->title,
],
'commentor' => [
'display_label' => $event->overall_comment->createdBy->displayLabel,
],
'type' => 'submission.overall_comment_reply.added',
];
$recipients = $submitters
->merge($commentors)
->merge($parent_commentor)
->merge($review_coordinators)
->unique()
->filter(function ($user) use ($event) {
return $user->id !== $event->overall_comment->createdBy->id;
});

Notification::send($recipients, new OverallCommentReplyAdded($notification_data));
}
}
Loading
Loading