diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index e47bea7..c843f5b 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -42,7 +42,7 @@ class Message extends FTNBase 'chrs' => 'CHRS: ', 'charset' => 'CHARSET: ', 'codepage' => 'CODEPAGE: ', - 'mid' => 'MID: ', + 'dbid' => 'DBID: ', 'pid' => 'PID: ', 'replyid' => 'REPLY: ', 'tid' => 'TID: ', @@ -423,6 +423,8 @@ class Message extends FTNBase case 'tagline': case 'tearline': case 'origin': + case 'seenby': + case 'path': case 'via': $this->{$key} = $value; break; @@ -511,7 +513,9 @@ class Message extends FTNBase $return .= sprintf("\01Via %s\r",$v); } else { - // @todo Add echomail SEEN-BY and PATH + // 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(' '),70,"\rPATH: ")); } $return .= "\00"; diff --git a/app/Classes/FTN/Process/Echomail/Test.php b/app/Classes/FTN/Process/Echomail/Test.php index 3976b65..11e1a71 100644 --- a/app/Classes/FTN/Process/Echomail/Test.php +++ b/app/Classes/FTN/Process/Echomail/Test.php @@ -26,7 +26,6 @@ final class Test extends Process private const testing = ['test','testing']; - // @todo add path and other kludges public static function handle(Message $msg): bool { if ((strtolower($msg->user_to) !== 'all') || ! in_array(strtolower($msg->subject),self::testing)) diff --git a/app/Jobs/MessageProcess.php b/app/Jobs/MessageProcess.php index 059631d..77a9bc0 100644 --- a/app/Jobs/MessageProcess.php +++ b/app/Jobs/MessageProcess.php @@ -159,8 +159,8 @@ class MessageProcess implements ShouldQueue self::LOGKEY, $this->msg->msgid, $this->msg->echoarea, - $this->msg->user_to,$this->msg->tftn, - $this->msg->user_from, + $this->msg->user_from,$this->msg->fftn, + $this->msg->user_to, )); if (! $o->msg_crc) diff --git a/app/Models/Echomail.php b/app/Models/Echomail.php index a97acbd..7e915ab 100644 --- a/app/Models/Echomail.php +++ b/app/Models/Echomail.php @@ -5,6 +5,7 @@ namespace App\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Rennokki\QueryCache\Traits\QueryCacheable; @@ -67,6 +68,13 @@ final class Echomail extends Model implements Packet return; } + // Our address + $ftns = Setup::findOrFail(config('app.id'))->system->match($model->fftn->zone); + + // Add our address to the seenby; + $model->set_seenby = array_merge($model->set_seenby,$ftns->pluck('id')->toArray()); + $model->set_path = array_merge($model->set_path,$ftns->pluck('id')->toArray()); + // Save the seenby foreach ($model->set_seenby as $aoid) { DB::insert('INSERT INTO echomail_seenby (echomail_id,address_id,packet) VALUES (?,?,?)',[ @@ -133,7 +141,8 @@ final class Echomail extends Model implements Packet public function path() { - return $this->belongsToMany(Address::class,'echomail_path'); + return $this->belongsToMany(Address::class,'echomail_path') + ->withPivot(['id','parent_id']); } /* METHODS */ @@ -190,11 +199,23 @@ final class Echomail extends Model implements Packet if ($this->origin) $o->origin = $this->origin; - // @todo SEENBY - // @todo PATH + $o->seenby = $this->seenby->pluck('ftn2d'); + $o->path = $this->path->pluck('ftn2d'); $o->packed = TRUE; return $o; } + + public function pathorder(string $display='ftn2d',int $start=NULL): Collection + { + $result = collect(); + + if ($x=$this->path->firstWhere('pivot.parent_id',$start)) { + $result->push($x->$display); + $result->push($this->pathorder($display,$x->pivot->id)); + }; + + return $result->flatten()->filter(); + } } \ No newline at end of file diff --git a/app/Models/OldEchomail.php b/app/Models/OldEchomail.php new file mode 100644 index 0000000..2392ac8 --- /dev/null +++ b/app/Models/OldEchomail.php @@ -0,0 +1,78 @@ + 'json' ]; + + private const cast_utf8 = [ + 'to', + 'from', + 'subject', + 'msg', + 'origin', + 'tearline', + 'tagline', + ]; + protected $dates = ['datetime']; + + public static function resolveConnection($connection = null) + { + return static::$resolver->connection('mongodb'); + } + + /* RELATIONS */ + + public function echoarea() + { + return $this->belongsTo(Echoarea::class); + } + + public function fftn() + { + return $this + ->setConnection('pgsql') + ->belongsTo(Address::class) + ->withTrashed(); + } + + /* ATTRIBUTES */ + + public function getKludgesAttribute(?string $value): Collection + { + return collect($this->castAttribute('kludges',$value)); + } + + public function getPathAttribute(?array $value): Collection + { + if (is_null($value)) + return collect(); + + return Address::whereIn('id',$value) + ->orderBy(DB::raw(sprintf("position (id::text in '(%s)')",join(',',$value)))) + ->get(); + } + + public function getSeenByAttribute(?array $value): Collection + { + if (is_null($value)) + return collect(); + + return Address::whereIn('id',$value)->get(); + } +} \ No newline at end of file diff --git a/app/Traits/MsgID.php b/app/Traits/MsgID.php index 5eb2347..7ebc293 100644 --- a/app/Traits/MsgID.php +++ b/app/Traits/MsgID.php @@ -14,7 +14,7 @@ trait MsgID { public function save(array $options = []) { - // Only create a MSGID for locally generated conetnt + // Only create a MSGID for locally generated content if ((! $this->exists) && ($this->flags & Message::FLAG_LOCAL)) { $ftns = Setup::findOrFail(config('app.id'))->system->match($this->fftn->zone)->first(); diff --git a/app/helpers.php b/app/helpers.php index bd0390d..4c99787 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -159,4 +159,28 @@ if (! function_exists('dwtime')) { return \Carbon\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(\Illuminate\Support\Collection $path): \Illuminate\Support\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 be3e063..bb8b61b 100644 --- a/resources/views/widgets/message.blade.php +++ b/resources/views/widgets/message.blade.php @@ -32,12 +32,12 @@