Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread::addParticipant ignores soft-deleted participants #407

Open
LucasBrunner opened this issue Jan 2, 2025 · 0 comments
Open

Thread::addParticipant ignores soft-deleted participants #407

LucasBrunner opened this issue Jan 2, 2025 · 0 comments

Comments

@LucasBrunner
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant