feat: implement fetchMe
This commit is contained in:
parent
0ea12e7f00
commit
58fe9a2eac
3 changed files with 13 additions and 3 deletions
|
@ -44,9 +44,11 @@ import type { MessageResponse, ScrollPosition, UserResponse } from '~/types/inte
|
||||||
import scrollToBottom from '~/utils/scrollToBottom';
|
import scrollToBottom from '~/utils/scrollToBottom';
|
||||||
import { generateIrcColor } from '#imports';
|
import { generateIrcColor } from '#imports';
|
||||||
|
|
||||||
|
const { fetchMe } = useApi()
|
||||||
|
|
||||||
const props = defineProps<{ channelUrl: string, amount?: number, offset?: number }>();
|
const props = defineProps<{ channelUrl: string, amount?: number, offset?: number }>();
|
||||||
|
|
||||||
const me = await fetchWithApi("/me") as UserResponse;
|
const me = await fetchMe() as UserResponse;
|
||||||
|
|
||||||
const messageTimestamps = ref<Record<string, number>>({});
|
const messageTimestamps = ref<Record<string, number>>({});
|
||||||
const messagesType = ref<Record<string, "normal" | "grouped">>({});
|
const messagesType = ref<Record<string, "normal" | "grouped">>({});
|
||||||
|
|
|
@ -21,6 +21,10 @@ export const useApi = () => {
|
||||||
return ensureIsArray(await fetchWithApi(`/me/guilds`));
|
return ensureIsArray(await fetchWithApi(`/me/guilds`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchMe(): Promise<UserResponse | undefined> {
|
||||||
|
return await fetchWithApi("/me")
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchChannels(guildId: string): Promise<ChannelResponse[]> {
|
async function fetchChannels(guildId: string): Promise<ChannelResponse[]> {
|
||||||
return ensureIsArray(await fetchWithApi(`/guilds/${guildId}/channels`));
|
return ensureIsArray(await fetchWithApi(`/guilds/${guildId}/channels`));
|
||||||
}
|
}
|
||||||
|
@ -98,6 +102,7 @@ export const useApi = () => {
|
||||||
fetchGuilds,
|
fetchGuilds,
|
||||||
fetchGuild,
|
fetchGuild,
|
||||||
fetchMyGuilds,
|
fetchMyGuilds,
|
||||||
|
fetchMe,
|
||||||
fetchChannels,
|
fetchChannels,
|
||||||
fetchChannel,
|
fetchChannel,
|
||||||
fetchMembers,
|
fetchMembers,
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import type { MessageProps } from "~/types/props";
|
import type { MessageProps } from "~/types/props";
|
||||||
|
|
||||||
|
const { fetchMe } = useApi()
|
||||||
|
|
||||||
export default async (element: HTMLDivElement, props: MessageProps) => {
|
export default async (element: HTMLDivElement, props: MessageProps) => {
|
||||||
console.log("message:", element);
|
console.log("message:", element);
|
||||||
const me = await fetchWithApi("/me") as any;
|
const me = await fetchMe();
|
||||||
if (props.author?.uuid == me.uuid) {
|
|
||||||
|
if (me && props.author?.uuid == me.uuid) {
|
||||||
const text = element.getElementsByClassName("message-text")[0] as HTMLDivElement;
|
const text = element.getElementsByClassName("message-text")[0] as HTMLDivElement;
|
||||||
text.contentEditable = "true";
|
text.contentEditable = "true";
|
||||||
text.focus();
|
text.focus();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue