Skip to content

Commit eb56163

Browse files
authored
feat: blabsy active chat indcator (#320)
1 parent 32c3498 commit eb56163

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ export function ChatList(): JSX.Element {
106106
onClick={() => setCurrentChat(chat)}
107107
className={`flex items-center gap-3 rounded-lg p-3 transition-colors ${
108108
currentChat?.id === chat.id
109-
? 'bg-primary text-white'
110-
: 'hover:bg-gray-100 dark:hover:bg-gray-800'
109+
? 'bg-gray-200 dark:bg-gray-700 border-l-4 border-primary'
110+
: 'hover:bg-gray-50 dark:hover:bg-gray-800'
111111
}`}
112112
>
113113
<div className='relative flex h-10 w-10 items-center justify-center overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700'>
@@ -193,8 +193,8 @@ function ChatListItem({
193193
return (
194194
<button
195195
type='button'
196-
className={`flex w-full items-center gap-3 rounded-lg p-3 transition hover:bg-gray-100 dark:hover:bg-gray-800 ${
197-
isSelected ? 'bg-gray-100 dark:bg-gray-800' : ''
196+
className={`flex w-full items-center gap-3 rounded-lg p-3 transition hover:bg-gray-50 dark:hover:bg-gray-800 ${
197+
isSelected ? 'bg-gray-200 dark:bg-gray-700 border-l-4 border-primary' : ''
198198
}`}
199199
onClick={onClick}
200200
>

platforms/pictique/src/routes/(protected)/messages/[id]/+page.svelte

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
let messageValue = $state('');
1313
let messagesContainer: HTMLDivElement;
1414
15+
// Function to remove duplicate messages by ID
16+
function removeDuplicateMessages(
17+
messagesArray: Record<string, unknown>[]
18+
): Record<string, unknown>[] {
19+
const seen = new Set<string>();
20+
return messagesArray.filter((msg) => {
21+
const id = msg.id as string;
22+
if (seen.has(id)) {
23+
console.log(`Removing duplicate message with ID: ${id}`);
24+
return false;
25+
}
26+
seen.add(id);
27+
return true;
28+
});
29+
}
30+
1531
function scrollToBottom() {
1632
if (messagesContainer) {
1733
messagesContainer.scrollTop = messagesContainer.scrollHeight;
@@ -38,11 +54,17 @@
3854
};
3955
4056
eventSource.onmessage = (e) => {
41-
const data = JSON.parse(e.data);
42-
console.log('messages', data);
43-
addMessages(data);
44-
// Use setTimeout to ensure DOM has updated
45-
setTimeout(scrollToBottom, 0);
57+
try {
58+
const data = JSON.parse(e.data);
59+
console.log('📨 SSE message received:', data);
60+
console.log('Current messages count before adding:', messages.length);
61+
addMessages(data);
62+
console.log('Messages count after adding:', messages.length);
63+
// Use setTimeout to ensure DOM has updated
64+
setTimeout(scrollToBottom, 0);
65+
} catch (error) {
66+
console.error('Error parsing SSE message:', error);
67+
}
4668
};
4769
}
4870
@@ -112,7 +134,18 @@
112134
};
113135
});
114136
115-
messages = messages.concat(processedMessages);
137+
// Prevent duplicate messages by checking IDs
138+
const existingIds = new Set(messages.map((msg) => msg.id));
139+
const uniqueNewMessages = processedMessages.filter((msg) => !existingIds.has(msg.id));
140+
141+
if (uniqueNewMessages.length > 0) {
142+
console.log(`Adding ${uniqueNewMessages.length} new unique messages`);
143+
const newMessagesArray = messages.concat(uniqueNewMessages);
144+
// Final safety check to remove any duplicates
145+
messages = removeDuplicateMessages(newMessagesArray);
146+
} else {
147+
console.log('No new unique messages to add');
148+
}
116149
}
117150
118151
onMount(async () => {
@@ -124,7 +157,7 @@
124157

125158
<section class="chat relative px-0">
126159
<div class="h-[calc(100vh-220px)] overflow-auto" bind:this={messagesContainer}>
127-
{#each messages as msg (msg.id)}
160+
{#each removeDuplicateMessages(messages) as msg (msg.id)}
128161
<ChatMessage
129162
isOwn={msg.isOwn as boolean}
130163
userImgSrc={msg.userImgSrc as string}

0 commit comments

Comments
 (0)