wip
This commit is contained in:
@@ -3,6 +3,7 @@ import { onMounted, onUnmounted, ref } from 'vue'
|
||||
import { type Chat, useChatsStore } from '@/stores/chats.ts'
|
||||
import { useAuthStore } from '@/stores/auth.ts'
|
||||
import { type Message, useMessagesStore } from '@/stores/messages.ts'
|
||||
import { useUsersStore } from '@/stores/users.ts'
|
||||
|
||||
export enum SocketDataReq {
|
||||
GET_CHATS = 'GET_CHATS',
|
||||
@@ -35,6 +36,7 @@ export const useSocketsStore = defineStore('sockets', () => {
|
||||
const authStore = useAuthStore()
|
||||
const chatsStore = useChatsStore()
|
||||
const messagesStore = useMessagesStore()
|
||||
const usersStore = useUsersStore()
|
||||
|
||||
const isConnected = ref(false)
|
||||
const error = ref<string>()
|
||||
@@ -57,26 +59,29 @@ export const useSocketsStore = defineStore('sockets', () => {
|
||||
|
||||
switch (type) {
|
||||
case SocketDataRes.USERS:
|
||||
console.log('USERS_LIST', data)
|
||||
usersStore.users = data
|
||||
break
|
||||
case SocketDataRes.USER:
|
||||
console.log('USER', data)
|
||||
authStore.me = data
|
||||
break
|
||||
case SocketDataRes.CHATS:
|
||||
console.log('CHATS', data)
|
||||
chatsStore.chats = data
|
||||
if (Array.isArray(data)) {
|
||||
chatsStore.chats = data
|
||||
} else {
|
||||
console.log(data)
|
||||
const idx = chatsStore.chats.findIndex((chat) => chat.id === data.id)
|
||||
console.log(idx)
|
||||
if (idx < 0) chatsStore.chats.push(data)
|
||||
}
|
||||
|
||||
break
|
||||
case SocketDataRes.MESSAGES:
|
||||
console.log('MESSAGES', data)
|
||||
|
||||
messagesStore.messages = data
|
||||
// if (options.onMessage) {
|
||||
// options.onMessage(data)
|
||||
// }
|
||||
break
|
||||
case SocketDataRes.MESSAGE:
|
||||
console.log('MESSAGE', data)
|
||||
messagesStore.messages.unshift(data)
|
||||
break
|
||||
case SocketDataRes.STATUS:
|
||||
|
||||
Reference in New Issue
Block a user