clrghouz/app/Notifications/Echomails/MatrixMessage.php

60 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2024-06-09 23:18:59 +00:00
<?php
namespace App\Notifications\Echomails;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use App\Events\Matrix\Message;
use App\Models\Echomail;
use App\Notifications\Echomails;
use App\Traits\MessagePath;
class MatrixMessage extends Echomails
{
use MessagePath;
private const LOGKEY = 'NMM';
/**
* Post a message from Matrix.
*
* @param Message $mo
*/
public function __construct(private Message $mo)
{
parent::__construct();
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return Echomail
* @throws \Exception
*/
public function toEchomail(object $notifiable): Echomail
{
$echoarea = $notifiable->routeNotificationFor(static::via);
$o = $this->setupEchomail($echoarea);
2024-06-11 04:17:03 +00:00
Log::info(sprintf('%s:+ Sending Matrix Message to [%s]',self::LOGKEY,$echoarea->name),['mo'=>$this->mo]);
2024-06-09 23:18:59 +00:00
$our = our_address($echoarea->domain)->last();
$o->to = 'All';
$o->from = $this->mo->sender;
$o->datetime = Carbon::createFromTimestampMs($this->mo->ts);
$o->subject = $this->mo->topic;
$o->fftn_id = $our->id;
$o->kludges->put('CHRS:','UTF-8 4');
2024-06-11 04:17:03 +00:00
$o->kludges->put('EVENT:',$this->mo->event_id);
2024-06-09 23:18:59 +00:00
// Message
2024-06-11 04:17:03 +00:00
$o->msg = str_replace("\n","\r",$this->mo->message);
2024-06-09 23:18:59 +00:00
$o->set_origin = sprintf('Matrix %s (%s)',$this->mo->room,$our->ftn4d);
$o->save();
return $o;
}
}