2019-04-27 13:57:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2021-08-29 01:48:27 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2021-07-30 14:35:52 +00:00
|
|
|
use Jenssegers\Mongodb\Eloquent\Model;
|
|
|
|
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
|
2019-04-27 13:57:39 +00:00
|
|
|
|
2021-07-30 14:35:52 +00:00
|
|
|
use App\Classes\FTN\Message;
|
|
|
|
use App\Interfaces\Packet;
|
2021-08-11 13:45:30 +00:00
|
|
|
use App\Traits\{EncodeUTF8,MsgID,UseMongo};
|
2021-07-30 14:35:52 +00:00
|
|
|
|
|
|
|
class Echomail extends Model implements Packet
|
2019-04-27 13:57:39 +00:00
|
|
|
{
|
2021-08-11 13:45:30 +00:00
|
|
|
use SoftDeletes,MsgID,UseMongo,EncodeUTF8;
|
|
|
|
|
|
|
|
protected $collection = FALSE;
|
|
|
|
|
|
|
|
private const cast_utf8 = [
|
2021-08-26 12:32:32 +00:00
|
|
|
'subject',
|
|
|
|
'msg',
|
2021-08-11 13:45:30 +00:00
|
|
|
];
|
2019-04-27 13:57:39 +00:00
|
|
|
|
2021-07-30 14:35:52 +00:00
|
|
|
protected $dates = ['datetime'];
|
|
|
|
|
|
|
|
/* RELATIONS */
|
2019-04-27 13:57:39 +00:00
|
|
|
|
2021-07-30 14:35:52 +00:00
|
|
|
public function fftn()
|
2019-04-27 13:57:39 +00:00
|
|
|
{
|
2021-07-30 14:35:52 +00:00
|
|
|
return $this
|
|
|
|
->setConnection('pgsql')
|
|
|
|
->belongsTo(Address::class)
|
|
|
|
->withTrashed();
|
2019-04-27 13:57:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-29 01:48:27 +00:00
|
|
|
/* ATTRIBUTES */
|
|
|
|
|
|
|
|
public function getPathAttribute($value): Collection
|
|
|
|
{
|
|
|
|
return Address::whereIn('id',$value)->get()->pluck('ftn3d');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSeenByAttribute($value): Collection
|
|
|
|
{
|
|
|
|
return Address::whereIn('id',$value)->get()->pluck('ftn2d');
|
|
|
|
}
|
|
|
|
|
2021-07-30 14:35:52 +00:00
|
|
|
/* METHODS */
|
|
|
|
|
2021-08-11 13:45:30 +00:00
|
|
|
public function jsonSerialize(): array
|
|
|
|
{
|
|
|
|
return $this->encode();
|
|
|
|
}
|
|
|
|
|
2021-07-30 14:35:52 +00:00
|
|
|
/**
|
|
|
|
* Return this model as a packet
|
|
|
|
*/
|
|
|
|
public function packet(Address $ao): Message
|
2019-04-27 13:57:39 +00:00
|
|
|
{
|
2021-07-30 14:35:52 +00:00
|
|
|
// @todo Dont bundle mail to nodes that have been disabled, or addresses that have been deleted
|
|
|
|
$o = new Message;
|
|
|
|
|
|
|
|
$o->header = [
|
|
|
|
'onode' => $this->fftn->node_id,
|
|
|
|
'dnode' => $ao->node_id,
|
|
|
|
'onet' => $this->fftn->host_id,
|
|
|
|
'dnet' => $ao->host_id,
|
|
|
|
'flags' => 0, // @todo?
|
|
|
|
'cost' => 0,
|
|
|
|
'date'=>$this->datetime->format('d M y H:i:s'),
|
|
|
|
];
|
|
|
|
|
|
|
|
$o->tzutc = $this->datetime->utcOffset($this->tzoffset)->getOffsetString('');
|
|
|
|
$o->user_to = $this->to;
|
|
|
|
$o->user_from = $this->from;
|
|
|
|
$o->subject = $this->subject;
|
|
|
|
$o->echoarea = $this->echoarea;
|
|
|
|
$o->flags = $this->flags;
|
|
|
|
|
|
|
|
$o->kludge->put('mid',$this->id);
|
|
|
|
|
|
|
|
$o->msgid = $this->msgid;
|
|
|
|
if ($this->reply)
|
|
|
|
$o->reply = $this->reply;
|
|
|
|
|
|
|
|
$o->message = $this->msg;
|
|
|
|
|
|
|
|
if ($this->tagline)
|
|
|
|
$o->tagline = $this->tagline;
|
|
|
|
|
|
|
|
if ($this->tearline)
|
|
|
|
$o->tearline = $this->tearline;
|
|
|
|
|
|
|
|
if ($this->origin)
|
|
|
|
$o->origin = $this->origin;
|
|
|
|
|
|
|
|
// @todo SEENBY
|
|
|
|
// @todo PATH
|
|
|
|
|
|
|
|
return $o;
|
2019-04-27 13:57:39 +00:00
|
|
|
}
|
|
|
|
}
|