Support merging addresses when both src/dst addresses are in the seenby

This commit is contained in:
Deon George 2024-04-13 20:54:05 +10:00
parent 03ca4c10b1
commit 2edc41b11e
1 changed files with 19 additions and 1 deletions

View File

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