From 74a56d1e17c8e3c68ed34fb8d424d107b1b7294a Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 5 Aug 2023 21:32:45 +1000 Subject: [PATCH] Now correctly showing packet receive time, and sending Notifications based on the packet address, not the node address --- app/Classes/File/Receive.php | 7 ++-- app/Console/Commands/PacketProcess.php | 3 +- app/Jobs/MessageProcess.php | 20 +++++++---- app/Models/Echomail.php | 7 ++-- app/Models/Netmail.php | 7 ++-- .../Netmails/EchoareaNoWrite.php | 2 +- .../Netmails/EchoareaNotSubscribed.php | 2 +- .../2023_08_05_205920_mail_recvtime.php | 34 +++++++++++++++++++ resources/views/system/addedit.blade.php | 16 ++++----- 9 files changed, 74 insertions(+), 24 deletions(-) create mode 100644 database/migrations/2023_08_05_205920_mail_recvtime.php diff --git a/app/Classes/File/Receive.php b/app/Classes/File/Receive.php index b1c1d47..a1df92c 100644 --- a/app/Classes/File/Receive.php +++ b/app/Classes/File/Receive.php @@ -2,6 +2,7 @@ namespace App\Classes\File; +use Carbon\Carbon; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; @@ -100,6 +101,8 @@ class Receive extends Base throw new \Exception('No file to close'); if ($this->f) { + $rcvd_time = Carbon::now(); + if ($this->pos !== $this->receiving->recvsize) Log::warning(sprintf('%s:- Closing [%s], but missing [%d] bytes',self::LOGKEY,$this->receiving->nameas,$this->receiving->recvsize-$this->pos)); else @@ -175,9 +178,9 @@ class Receive extends Base try { // Dispatch job. if ($queue) - MessageProcess::dispatch($msg,$f->pktName(),$this->ao); + MessageProcess::dispatch($msg,$f->pktName(),$this->ao,$po->fftn_o,$rcvd_time); else - MessageProcess::dispatchSync($msg,$f->pktName(),$this->ao); + MessageProcess::dispatchSync($msg,$f->pktName(),$this->ao,$po->fftn_o,$rcvd_time); } catch (\Exception $e) { Log::error(sprintf('%s:! Got error dispatching message [%s] (%d:%s-%s).',self::LOGKEY,$msg->msgid,$e->getLine(),$e->getFile(),$e->getMessage())); diff --git a/app/Console/Commands/PacketProcess.php b/app/Console/Commands/PacketProcess.php index 7c85f58..33abc89 100644 --- a/app/Console/Commands/PacketProcess.php +++ b/app/Console/Commands/PacketProcess.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use Carbon\Carbon; use Illuminate\Console\Command; use App\Classes\File; @@ -47,7 +48,7 @@ class PacketProcess extends Command $this->info(sprintf('Processing message from [%s] with msgid [%s] in (%s)',$msg->fboss,$msg->msgid,$f->pktName())); // Dispatch job. - Job::dispatchSync($msg,$f->pktName(),$a,$this->option('nobot')); + Job::dispatchSync($msg,$f->pktName(),$a,$packet->fftn_o,Carbon::now(),$this->option('nobot')); } } } diff --git a/app/Jobs/MessageProcess.php b/app/Jobs/MessageProcess.php index c9fcc37..4b303de 100644 --- a/app/Jobs/MessageProcess.php +++ b/app/Jobs/MessageProcess.php @@ -23,14 +23,18 @@ class MessageProcess implements ShouldQueue private Address $sender; private Message $msg; + private Address $pktsrc; + private Carbon $recvtime; private bool $skipbot; private string $packet; - public function __construct(Message $msg,string $packet,Address $sender,bool $skipbot=FALSE) + public function __construct(Message $msg,string $packet,Address $sender,Address $pktsrc,Carbon $recvtime,bool $skipbot=FALSE) { $this->msg = $msg; $this->packet = $packet; $this->sender = $sender; + $this->pktsrc = $pktsrc; + $this->recvtime = $recvtime; $this->skipbot = $skipbot; } @@ -111,6 +115,7 @@ class MessageProcess implements ShouldQueue $o->set_pkt = $this->packet; $o->set_sender = $this->sender; $o->set_path = $this->msg->pathaddress; + $o->set_recvtime = $this->recvtime; // Strip any local/transit flags $o->flags &= ~(Message::FLAG_LOCAL|Message::FLAG_INTRANSIT); @@ -222,7 +227,7 @@ class MessageProcess implements ShouldQueue if (! $ea) { Log::alert(sprintf('%s:! Echoarea [%s] doesnt exist for zone [%d]',self::LOGKEY,$this->msg->echoarea,$this->msg->fboss_o->zone->zone_id)); - Notification::route('netmail',$this->sender)->notify(new EchoareaNotExist($this->msg)); + Notification::route('netmail',$this->pktsrc)->notify(new EchoareaNotExist($this->msg)); return; } @@ -281,14 +286,14 @@ class MessageProcess implements ShouldQueue // @todo Can the sender create it if it doesnt exist? // Can the system send messages to this area? - if (! $ea->sec_write || ($this->sender->security < $ea->sec_write)) { - Notification::route('netmail',$this->sender)->notify(new EchoareaNoWrite($this->msg)); + if (! $ea->sec_write || ($this->pktsrc->security < $ea->sec_write)) { + Notification::route('netmail',$this->pktsrc)->notify(new EchoareaNoWrite($this->msg)); return; } - // If the node is not subsccribed - if ($this->sender->echoareas->search(function($item) use ($ea) { return $item->id === $ea->id; }) === FALSE) - Notification::route('netmail',$this->sender)->notify(new EchoareaNotSubscribed($this->msg)); + // If the node is not subscribed + if ($this->pktsrc->echoareas->search(function($item) use ($ea) { return $item->id === $ea->id; }) === FALSE) + Notification::route('netmail',$this->pktsrc)->notify(new EchoareaNotSubscribed($this->msg)); // We know about this area, store it $o = new Echomail; @@ -312,6 +317,7 @@ class MessageProcess implements ShouldQueue $o->rogue_path = $this->msg->rogue_path; $o->set_path = $this->msg->pathaddress; $o->set_seenby = $this->msg->seenaddress; + $o->set_recvtime = $this->recvtime; // Record receiving packet and sender $o->set_pkt = $this->packet; diff --git a/app/Models/Echomail.php b/app/Models/Echomail.php index 9664e8e..cbdd81b 100644 --- a/app/Models/Echomail.php +++ b/app/Models/Echomail.php @@ -22,6 +22,7 @@ final class Echomail extends Model implements Packet private const LOGKEY = 'ME-'; private Collection $set_seenby; private Collection $set_path; + private Carbon $set_recvtime; private string $set_pkt; private bool $no_export = FALSE; @@ -51,6 +52,7 @@ final class Echomail extends Model implements Packet case 'no_export': case 'set_path': case 'set_pkt': + case 'set_recvtime': case 'set_seenby': $this->{$key} = $value; break; @@ -87,9 +89,10 @@ final class Echomail extends Model implements Packet } // Our last node in the path is our sender - if (isset($model->set_pkt)) { - DB::update('UPDATE echomail_path set recv_pkt=? where address_id=? and echomail_id=?',[ + if (isset($model->set_pkt) && isset($model->set_recvtime)) { + DB::update('UPDATE echomail_path set recv_pkt=?,recv_at=? where address_id=? and echomail_id=?',[ $model->set_pkt, + $model->set_recvtime, $model->set_path->last(), $model->id, ]); diff --git a/app/Models/Netmail.php b/app/Models/Netmail.php index f3dee4c..3dd0fcc 100644 --- a/app/Models/Netmail.php +++ b/app/Models/Netmail.php @@ -25,6 +25,7 @@ final class Netmail extends Model implements Packet private Collection $set_path; private Address $set_sender; + private Carbon $set_recvtime; private string $set_pkt; private const cast_utf8 = [ @@ -50,6 +51,7 @@ final class Netmail extends Model implements Packet switch ($key) { case 'set_path': case 'set_pkt': + case 'set_recvtime': case 'set_sender': $this->{$key} = $value; break; @@ -86,9 +88,10 @@ final class Netmail extends Model implements Packet } // Our last node in the path is our sender - if (isset($model->set_pkt) && isset($model->set_sender)) { - DB::update('UPDATE netmail_path set recv_pkt=?,recv_id=? where address_id=? and netmail_id=?',[ + if (isset($model->set_pkt) && isset($model->set_sender) && isset($model->set_recvtime)) { + DB::update('UPDATE netmail_path set recv_pkt=?,recv_at=?,recv_id=? where address_id=? and netmail_id=?',[ $model->set_pkt, + $model->set_recvtime, $model->set_sender->id, Arr::get($model->set_path->last(),'node')->id, $model->id, diff --git a/app/Notifications/Netmails/EchoareaNoWrite.php b/app/Notifications/Netmails/EchoareaNoWrite.php index be8ed9c..7522d87 100644 --- a/app/Notifications/Netmails/EchoareaNoWrite.php +++ b/app/Notifications/Netmails/EchoareaNoWrite.php @@ -59,7 +59,7 @@ class EchoareaNoWrite extends Netmails ) ); - $msg->addText("It appears that you do not have permission to post in this echoarea, so the message from your system was rejected.\r\r"); + $msg->addText(sprintf("It appears that you do not have permission to post in this echoarea using the address [%s], so the message from your system was rejected.\r\r",$ao->ftn)); $msg->addText("Please contact the ZC if you think this is a mistake.\r\r"); $msg->addText($this->message_path($this->mo)); diff --git a/app/Notifications/Netmails/EchoareaNotSubscribed.php b/app/Notifications/Netmails/EchoareaNotSubscribed.php index 8fc3e19..6328040 100644 --- a/app/Notifications/Netmails/EchoareaNotSubscribed.php +++ b/app/Notifications/Netmails/EchoareaNotSubscribed.php @@ -59,7 +59,7 @@ class EchoareaNotSubscribed extends Netmails ) ); - $msg->addText("It appears that you havent been previously subscribed to this echoarea.\r\r"); + $msg->addText(sprintf("It appears that you havent been previously subscribed to this echoarea using the address [%s].\r\r",$ao->ftn)); $msg->addText("Even though your post was accepted, I'm not configured to export any posts to you when others respond, you might like to log in to the web interface and do that.\r\r"); diff --git a/database/migrations/2023_08_05_205920_mail_recvtime.php b/database/migrations/2023_08_05_205920_mail_recvtime.php new file mode 100644 index 0000000..5a40941 --- /dev/null +++ b/database/migrations/2023_08_05_205920_mail_recvtime.php @@ -0,0 +1,34 @@ +datetime('recv_at')->nullable(); + }); + + DB::statement('UPDATE netmail_path SET recv_at=created_at FROM netmails WHERE netmails.id=netmail_path.netmail_id'); + + Schema::table('echomail_path',function (Blueprint $table) { + $table->datetime('recv_at')->nullable(); + }); + + DB::statement('UPDATE echomail_path SET recv_at=created_at FROM echomails WHERE echomails.id=echomail_path.echomail_id'); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index 727508a..ea66d49 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -521,11 +521,11 @@
The last Netmails received (you sent): - @if(($x=\App\Models\Netmail::select(['recv_pkt','created_at',DB::raw('count(*) AS count')]) + @if(($x=\App\Models\Netmail::select(['recv_pkt','recv_at',DB::raw('count(*) AS count')]) ->join('netmail_path',['netmail_path.netmail_id'=>'netmails.id']) ->whereIn('address_id',$o->addresses->pluck('id')) - ->groupBy(['recv_pkt','created_at']) - ->orderBy('created_at','DESC') + ->groupBy(['recv_pkt','recv_at']) + ->orderBy('recv_at','DESC') ->limit(10) ->get())->count()) @@ -541,7 +541,7 @@ @foreach ($x as $oo) - + @endforeach @@ -555,12 +555,12 @@
The last Echomails received (you sent): - @if(($x=\App\Models\Echomail::select(['recv_pkt','created_at',DB::raw('count(*) AS count')]) + @if(($x=\App\Models\Echomail::select(['recv_pkt','recv_at',DB::raw('count(*) AS count')]) ->join('echomail_path',['echomail_path.echomail_id'=>'echomails.id']) ->whereNotNull('recv_pkt') ->whereIn('address_id',$o->addresses->pluck('id')) - ->groupBy(['recv_pkt','created_at']) - ->orderBy('created_at','DESC') + ->groupBy(['recv_pkt','recv_at']) + ->orderBy('recv_at','DESC') ->limit(10) ->get())->count())
{{ $oo->recv_pkt }}{{ $oo->created_at }}{{ $oo->recv_at }} {{ $oo->count }}
@@ -576,7 +576,7 @@ @foreach ($x as $oo) - + @endforeach
{{ $oo->recv_pkt }}{{ $oo->created_at }}{{ $oo->recv_at }} {{ $oo->count }}