Add DBID back to messages, add path/seen-by to generated messages, other minor cosmetic fixes

This commit is contained in:
Deon George 2022-01-22 23:08:46 +11:00
parent fe9fbb88b0
commit efa7195633
8 changed files with 137 additions and 11 deletions

View File

@ -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";

View File

@ -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))

View File

@ -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)

View File

@ -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();
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace App\Models;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Jenssegers\Mongodb\Eloquent\Model;
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
use App\Interfaces\Packet;
final class OldEchomail extends Model
{
use SoftDeletes;
private const LOGKEY = 'ME-';
protected $table = 'echomails';
protected $collection = FALSE;
protected $casts = [ 'kludges' => '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();
}
}

View File

@ -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();

View File

@ -160,3 +160,27 @@ 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;
}
}

View File

@ -32,12 +32,12 @@
<div class="row pb-2">
<div class="col-8">
SEENBY: <br><strong class="highlight">{!! $msg->seenby->pluck('ftn2d')->join('</strong>, <strong class="highlight">') !!}</strong>
SEENBY: <br><strong class="highlight">{!! optimize_path($msg->seenby->pluck('ftn2d'))->join('</strong>, <strong class="highlight">') !!}</strong>
</div>
</div>
<div class="row pb-2">
<div class="col-8">
PATH: <br><strong class="highlight">{!! $msg->path->pluck('ftn3d')->join('</strong> -> <strong class="highlight">') !!}</strong>
PATH: <br><strong class="highlight">{!! optimize_path($msg->pathorder())->join('</strong> -> <strong class="highlight">') !!}</strong>
</div>
</div>