From 509d43395971d336ac42b77a50bf25a8cd532cea Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 1 Apr 2024 20:21:01 +0800 Subject: [PATCH] :sparkles: Bug fixes --- src/components/chat/ChatMessage.vue | 9 +++- .../chat/renderer/MessageAttachment.vue | 4 +- src/layouts/master.vue | 13 +++++- src/stores/userinfo.ts | 43 ++++++++++++++----- 4 files changed, 53 insertions(+), 16 deletions(-) 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 }