- {#each chat.channelMessages as msg (msg.id.toString())}
+ {#each messages as msg, i (msg.id.toString())}
{@const isHighlighted = (chat.pendingThreadParentMessageId === msg.id) || (chat.activeThread?.parentMessageId === msg.id)}
{/each}
diff --git a/src/chat/components/ThreadMessageList.svelte b/src/chat/components/ThreadMessageList.svelte
index b33f2a7..bd444af 100644
--- a/src/chat/components/ThreadMessageList.svelte
+++ b/src/chat/components/ThreadMessageList.svelte
@@ -9,13 +9,35 @@
threadMessages: readonly Types.Message[],
onContentLoad?: () => void
} = $props();
+
+ const messages = $derived(threadMessages);
+
+ const messageGroups = $derived.by(() => {
+ return messages.map((msg, index) => {
+ if (index === 0) return false;
+ const prevMsg = messages[index - 1];
+
+ try {
+ const sameSender = msg.sender.toHexString() === prevMsg.sender.toHexString();
+ const sameThread = msg.threadId === prevMsg.threadId;
+ const diff = msg.sent.microsSinceUnixEpoch - prevMsg.sent.microsSinceUnixEpoch;
+ // Ensure non-negative and within 5 mins (300,000,000 micros)
+ const withinFiveMinutes = diff >= 0n && diff < 300000000n;
+
+ return sameSender && sameThread && withinFiveMinutes;
+ } catch {
+ return false;
+ }
+ });
+ });
- {#each threadMessages as msg (msg.id.toString())}
+ {#each messages as msg, i (msg.id.toString())}
{/each}
diff --git a/src/chat/services/messaging.svelte.ts b/src/chat/services/messaging.svelte.ts
index df8368b..abcc1c0 100644
--- a/src/chat/services/messaging.svelte.ts
+++ b/src/chat/services/messaging.svelte.ts
@@ -171,7 +171,7 @@ export class MessagingService {
if (!isExpanded) {
// In non-expanded mode, strictly ONLY show the cache for THIS channel
return mappedRecent.sort((a, b) =>
- Number(BigInt(a.sent.microsSinceUnixEpoch) - BigInt(b.sent.microsSinceUnixEpoch))
+ a.sent.microsSinceUnixEpoch < b.sent.microsSinceUnixEpoch ? -1 : (a.sent.microsSinceUnixEpoch > b.sent.microsSinceUnixEpoch ? 1 : 0)
);
}
@@ -191,7 +191,7 @@ export class MessagingService {
}
return Array.from(msgMap.values()).sort((a, b) =>
- Number(BigInt(a.sent.microsSinceUnixEpoch) - BigInt(b.sent.microsSinceUnixEpoch))
+ a.sent.microsSinceUnixEpoch < b.sent.microsSinceUnixEpoch ? -1 : (a.sent.microsSinceUnixEpoch > b.sent.microsSinceUnixEpoch ? 1 : 0)
);
}
@@ -243,7 +243,7 @@ export class MessagingService {
}
return Array.from(msgMap.values()).sort((a, b) =>
- Number(BigInt(a.sent.microsSinceUnixEpoch) - BigInt(b.sent.microsSinceUnixEpoch))
+ a.sent.microsSinceUnixEpoch < b.sent.microsSinceUnixEpoch ? -1 : (a.sent.microsSinceUnixEpoch > b.sent.microsSinceUnixEpoch ? 1 : 0)
);
}