Basic chat layouts

This commit is contained in:
2024-03-30 21:26:22 +08:00
parent 05e8782557
commit 8bb9816cd0
9 changed files with 199 additions and 13 deletions

37
src/stores/channels.ts Normal file
View File

@@ -0,0 +1,37 @@
import { defineStore } from "pinia"
import { reactive, ref } from "vue"
import { checkLoggedIn, getAtk } from "@/stores/userinfo"
import { request } from "@/scripts/request"
export const useChannels = defineStore("channels", () => {
const done = ref(false)
const show = reactive({
editor: false,
delete: false
})
const related_to = reactive<{ edit_to: any; delete_to: any }>({
edit_to: null,
delete_to: null
})
const available = ref<any[]>([])
const current = ref<any>(null)
const messages = ref<any[]>([])
async function list() {
if (!(await checkLoggedIn())) return
const res = await request("messaging", "/api/channels/me/available", {
headers: { Authorization: `Bearer ${await getAtk()}` }
})
if (res.status !== 200) {
throw new Error(await res.text())
} else {
available.value = await res.json()
}
}
return { done, show, related_to, available, current, messages, list }
})

View File

@@ -31,7 +31,5 @@ export const useRealms = defineStore("realms", () => {
}
}
list().then(() => console.log("[STARTUP HOOK] Fetch available realm successes."))
return { done, show, related: related_to, available, list }
})

View File

@@ -2,6 +2,8 @@ import { defineStore } from "pinia"
import { ref } from "vue"
import { request } from "@/scripts/request"
import { Preferences } from "@capacitor/preferences"
import { useRealms } from "@/stores/realms"
import { useChannels } from "@/stores/channels"
export interface Userinfo {
isReady: boolean
@@ -30,6 +32,10 @@ export async function checkLoggedIn(): Promise<boolean> {
}
export const useUserinfo = defineStore("userinfo", () => {
const userinfoHooks = {
after: [useRealms().list, useChannels().list]
}
const userinfo = ref(defaultUserinfo)
const isReady = ref(false)
@@ -54,6 +60,8 @@ export const useUserinfo = defineStore("userinfo", () => {
displayName: data["nick"],
data: data
}
userinfoHooks.after.forEach((call) => call())
}
return { userinfo, isReady, readProfiles }