Skip to content

Commit 79a3ab9

Browse files
committed
fix: search bug
1 parent ee83003 commit 79a3ab9

File tree

8 files changed

+279
-121
lines changed

8 files changed

+279
-121
lines changed

platforms/blabsy/firestore.rules

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,22 @@ service cloud.firestore {
4646

4747
match /chats/{chatId} {
4848
allow read: if request.auth != null;
49-
allow create: if request.auth != null && request.auth.uid in request.resource.data.participants;
50-
allow update: if request.auth != null && request.auth.uid in resource.data.participants;
51-
allow delete: if request.auth != null && request.auth.uid in resource.data.participants;
49+
allow create: if request.auth != null &&
50+
(request.auth.uid in request.resource.data.participants ||
51+
('@' + request.auth.uid) in request.resource.data.participants);
52+
allow update: if request.auth != null &&
53+
(request.auth.uid in resource.data.participants ||
54+
('@' + request.auth.uid) in resource.data.participants);
55+
allow delete: if request.auth != null &&
56+
(request.auth.uid in resource.data.participants ||
57+
('@' + request.auth.uid) in resource.data.participants);
5258
}
5359

5460
match /chats/{chatId}/messages/{messageId} {
5561
allow read: if request.auth != null;
56-
allow create: if request.auth != null &&
57-
request.auth.uid in get(/databases/$(database)/documents/chats/$(chatId)).data.participants &&
58-
request.auth.uid == resource.data.senderId;
59-
allow update: if request.auth != null &&
60-
request.auth.uid in get(/databases/$(database)/documents/chats/$(chatId)).data.participants;
61-
allow delete: if request.auth != null &&
62-
request.auth.uid in get(/databases/$(database)/documents/chats/$(chatId)).data.participants &&
63-
request.auth.uid == resource.data.senderId;
62+
allow create: if request.auth != null;
63+
allow update: if request.auth != null;
64+
allow delete: if request.auth != null;
6465
}
6566
}
6667
}

platforms/blabsy/src/components/chat/add-members.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function AddMembers({
183183
!selectedUsers.some(
184184
(selected) => selected.id === userData.id
185185
) && // Exclude already selected
186-
!currentChat?.participants.includes(userData.id) && // Exclude existing chat participants
186+
(newChat || !currentChat?.participants.includes(userData.id)) && // Only exclude existing participants if NOT creating new chat
187187
(userData.name
188188
?.toLowerCase()
189189
.includes(query.toLowerCase()) ||
@@ -482,7 +482,7 @@ export function AddMembers({
482482
(u) => u.id === userItem.id
483483
);
484484
const isExistingMember =
485-
currentChat?.participants.includes(userItem.id);
485+
!newChat && currentChat?.participants.includes(userItem.id);
486486

487487
return (
488488
<label

platforms/blabsy/src/components/chat/chat-list.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function ChatList(): JSX.Element {
4646
}
4747

4848
if (Object.keys(newParticipantData).length > 0) {
49+
console.log('ChatList: Fetched new participant data:', newParticipantData);
4950
setParticipantData((prev) => ({
5051
...prev,
5152
...newParticipantData
@@ -54,7 +55,7 @@ export function ChatList(): JSX.Element {
5455
};
5556

5657
void fetchParticipantData();
57-
}, [chats, user, participantData]);
58+
}, [chats, user]); // Removed participantData from dependencies
5859

5960
if (loading) {
6061
console.log('ChatList: Loading state');
@@ -109,7 +110,19 @@ export function ChatList(): JSX.Element {
109110
}`}
110111
>
111112
<div className='relative flex h-10 w-10 items-center justify-center overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700'>
112-
{participant?.photoURL ? (
113+
{chat.type === 'group' ? (
114+
chat.photoURL ? (
115+
<Image
116+
src={chat.photoURL}
117+
alt={chat.name || 'Group'}
118+
width={40}
119+
height={40}
120+
className='object-cover'
121+
/>
122+
) : (
123+
<UserIcon className='h-6 w-6' />
124+
)
125+
) : participant?.photoURL ? (
113126
<Image
114127
src={participant.photoURL}
115128
alt={

platforms/blabsy/src/components/chat/chat-window.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ export function ChatWindow(): JSX.Element {
149149
otherParticipant &&
150150
newParticipantsData[otherParticipant]
151151
) {
152+
console.log('ChatWindow: Setting otherUser:', newParticipantsData[otherParticipant]);
152153
setOtherUser(newParticipantsData[otherParticipant]);
154+
} else {
155+
console.log('ChatWindow: Could not set otherUser. otherParticipant:', otherParticipant, 'userData:', otherParticipant ? newParticipantsData[otherParticipant] : 'undefined');
153156
}
154157
}
155158
} catch (error) {
@@ -209,13 +212,23 @@ export function ChatWindow(): JSX.Element {
209212
<div className='flex h-fit items-center justify-between gap-3 border-b border-gray-200 p-4 dark:border-gray-800'>
210213
<div className='flex items-center gap-3'>
211214
<div className='relative flex h-10 w-10 items-center justify-center overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700'>
212-
{otherUser?.photoURL ? (
215+
{currentChat.type === 'group' ? (
216+
currentChat.photoURL ? (
217+
<Image
218+
src={currentChat.photoURL}
219+
alt={currentChat.name || 'Group'}
220+
width={40}
221+
height={40}
222+
className='object-cover'
223+
/>
224+
) : (
225+
<UserIcon className='h-6 w-6' />
226+
)
227+
) : otherUser?.photoURL ? (
213228
<Image
214229
src={otherUser.photoURL}
215230
alt={
216-
otherUser.name ||
217-
otherUser.username ||
218-
'User'
231+
otherUser.name || otherUser.username || 'User'
219232
}
220233
width={40}
221234
height={40}
@@ -235,7 +248,9 @@ export function ChatWindow(): JSX.Element {
235248
</p>
236249
<p className='text-sm text-gray-500 dark:text-gray-400'>
237250
{currentChat.type === 'direct'
238-
? 'Direct Message'
251+
? otherUser?.username
252+
? `@${otherUser.username}`
253+
: 'Direct Message'
239254
: `${currentChat.participants.length} participants`}
240255
</p>
241256
</div>

0 commit comments

Comments
 (0)