Some message optimisation, added Echomail processing

This commit is contained in:
Deon George
2021-07-31 00:35:52 +10:00
parent 6f26bc4c71
commit d937547599
15 changed files with 476 additions and 134 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Carbon\Carbon;
use Exception;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -151,6 +152,26 @@ class Address extends Model
return ($o && $o->system->active) ? $o : NULL;
}
/**
* Get echomail for this node
*
* @return Packet|null
*/
public function getEchomail(): ?Packet
{
if (($x=Echomail::select('*') //where('tftn_id',$this->id)
->where(function($q) {
return $q->whereNull('sent')
->orWhere('sent',FALSE);
}))
->count())
{
return $this->getPacket($x->get());
}
return NULL;
}
/**
* Get netmail for this node (including it's children)
*
@@ -165,23 +186,34 @@ class Address extends Model
}))
->count())
{
$o = new Packet($this);
foreach ($x->get() as $oo) {
$o->addNetmail($oo->packet());
$oo->packet = $o->name;
$oo->sent = TRUE;
$oo->sent_at = Carbon::now();
$oo->save();
}
return $o;
return $this->getPacket($x->get());
}
return NULL;
}
/**
* Return a packet of mail
*
* @param Collection $c
* @return Packet
*/
private function getPacket(Collection $c): Packet
{
$o = new Packet($this);
foreach ($c as $oo) {
$o->addMail($oo->packet($this));
$oo->packet = $o->name;
$oo->sent = TRUE;
$oo->sent_at = Carbon::now();
$oo->save();
}
return $o;
}
/**
* Parse a string and split it out as an FTN array
*