Skip to content

Commit 924cd0a

Browse files
author
RainbowBird
committed
feat(client): store chats by userid instead of session id
1 parent 550bcac commit 924cd0a

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

packages/client/src/stores/useAccount.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { computed, ref, watch } from 'vue'
55
import { toast } from 'vue-sonner'
66

77
import { useBridgeStore } from '../composables/useBridge'
8+
import { useChatStore } from './useChat'
89
import { useMessageStore } from './useMessage'
910

1011
export const useAccountStore = defineStore('account', () => {
@@ -40,6 +41,8 @@ export const useAccountStore = defineStore('account', () => {
4041

4142
if (session?.isReady || !session?.session) {
4243
logger.verbose('No need to login', { session })
44+
45+
useChatStore().fetchChats()
4346
return
4447
}
4548

packages/client/src/stores/useChat.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,32 @@ export const useChatStore = defineStore('chat', () => {
1414

1515
const chats = computed({
1616
get: () => {
17-
const sessionId = bridgeStore.activeSessionId
18-
if (!sessionId)
17+
const userId = bridgeStore.activeSession?.me?.id
18+
if (!userId)
1919
return []
20-
return allChats.value[sessionId] ?? []
20+
return allChats.value[userId] ?? []
2121
},
2222
set: (v) => {
23-
const sessionId = bridgeStore.activeSessionId
24-
if (!sessionId)
23+
const userId = bridgeStore.activeSession?.me?.id
24+
if (!userId)
2525
return
2626

2727
allChats.value = {
2828
...allChats.value,
29-
[sessionId]: v,
29+
[userId]: v,
3030
}
3131
},
3232
})
3333

34-
const getChat = (id: string) => {
34+
function getChat(id: string) {
3535
return chats.value.find(chat => chat.id === Number(id))
3636
}
3737

38-
const init = () => {
38+
function fetchChats() {
39+
bridgeStore.sendEvent('dialog:fetch')
40+
}
41+
42+
function init() {
3943
useLogger('ChatStore').log('Init dialogs')
4044

4145
if (chats.value.length === 0) {
@@ -53,6 +57,7 @@ export const useChatStore = defineStore('chat', () => {
5357
return {
5458
init,
5559
getChat,
60+
fetchChats,
5661
chats,
5762
}
5863
})

0 commit comments

Comments
 (0)