diff --git a/packages/ui/src/lib/adapters/firebase/index.ts b/packages/ui/src/lib/adapters/firebase/index.ts index 7267487..2e00c14 100644 --- a/packages/ui/src/lib/adapters/firebase/index.ts +++ b/packages/ui/src/lib/adapters/firebase/index.ts @@ -1,5 +1,5 @@ import { connectWallet } from '$lib/services' -import { chats, type Chat, type Message } from '$lib/stores/chat' +import { chats, type Chat, type Message, type DraftChat } from '$lib/stores/chat' import { personas, type DraftPersona, type Persona } from '$lib/stores/persona' import { profile } from '$lib/stores/profile' import { getFromLocalStorage, saveToLocalStorage } from '$lib/utils' @@ -486,20 +486,24 @@ export class Firebase implements Adapter { }) } - async startChat(chat: Chat): Promise { + async startChat(chat: DraftChat): Promise { const address = get(profile).address if (!address) throw new Error('You need to be logged in to start a chat') if (!chat.post.address) throw new Error('Info about original poster is missing') if (!chat.post.postId) throw new Error('PostId is missing') if (!chat.persona.personaId) throw new Error('PersonaId is missing') - if (chat.messages.length === 0) throw new Error('No messages to start a chat') const dbChat = { users: [address, chat.post.address], - post: chat.post, + post: { + postId: chat.post.postId, + address: chat.post.address, + images: chat.post.images, + timestamp: chat.post.timestamp, + text: chat.post.text, + } as Post, personaId: chat.persona.personaId, - messages: chat.messages, } const chatCollection = collection(db, `/chats`) const chatDoc = await addDoc(chatCollection, dbChat) diff --git a/packages/ui/src/routes/persona/[id]/pending/[postId]/+page.svelte b/packages/ui/src/routes/persona/[id]/pending/[postId]/+page.svelte index 401abfd..e4b4b1f 100644 --- a/packages/ui/src/routes/persona/[id]/pending/[postId]/+page.svelte +++ b/packages/ui/src/routes/persona/[id]/pending/[postId]/+page.svelte @@ -68,11 +68,8 @@ async function sendMessage(text: string) { if (!draftChat) return - const chat = { - ...draftChat, - messages: [{ timestamp: Date.now(), text, address: $profile.address }], - } - const chatId = await adapter.startChat(chat) + const chatId = await adapter.startChat(draftChat) + await adapter.sendChatMessage(chatId, text) goto(ROUTES.CHAT(chatId)) } diff --git a/packages/ui/src/routes/persona/[id]/post/[postId]/+page.svelte b/packages/ui/src/routes/persona/[id]/post/[postId]/+page.svelte index ee44941..ab671a9 100644 --- a/packages/ui/src/routes/persona/[id]/post/[postId]/+page.svelte +++ b/packages/ui/src/routes/persona/[id]/post/[postId]/+page.svelte @@ -38,11 +38,7 @@ async function sendMessage(text: string) { if (!draftChat) return - const chat = { - ...draftChat, - messages: [], - } - const chatId = await adapter.startChat(chat) + const chatId = await adapter.startChat(draftChat) await adapter.sendChatMessage(chatId, text) goto(ROUTES.CHAT(chatId)) }