Cast empty Collections to null, Cast strings to zstd compressed strings, add msg_src to echomails processed, fix duplicate seenbys
This commit is contained in:
@@ -10,6 +10,7 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
use App\Casts\{CollectionOrNull,CompressedString};
|
||||
use App\Classes\FTN\Message;
|
||||
use App\Interfaces\Packet;
|
||||
use App\Traits\{EncodeUTF8,MsgID};
|
||||
@@ -19,15 +20,17 @@ final class Echomail extends Model implements Packet
|
||||
use SoftDeletes,EncodeUTF8,MsgID,QueryCacheable;
|
||||
|
||||
private const LOGKEY = 'ME-';
|
||||
private array $set_seenby = [];
|
||||
private array $set_path = [];
|
||||
private Collection $set_seenby;
|
||||
private Collection $set_path;
|
||||
private ?string $set_packet = NULL;
|
||||
private bool $no_export = FALSE;
|
||||
|
||||
protected $casts = [
|
||||
'kludges' => 'json',
|
||||
'rogue_seenby' => 'json',
|
||||
'rogue_path' => 'json',
|
||||
'kludges' => CollectionOrNull::class,
|
||||
'rogue_seenby' => CollectionOrNull::class,
|
||||
'rogue_path' => CollectionOrNull::class,
|
||||
'msg' => CompressedString::class,
|
||||
'msg_src' => CompressedString::class,
|
||||
];
|
||||
|
||||
private const cast_utf8 = [
|
||||
@@ -70,20 +73,16 @@ final class Echomail extends Model implements Packet
|
||||
}
|
||||
|
||||
// Our address
|
||||
$ftns = Setup::findOrFail(config('app.id'))->system->match($model->fftn->zone,Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_HOLD);
|
||||
$ftns = Setup::findOrFail(config('app.id'))
|
||||
->system
|
||||
->match($model->fftn->zone,Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_HOLD);
|
||||
|
||||
// Add our address to the seenby;
|
||||
$model->set_seenby = array_merge($model->set_seenby,$ftns->pluck('id')->toArray());
|
||||
$model->set_path = array_merge($model->set_path,$ftns->pluck('id')->toArray());
|
||||
$model->set_seenby = $model->set_seenby->merge($ftns->pluck('id'))->unique();
|
||||
$model->set_path = $model->set_path->merge($ftns->pluck('id'));
|
||||
|
||||
// Save the seenby
|
||||
foreach ($model->set_seenby as $aoid) {
|
||||
DB::insert('INSERT INTO echomail_seenby (echomail_id,address_id,packet) VALUES (?,?,?)',[
|
||||
$model->id,
|
||||
$aoid,
|
||||
$model->set_packet,
|
||||
]);
|
||||
}
|
||||
$model->seenby()->syncWithPivotValues($model->set_seenby,['packet'=>$model->set_packet]);
|
||||
|
||||
// Save the Path
|
||||
$ppoid = NULL;
|
||||
@@ -109,14 +108,7 @@ final class Echomail extends Model implements Packet
|
||||
Log::debug(sprintf('%s:- Exporting message [%s] to [%s]',self::LOGKEY,$model->id,$exportto->join(',')));
|
||||
|
||||
// Save the seenby for the exported systems
|
||||
$export_at = Carbon::now();
|
||||
foreach ($exportto as $aoid) {
|
||||
DB::insert('INSERT INTO echomail_seenby (echomail_id,address_id,export_at) VALUES (?,?,?)',[
|
||||
$model->id,
|
||||
$aoid,
|
||||
$export_at,
|
||||
]);
|
||||
}
|
||||
$model->seenby()->syncWithPivotValues($exportto,['export_at'=>Carbon::now()],FALSE);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -146,18 +138,6 @@ final class Echomail extends Model implements Packet
|
||||
->withPivot(['id','parent_id']);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getMsgAttribute($value): ?string
|
||||
{
|
||||
return $value ? zstd_uncompress(base64_decode($value)) : NULL;
|
||||
}
|
||||
|
||||
public function getMsgSrcAttribute($value): ?string
|
||||
{
|
||||
return $value ? zstd_uncompress(base64_decode($value)) : NULL;
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
public function jsonSerialize(): array
|
||||
|
Reference in New Issue
Block a user