Add DBID back to messages, add path/seen-by to generated messages, other minor cosmetic fixes

This commit is contained in:
Deon George
2022-01-22 23:08:46 +11:00
parent fe9fbb88b0
commit efa7195633
8 changed files with 137 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Rennokki\QueryCache\Traits\QueryCacheable;
@@ -67,6 +68,13 @@ final class Echomail extends Model implements Packet
return;
}
// Our address
$ftns = Setup::findOrFail(config('app.id'))->system->match($model->fftn->zone);
// 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());
// Save the seenby
foreach ($model->set_seenby as $aoid) {
DB::insert('INSERT INTO echomail_seenby (echomail_id,address_id,packet) VALUES (?,?,?)',[
@@ -133,7 +141,8 @@ final class Echomail extends Model implements Packet
public function path()
{
return $this->belongsToMany(Address::class,'echomail_path');
return $this->belongsToMany(Address::class,'echomail_path')
->withPivot(['id','parent_id']);
}
/* METHODS */
@@ -190,11 +199,23 @@ final class Echomail extends Model implements Packet
if ($this->origin)
$o->origin = $this->origin;
// @todo SEENBY
// @todo PATH
$o->seenby = $this->seenby->pluck('ftn2d');
$o->path = $this->path->pluck('ftn2d');
$o->packed = TRUE;
return $o;
}
public function pathorder(string $display='ftn2d',int $start=NULL): Collection
{
$result = collect();
if ($x=$this->path->firstWhere('pivot.parent_id',$start)) {
$result->push($x->$display);
$result->push($this->pathorder($display,$x->pivot->id));
};
return $result->flatten()->filter();
}
}