diff --git a/src/components/chat/ChatMessage.vue b/src/components/chat/ChatMessage.vue index b3bf540..14b198b 100644 --- a/src/components/chat/ChatMessage.vue +++ b/src/components/chat/ChatMessage.vue @@ -35,8 +35,8 @@
- - + +
@@ -46,12 +46,17 @@ diff --git a/src/stores/userinfo.ts b/src/stores/userinfo.ts index fbcdcfe..81aef2a 100644 --- a/src/stores/userinfo.ts +++ b/src/stores/userinfo.ts @@ -29,10 +29,26 @@ export async function getRtk() { return (await Preferences.get({ key: "identity.refresh_token" })).value } +export async function getIdSet() { + const value = (await Preferences.get({ key: "userinfo.id_set" })).value + if (value == null) return null + else return JSON.parse(value) +} + +export async function setIdSet(data: any) { + await Preferences.set({ key: "userinfo.id_set", value: JSON.stringify(data) }) +} + export async function checkLoggedIn(): Promise { return (await Preferences.get({ key: "identity.access_token" })).value != null } +export async function signout() { + await Preferences.remove({ key: "identity.access_token" }) + await Preferences.remove({ key: "identity.refresh_token" }) + await Preferences.remove({ key: "userinfo.id_set" }) +} + export const useUserinfo = defineStore("userinfo", () => { const userinfoHooks = { after: [useRealms().list, useChannels().list, useChannels().connect] @@ -54,24 +70,29 @@ export const useUserinfo = defineStore("userinfo", () => { } const data = await res.json() + let idSet = await getIdSet() - const federationResp = await Promise.all([ - request("interactive", "/api/users/me", { - headers: { Authorization: `Bearer ${await getAtk()}` } - }), - request("messaging", "/api/users/me", { - headers: { Authorization: `Bearer ${await getAtk()}` } + if (idSet == null) { + const federationResp = await Promise.all([ + request("interactive", "/api/users/me", { + headers: { Authorization: `Bearer ${await getAtk()}` } + }), + request("messaging", "/api/users/me", { + headers: { Authorization: `Bearer ${await getAtk()}` } + }) + ]) + await setIdSet({ + interactive: (await federationResp[0].json())["id"], + messaging: (await federationResp[1].json())["id"] }) - ]) + idSet = await getIdSet() + } userinfo.value = { isReady: true, isLoggedIn: true, displayName: data["nick"], - idSet: { - interactive: (await federationResp[0].json())["id"], - messaging: (await federationResp[1].json())["id"] - }, + idSet: idSet, data: data }