вложения, канальчики, бим-бим + бам-бам
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
import chadApi from '#shared/chad-api'
|
||||
import { createGlobalState } from '@vueuse/core'
|
||||
|
||||
export interface ChatClientMessage {
|
||||
text: string
|
||||
replyTo?: {
|
||||
messageId: string
|
||||
}
|
||||
// replyTo?: {
|
||||
// messageId: string
|
||||
// }
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
id: string
|
||||
sender: string
|
||||
senderId: string
|
||||
text: string
|
||||
createdAt: string
|
||||
replyTo?: {
|
||||
messageId: string
|
||||
sender: string
|
||||
text: string
|
||||
}
|
||||
updatedAt: string
|
||||
attachments: string[]
|
||||
// replyTo?: {
|
||||
// messageId: string
|
||||
// sender: string
|
||||
// text: string
|
||||
// }
|
||||
}
|
||||
|
||||
export const useChat = createGlobalState(() => {
|
||||
@@ -41,16 +44,16 @@ export const useChat = createGlobalState(() => {
|
||||
})
|
||||
}, { immediate: true, flush: 'sync' })
|
||||
|
||||
function sendMessage(message: ChatClientMessage) {
|
||||
if (!signaling.connected.value)
|
||||
return
|
||||
|
||||
async function sendMessage(message: ChatClientMessage) {
|
||||
message.text = message.text.trim()
|
||||
|
||||
if (!message.text.length)
|
||||
return
|
||||
|
||||
signaling.socket.value!.emit('chat:message', message)
|
||||
await chadApi<ChatMessage>('/chat/send', {
|
||||
method: 'POST',
|
||||
body: message,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user