2024-06-11 04:17:03 +00:00
|
|
|
<?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
|
2024-09-09 09:44:14 +00:00
|
|
|
if (preg_match('/^@.+:/',$event->eo->from))
|
2024-06-11 04:17:03 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|