wip
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import type { User } from '@/stores/users.ts'
|
||||
import type { Message } from '@/stores/messages.ts'
|
||||
import { useAuthStore } from '@/stores/auth.ts'
|
||||
|
||||
export interface Chat {
|
||||
id: string
|
||||
@@ -12,8 +13,31 @@ export interface Chat {
|
||||
}
|
||||
|
||||
export const useChatsStore = defineStore('chats', () => {
|
||||
const authStore = useAuthStore()
|
||||
const chats = ref<Chat[]>([])
|
||||
const selected = ref<string>()
|
||||
const selected = ref<string[]>([])
|
||||
|
||||
return { chats, selected }
|
||||
const selectedChat = computed(() => {
|
||||
const chatId = selected.value[0]
|
||||
|
||||
return chats.value.find((chat: Chat) => {
|
||||
return chat.id === chatId
|
||||
})
|
||||
})
|
||||
|
||||
function getChatInfo(chat: Chat) {
|
||||
switch (chat.typeId) {
|
||||
case 1:
|
||||
const user = chat.users.find((user) => {
|
||||
return user.id !== authStore.me?.id
|
||||
})
|
||||
return user ?? chat
|
||||
case 2:
|
||||
return chat
|
||||
default:
|
||||
return chat
|
||||
}
|
||||
}
|
||||
|
||||
return { chats, selected, selectedChat, getChatInfo }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user