Move the send DB updates out of the protocol and into Send::class

This commit is contained in:
2023-07-19 12:32:41 +10:00
parent 7584e3e44e
commit f4fc6c24a4
6 changed files with 67 additions and 58 deletions

View File

@@ -4,7 +4,10 @@ namespace App\Classes\File;
use Carbon\Carbon;
use App\Classes\FTN\Packet;
use Illuminate\Support\Facades\DB;
use App\Classes\Node;
use App\Classes\FTN\{Message,Packet};
final class Mail extends Send
{
@@ -48,10 +51,35 @@ final class Mail extends Send
}
}
public function close(bool $successful): void
public function close(bool $successful,Node $node): void
{
if ($successful)
if ($successful) {
$this->complete = TRUE;
// Update netmail table
if (($this->type === Send::T_NETMAIL)
&& ($x=$this->dbids)->count())
DB::table('netmails')
->whereIn('id',$x)
->update([
'sent_at'=>Carbon::now(),
'sent_pkt'=>$this->name,
'sent_id'=>$node->address->id,
'flags'=>DB::raw('flags | '.Message::FLAG_SENT),
]);
// Update echomails table
elseif (($this->type === Send::T_ECHOMAIL)
&& ($x=$this->dbids)->count()
&& $node->aka_remote_authed->count())
DB::table('echomail_seenby')
->whereIn('echomail_id',$x)
->whereIn('address_id',$node->aka_remote_authed->pluck('id'))
->update([
'sent_at'=>Carbon::now(),
'sent_pkt'=>$this->name,
]);
}
}
public function feof(): bool