clrghouz/app/Listeners/EchomailListener.php
Deon George a46ce7ff9e
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 1m55s
Create Docker Image / Final Docker Image Manifest (push) Successful in 11s
Posting messages to matrix
2024-06-11 17:23:59 +10:00

43 lines
1.1 KiB
PHP

<?php
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use App\Notifications\Matrix\Echomail;
class EchomailListener implements ShouldQueue
{
protected const LOGKEY = 'LEL';
public string $queue = 'matrix';
/**
* Create the event listener.
*/
public function __construct()
{
}
/**
* Handle the event.
*/
public function handle(object $event): void
{
$ea = $event->eo->echoarea;
// Catch our messages that we've posted, so they dont go back
if (str_ends_with($event->eo->from,':'.config('matrix.server')))
return;
if ($ea && collect(config('matrix.rooms'))->contains($ea->name)) {
Log::debug(sprintf('%s:- Sending echomail to matrix for [%s]',self::LOGKEY,$event->eo->msgid));
Notification::route('matrix',collect(config('matrix.rooms'))->search($ea->name))->notify(new Echomail($event->eo->withoutRelations()));
} else {
Log::debug(sprintf('%s:- Not sending echomail to matrix for [%s]',self::LOGKEY,$event->eo->msgid));
}
}
}