2024-05-17 12:10:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common Attributes used by message packets (and thus their Models)
|
|
|
|
*/
|
|
|
|
namespace App\Traits;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2024-05-20 11:31:21 +00:00
|
|
|
use Illuminate\Support\MessageBag;
|
2024-05-17 12:10:54 +00:00
|
|
|
|
|
|
|
use App\Classes\FTN\Message;
|
2024-06-03 09:08:40 +00:00
|
|
|
use App\Models\{Address,Echomail,Origin,Tagline,Tearline};
|
2024-05-17 12:10:54 +00:00
|
|
|
|
|
|
|
trait MessageAttributes
|
|
|
|
{
|
|
|
|
// Items we need to set when creating()
|
|
|
|
public Collection $set;
|
|
|
|
// Validation Errors
|
2024-05-20 11:31:21 +00:00
|
|
|
public ?MessageBag $errors = NULL;
|
2024-05-17 12:10:54 +00:00
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
// Init
|
|
|
|
$this->set = collect();
|
|
|
|
}
|
|
|
|
|
2024-06-03 09:08:40 +00:00
|
|
|
/* RELATIONS */
|
2024-05-17 12:10:54 +00:00
|
|
|
|
2024-06-03 09:08:40 +00:00
|
|
|
public function fftn()
|
2024-05-17 12:10:54 +00:00
|
|
|
{
|
2024-06-03 09:08:40 +00:00
|
|
|
return $this
|
|
|
|
->belongsTo(Address::class)
|
|
|
|
->withTrashed();
|
|
|
|
}
|
2024-05-17 12:10:54 +00:00
|
|
|
|
2024-06-03 09:08:40 +00:00
|
|
|
public function origin()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Origin::class);
|
|
|
|
}
|
2024-05-17 12:10:54 +00:00
|
|
|
|
2024-06-03 09:08:40 +00:00
|
|
|
public function tagline()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Tagline::class);
|
|
|
|
}
|
2024-05-17 12:10:54 +00:00
|
|
|
|
2024-06-03 09:08:40 +00:00
|
|
|
public function tearline()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Tearline::class);
|
|
|
|
}
|
2024-05-17 12:10:54 +00:00
|
|
|
|
2024-06-03 09:08:40 +00:00
|
|
|
/* ATTRIBUTES */
|
2024-05-17 12:10:54 +00:00
|
|
|
|
2024-06-03 09:08:40 +00:00
|
|
|
public function getContentAttribute(): string
|
|
|
|
{
|
|
|
|
return ($this->msg_src) ? $this->msg_src : $this->rebuildMessage();
|
2024-05-17 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 03:09:48 +00:00
|
|
|
/** @deprecated use datetime? */
|
2024-05-17 12:10:54 +00:00
|
|
|
public function getDateAttribute(): Carbon
|
|
|
|
{
|
2024-06-25 03:09:48 +00:00
|
|
|
Log::alert(sprintf('%s:! This function is deprecated',self::LOGKEY),['class'=>get_class($this)]);
|
|
|
|
return $this->datetime;
|
2024-05-17 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getOriginAttribute(string $val=NULL): ?string
|
|
|
|
{
|
2024-06-03 09:08:40 +00:00
|
|
|
if (($x=$this->getRelationValue('origin')) && $x->value)
|
|
|
|
return $x->complete($this->fftn);
|
|
|
|
|
|
|
|
if (($this->set->has('set_origin')) || ($val))
|
|
|
|
return sprintf(' * Origin: %s',$this->set->get('set_origin',$val));
|
|
|
|
|
|
|
|
return NULL;
|
2024-05-17 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTaglineAttribute(string $val=NULL): ?string
|
|
|
|
{
|
2024-06-03 09:08:40 +00:00
|
|
|
if (($x=$this->getRelationValue('tagline')) && $x->value)
|
|
|
|
return $x->complete();
|
|
|
|
|
|
|
|
if (($this->set->has('set_tagline')) || ($val))
|
|
|
|
return sprintf('... %s',$this->set->get('set_tagline',$val));
|
|
|
|
|
|
|
|
return NULL;
|
2024-05-17 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTearlineAttribute(string $val=NULL): ?string
|
|
|
|
{
|
2024-06-03 09:08:40 +00:00
|
|
|
if (($x=$this->getRelationValue('tearline')) && $x->value)
|
|
|
|
return $x->complete();
|
|
|
|
|
|
|
|
if (($this->set->has('set_tearline')) || ($val))
|
|
|
|
return sprintf('--- %s',$this->set->get('set_tearline',$val));
|
|
|
|
|
|
|
|
return NULL;
|
2024-05-17 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* METHODS */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array of flag descriptions
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*
|
|
|
|
* http://ftsc.org/docs/fsc-0001.000
|
|
|
|
* AttributeWord bit meaning
|
|
|
|
* --- --------------------
|
|
|
|
* 0 + Private
|
|
|
|
* 1 + s Crash
|
|
|
|
* 2 Recd
|
|
|
|
* 3 Sent
|
|
|
|
* 4 + FileAttached
|
|
|
|
* 5 InTransit
|
|
|
|
* 6 Orphan
|
|
|
|
* 7 KillSent
|
|
|
|
* 8 Local
|
|
|
|
* 9 s HoldForPickup
|
|
|
|
* 10 + unused
|
|
|
|
* 11 s FileRequest
|
|
|
|
* 12 + s ReturnReceiptRequest
|
|
|
|
* 13 + s IsReturnReceipt
|
|
|
|
* 14 + s AuditRequest
|
|
|
|
* 15 s FileUpdateReq
|
|
|
|
*
|
|
|
|
* s - this bit is supported by SEAdog only
|
|
|
|
* + - this bit is not zeroed before packeting
|
|
|
|
*/
|
|
|
|
public function flags(): Collection
|
|
|
|
{
|
|
|
|
return collect([
|
|
|
|
'private' => $this->isFlagSet(Message::FLAG_PRIVATE),
|
|
|
|
'crash' => $this->isFlagSet(Message::FLAG_CRASH),
|
|
|
|
'recd' => $this->isFlagSet(Message::FLAG_RECD),
|
|
|
|
'sent' => $this->isFlagSet(Message::FLAG_SENT),
|
|
|
|
'fileattach' => $this->isFlagSet(Message::FLAG_FILEATTACH),
|
|
|
|
'intransit' => $this->isFlagSet(Message::FLAG_INTRANSIT),
|
|
|
|
'orphan' => $this->isFlagSet(Message::FLAG_ORPHAN),
|
|
|
|
'killsent' => $this->isFlagSet(Message::FLAG_KILLSENT),
|
|
|
|
'local' => $this->isFlagSet(Message::FLAG_LOCAL),
|
|
|
|
'hold' => $this->isFlagSet(Message::FLAG_HOLD),
|
|
|
|
'unused-10' => $this->isFlagSet(Message::FLAG_UNUSED_10),
|
|
|
|
'filereq' => $this->isFlagSet(Message::FLAG_FREQ),
|
|
|
|
'receipt-req' => $this->isFlagSet(Message::FLAG_RETRECEIPT),
|
|
|
|
'receipt' => $this->isFlagSet(Message::FLAG_ISRETRECEIPT),
|
|
|
|
'audit' => $this->isFlagSet(Message::FLAG_AUDITREQ),
|
|
|
|
'fileupdate' => $this->isFlagSet(Message::FLAG_FILEUPDATEREQ),
|
2024-05-19 13:28:45 +00:00
|
|
|
'pktpasswd' => $this->isFlagSet(Message::FLAG_PKTPASSWD),
|
2024-05-17 12:10:54 +00:00
|
|
|
])->filter();
|
|
|
|
}
|
|
|
|
|
2024-05-19 13:28:45 +00:00
|
|
|
public function isFlagSet($flag): bool
|
2024-05-17 12:10:54 +00:00
|
|
|
{
|
|
|
|
return ($this->flags & $flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return this model as a packet
|
|
|
|
*/
|
|
|
|
public function packet(Address $ao): Message
|
|
|
|
{
|
2024-06-17 09:03:48 +00:00
|
|
|
Log::debug(sprintf('%s:+ Bundling [%s] for [%s]',self::LOGKEY,$this->id,$ao->ftn3d),['type'=>get_class($this)]);
|
2024-05-17 12:10:54 +00:00
|
|
|
|
2024-05-26 12:08:39 +00:00
|
|
|
// For echomail, our tftn is this address
|
|
|
|
if ($this instanceof Echomail)
|
|
|
|
$this->tftn = $ao;
|
|
|
|
|
2024-05-17 12:10:54 +00:00
|
|
|
// @todo Dont bundle mail to nodes that have been disabled, or addresses that have been deleted
|
|
|
|
return Message::packMessage($this);
|
|
|
|
}
|
|
|
|
|
2024-06-03 09:08:40 +00:00
|
|
|
public function rebuildMessage(): string
|
|
|
|
{
|
|
|
|
// If we have a msg_src attribute, we'll use that
|
2024-06-06 22:42:10 +00:00
|
|
|
$result = $this->msg."\r\r";
|
2024-06-03 09:08:40 +00:00
|
|
|
|
|
|
|
if ($x=$this->tagline)
|
|
|
|
$result .= sprintf("%s\r",$x);
|
|
|
|
|
|
|
|
if ($x=$this->tearline)
|
|
|
|
$result .= sprintf("%s\r",$x);
|
|
|
|
|
|
|
|
if ($x=$this->origin)
|
|
|
|
$result .= sprintf("%s",$x);
|
|
|
|
|
|
|
|
return rtrim($result,"\r");
|
|
|
|
}
|
|
|
|
|
2024-05-17 12:10:54 +00:00
|
|
|
/**
|
|
|
|
* Return our path in order
|
|
|
|
*
|
|
|
|
* @param string $display
|
|
|
|
* @param int|NULL $start
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|