implement sending Emoji, pin or mute conversation

This commit is contained in:
2026-05-01 11:30:14 +03:30
parent 1121939c25
commit 7b2541dd35
11 changed files with 359 additions and 12 deletions

View File

@@ -196,12 +196,19 @@ class ConversationList extends Component
->forUser($user)
->with([
'participants' => fn ($query) => $query
->select(['id', 'conversation_id', 'user_id', 'role', 'last_read_at'])
->select(['id', 'conversation_id', 'user_id', 'role', 'last_read_at', 'muted_until', 'pinned_at'])
->with('user:id,name,email'),
'latestMessage' => fn ($query) => $query
->select(['messages.id', 'messages.conversation_id', 'messages.user_id', 'messages.type', 'messages.body', 'messages.metadata', 'messages.created_at']),
'latestMessage.sender:id,name,email',
])
->addSelect([
'current_participant_pinned_at' => ConversationParticipant::query()
->select('pinned_at')
->whereColumn('conversation_participants.conversation_id', 'conversations.id')
->where('conversation_participants.user_id', $user->id)
->limit(1),
])
->withMax('messages', 'created_at')
->withCount([
'messages as unread_messages_count' => fn (Builder $messages) => $messages
@@ -224,6 +231,7 @@ class ConversationList extends Component
->where('name', 'like', "%{$search}%")
->orWhere('email', 'like', "%{$search}%")));
}))
->orderByDesc('current_participant_pinned_at')
->orderByDesc('messages_max_created_at')
->orderByDesc('updated_at')
->limit(40)
@@ -336,6 +344,16 @@ class ConversationList extends Component
]);
}
public function isPinnedFor(Conversation $conversation): bool
{
return (bool) $this->currentParticipantFor($conversation)?->isPinned();
}
public function isMutedFor(Conversation $conversation): bool
{
return (bool) $this->currentParticipantFor($conversation)?->isMuted();
}
public function isOnline(Conversation $conversation): bool
{
$participant = $this->otherParticipant($conversation);
@@ -343,6 +361,12 @@ class ConversationList extends Component
return $participant instanceof User && $participant->id % 3 !== 0;
}
private function currentParticipantFor(Conversation $conversation): ?ConversationParticipant
{
return $conversation->participants
->first(fn (ConversationParticipant $participant) => $participant->user_id === Auth::id());
}
private function otherParticipant(Conversation $conversation): ?User
{
return $conversation->participants