diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 10822a2..6c0fc2e 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -16,7 +16,7 @@ use Illuminate\Support\ViewErrorBag; use App\Classes\FTN\Message; use App\Http\Requests\{AddressMerge,AreafixRequest,SystemRegister}; use App\Jobs\AddressPoll; -use App\Models\{Address,Echoarea,Filearea,Netmail,Setup,System,Zone}; +use App\Models\{Address,Echoarea,Echomail,Filearea,Netmail,Setup,System,Zone}; use App\Notifications\Netmails\AddressLink; use App\Rules\{FidoInteger,TwoByteInteger}; @@ -336,6 +336,24 @@ class SystemController extends Controller if ($request->validated()) { DB::beginTransaction(); + // Find all the echomails that have both seenby's + $x = Echomail::select(['id']) + ->join('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id']) + ->whereIn('address_id',[$request->src]) + ->distinct() + ->with(['seenby:id']) + ->get() + ->filter(function($item) use ($request) { + return $item->seenby->contains($request->dst) && $item->seenby->contains($request->src); + }); + + // If the Echomail has both source and dest, delete the src + if ($x->count()) + DB::table('echomail_seenby') + ->where('address_id',$request->src) + ->whereIn('echomail_id',$x->pluck('id')) + ->delete(); + // Find all echomail seenbys $x = DB::update('update echomail_seenby set address_id=? where address_id=?',[$request->dst,$request->src]);