Process packet seenby/path/via lines when saving echomail/netmail

This commit is contained in:
2023-09-20 20:29:23 +10:00
parent 7fedf88d8c
commit 612efda945
11 changed files with 337 additions and 230 deletions

View File

@@ -13,11 +13,11 @@ use Rennokki\QueryCache\Traits\QueryCacheable;
use App\Casts\{CollectionOrNull,CompressedString};
use App\Classes\FTN\Message;
use App\Interfaces\Packet;
use App\Traits\{EncodeUTF8,MsgID};
use App\Traits\{EncodeUTF8,MsgID,ParseAddresses};
final class Echomail extends Model implements Packet
{
use SoftDeletes,EncodeUTF8,MsgID,QueryCacheable;
use SoftDeletes,EncodeUTF8,MsgID,QueryCacheable,ParseAddresses;
private const LOGKEY = 'ME-';
private Collection $set_seenby;
@@ -68,17 +68,17 @@ final class Echomail extends Model implements Packet
// @todo if the message is updated with new SEEN-BY's from another route, we'll delete the pending export for systems (if there is one)
static::created(function($model) {
if (! $model->echoarea_id) {
Log::alert(sprintf('%s:- Message has no echoarea, not exporting',self::LOGKEY,$model->id));
return;
}
$rogue = collect();
$seenby = NULL;
$path = [];
// Save the seenby
$model->seenby()->sync($model->set_seenby);
// Parse PATH
if ($model->set_path->count())
$path = self::parseAddresses('path',$model->set_path,$model->fftn->zone,$rogue);
// Save the Path
$ppoid = NULL;
foreach ($model->set_path as $aoid) {
foreach ($path as $aoid) {
$po = DB::select('INSERT INTO echomail_path (echomail_id,address_id,parent_id) VALUES (?,?,?) RETURNING id',[
$model->id,
$aoid,
@@ -88,12 +88,26 @@ final class Echomail extends Model implements Packet
$ppoid = $po[0]->id;
}
$rogue = collect();
// Parse SEEN-BY
if ($model->set_seenby->count())
$seenby = self::parseAddresses('seenby',$model->set_seenby,$model->fftn->zone,$rogue);
if (count($rogue)) {
$model->rogue_seenby = $rogue;
$model->save();
}
if ($seenby)
$model->seenby()->sync($seenby);
// Our last node in the path is our sender
if (isset($model->set_pkt) && isset($model->set_recvtime)) {
DB::update('UPDATE echomail_path set recv_pkt=?,recv_at=? where address_id=? and echomail_id=?',[
$model->set_pkt,
$model->set_recvtime,
$model->set_path->last(),
$path->last(),
$model->id,
]);
}
@@ -105,7 +119,7 @@ final class Echomail extends Model implements Packet
->addresses
->filter(function($item) use ($model) { return $item->security >= $model->echoarea->sec_read; }))
->pluck('id')
->diff($model->set_seenby);
->diff($seenby);
if ($exportto->count()) {
if ($model->no_export) {