refac/enh: channel message

This commit is contained in:
Timothy Jaeryang Baek committed 2025-11-28 10:45:48 -05:00
1 parent b9e849f17d
commit 25994dd3da
6 files changed
+32 -7

No files matched your search

+24 -3
View File
@@ -4,6 +4,7 @@
import { onDestroy, onMount, tick } from 'svelte';
import { goto } from '$app/navigation';
import { v4 as uuidv4 } from 'uuid';
import {
chatId,
@@ -118,7 +119,8 @@
if (type === 'message') {
if ((data?.parent_id ?? null) === null) {
messages = [data, ...messages];
const tempId = data?.temp_id ?? null;
messages = [{ ...data, temp_id: null }, ...messages.filter((m) => m?.temp_id !== tempId)];
if (typingUsers.find((user) => user.id === event.user.id)) {
typingUsers = typingUsers.filter((user) => user.id !== event.user.id);
@@ -183,11 +185,30 @@
return;
}
const res = await sendMessage(localStorage.token, id, {
const tempId = uuidv4();
const message = {
temp_id: tempId,
content: content,
data: data,
reply_to_id: replyToMessage?.id ?? null
}).catch((error) => {
};
const ts = Date.now() * 1000000; // nanoseconds
messages = [
{
...message,
id: tempId,
user_id: $user?.id,
user: $user,
reply_to_message: replyToMessage ?? null,
created_at: ts,
updated_at: ts
},
...messages
];
const res = await sendMessage(localStorage.token, id, message).catch((error) => {
toast.error(`${error}`);
return null;
});