diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index 2524a14..612ecb8 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -495,8 +495,8 @@ class Message extends FTNBase } else { // Seenby & PATH - FSC-0068 - $return .= sprintf("SEEN-BY: %s\r",wordwrap(optimize_path($this->seenby)->join(' '),70,"\rSEEN-BY: ")); - $return .= sprintf("\01PATH: %s\r",wordwrap(optimize_path($this->path)->join(' '),73,"\rPATH: ")); + $return .= $this->optimise_path($this->seenby,'SEEN-BY:')."\r"; + $return .= "\x01".$this->optimise_path($this->path,'PATH:')."\r"; } $return .= "\00"; @@ -514,6 +514,44 @@ class Message extends FTNBase $this->decode($values); } + /** + * Reduce our PATH/SEEN-BY for messages as per FSC-0068 + * + * @param Collection $path + * @param string $prefix + * @param int $len + * @param string $delim + * @return string + */ + function optimise_path(Collection $path,string $prefix,int $len=79,string $delim="\r"): string + { + $cur = NULL; + $result = $prefix; + $c = strlen($prefix); + + foreach ($path as $address) { + [$host,$node] = explode('/',$address); + + if (($c+strlen(' '.$host)) > $len) { + $result .= ($x=$delim.$prefix); + $c = strlen($x); + $cur = NULL; + } + + if ($host !== $cur) { + $cur = $host; + $result .= ($x=' '.$address); + + } else { + $result .= ($x=' '.$node); + } + + $c += strlen($x); + } + + return $result; + } + /** * Parse a message from a packet * diff --git a/app/helpers.php b/app/helpers.php index 4c44878..d134499 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -162,29 +162,4 @@ if (! function_exists('wtime')) { return Carbon::create($year,$month,$day,$hr,$min,$sec+$milli/10); } -} - -if (! function_exists('optimize_path')) { - /** - * This will optimize an array of paths to show the smallest number of characters - */ - function optimize_path(Collection $path): Collection - { - $cur = NULL; - $result = collect(); - - foreach ($path as $address) { - [$host,$node] = explode('/',$address); - - if ($host !== $cur) { - $cur = $host; - $result->push($address); - - } else { - $result->push($node); - } - } - - return $result; - } } \ No newline at end of file diff --git a/resources/views/widgets/message.blade.php b/resources/views/widgets/message.blade.php index 3cc89c0..232e0ab 100644 --- a/resources/views/widgets/message.blade.php +++ b/resources/views/widgets/message.blade.php @@ -42,7 +42,7 @@ use App\Classes\FTN\Message; @if ($msg instanceof \App\Models\Echomail)