clrghouz/app/Notifications/Netmails.php
Deon George 4d7af7c7e3
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 42s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m51s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s
Store datetime in UTC format now, and fix presentation of TZUTC. Also standardise message summaries on Notifications
2024-06-28 23:27:06 +10:00

81 lines
1.9 KiB
PHP

<?php
namespace App\Notifications;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use App\Classes\FTN\Message;
use App\Models\{Echomail,Netmail,Setup};
abstract class Netmails extends Notification //implements ShouldQueue
{
use Queueable;
protected const via = 'netmail';
private const LOGKEY = 'NN-';
/**
* Create a new notification instance.
*/
public function __construct()
{
$this->queue = 'netmail';
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
* @todo change to object $notifiable
*/
public function via($notifiable)
{
return [ self::via ];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
abstract public function toNetmail(object $notifiable): Netmail;
protected function setupNetmail(object $notifiable): Netmail
{
// @todo Redirect netmails to Hubs or higher to the admin
$ao = $notifiable->routeNotificationFor(static::via);
$ao->load('system');
$o = new Netmail;
$o->to = $ao->system->sysop;
$o->from = Setup::PRODUCT_NAME;
$o->datetime = Carbon::now()->utc();
$o->tzoffset = Carbon::now()->utcOffset();
$o->fftn_id = our_address($ao)->id;
$o->tftn_id = $ao->id;
$o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE);
$o->cost = 0;
$o->set_tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
return $o;
}
protected function sourceSummary(Echomail|Netmail $o,string $item=NULL): string
{
return sprintf("Your %s was received here on [%s] and it looks like you sent it on [%s].",
$item ?: sprintf('%s with ID [%s] to [%s]',$o instanceof Netmail ? 'Netmail' : 'Echomail',$o->msgid,$o->to),
Carbon::now()->utc()->toDateTimeString(),
$o->date->utc()->toDateTimeString(),
);
}
}