Open
Description
Thread::addParticipant
does not check to see if a matching soft-deleted participants
record already exists and will create a duplicate record. Thread::activateAllParticipants
can then restore the deleted record.
When multiple active participants
records exist for a single user-thread pair the example project displays unexpected behavior, such as showing threads multiple times.
This could be fixed by updating Thread::addParticipant
to check for existing soft-deleted records.
Example code:
use App\Models\User;
use Cmgmyr\Messenger\Models\Participant;
use Cmgmyr\Messenger\Models\Thread;
$user = User::create([
'name' => 'myself',
'email' => '[email protected]',
'password' => bcrypt('password'),
]);
$thread = Thread::create(['subject' => 'Duplicate Participant']);
echo $thread->participants()->count(); // 0
$thread->addParticipant($user->id);
echo $thread->participants()->count(); // 1
$thread->participants()->delete();
echo $thread->participants()->count(); // 0
$thread->addParticipant($user->id);
echo $thread->participants()->count(); // 1
$thread->activateAllParticipants();
echo $thread->participants()->count(); // 2
Metadata
Metadata
Assignees
Labels
No labels