mirror of
https://github.com/acid-info/Kurate.git
synced 2025-02-11 23:36:25 +00:00
fix: chat in firebase (#386)
This commit is contained in:
parent
7dd6c59b4a
commit
10137cf1e3
@ -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<string> {
|
||||
async startChat(chat: DraftChat): Promise<string> {
|
||||
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)
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user