Skip to content

Commit

Permalink
Send message in a group if blocked by one member
Browse files Browse the repository at this point in the history
  • Loading branch information
Saodus committed Dec 12, 2024
1 parent 22df795 commit 402ee2c
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions app/Http/Controllers/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,7 @@ public function storeMessage(Request $request, $chatId)
return response()->json(['error' => 'Chat not found or unauthorized.'], 404);
}

if ($chat->members->count() > 2) {
$blockedByAnyone = $chat->members->filter(function ($member) {
return $member->id !== auth()->id();
})->contains(function ($member) {
$friendship = Friendship::where(function ($query) use ($member) {
$query->where('user_id', auth()->id())
->where('friend_id', $member->id);
})->orWhere(function ($query) use ($member) {
$query->where('user_id', $member->id)
->where('friend_id', auth()->id());
})->first();

return $friendship && $friendship->isBlocked();
});

if ($blockedByAnyone) {
return response()->json(['error' => 'You are blocked by one of the members of this group.']);
}
} else {
if ($chat->members->count() == 2) {
$otherMember = $chat->members->firstWhere('id', '!=', auth()->id());

$friendship = Friendship::where(function ($query) use ($otherMember) {
Expand Down

0 comments on commit 402ee2c

Please sign in to comment.