Files
projectsend/app/Modules/Comments/Notifications/CommentPostedNotification.php
ignacionelson 6e47d76ba6 ProjectSend 2.0.0
Client file sharing, rebuilt from the ground up: a private area per
client, resumable uploads, folders, groups and categories, sharing with
expiry dates and download limits, comments, file versions, an activity
log, a REST API, and sixteen languages.

This repository begins here. ProjectSend 2 was developed privately, and
that development history is not published — the previous generation
remains available, with its own history, at projectsend/legacy.

Free software under the GNU General Public License v2, or (at your
option) any later version.
2026-08-14 01:38:12 -03:00

74 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Comments\Notifications;
use App\Modules\Notifications\PendingNotification;
use App\Modules\Platform\Notifications\Concerns\RendersOverridableMail;
use App\Modules\Platform\Notifications\EmailTemplateSlot;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
/**
* A single comment, emailed once the digest window closed with only one
* thing in it. Sent by SendNotificationDigest, never by Notifier — see
* NotificationTypeDefinition's $digestMail.
*
* **The comment's body is deliberately not in the email.** A comment can
* be visible to one client only, and email is forwarded, quoted and left
* open on screens. This says something was said and where; the reader
* opens the file and reads it under the same rules as everyone else.
*/
class CommentPostedNotification extends Notification implements ShouldQueue
{
use Queueable, RendersOverridableMail;
public function __construct(
private readonly string $fileName,
private readonly string $authorName,
private readonly ?int $fileId,
) {}
public static function from(PendingNotification $item): self
{
return new self(
$item->subject_name,
(string) ($item->context['author_name'] ?? __('Someone')),
isset($item->context['file_id']) ? (int) $item->context['file_id'] : null,
);
}
/**
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['mail'];
}
public function toMail(object $notifiable): MailMessage
{
$replacements = [':name' => $this->fileName, ':author' => $this->authorName];
$message = ($override = $this->overrideOrNull(EmailTemplateSlot::CommentPosted)) !== null
? $this->mailFromOverride($override, $replacements)
: (new MailMessage)
->subject(__('New comment on ":name"', ['name' => $this->fileName]))
->line(__(':author commented on ":name".', ['author' => $this->authorName, 'name' => $this->fileName]));
return $message->action(__('Read the comment'), $this->url());
}
/**
* The deep link resolves per viewer (staff and clients have no page in
* common), so it is safe to send the same URL to either.
*/
private function url(): string
{
return $this->fileId === null ? route('my-files.index') : route('comments.go', $this->fileId);
}
}