aboutsummaryrefslogtreecommitdiff
path: root/src/utils/discord.tsx
diff options
context:
space:
mode:
authorV <vendicated@riseup.net>2023-09-08 03:42:20 +0200
committerGitHub <noreply@github.com>2023-09-08 03:42:20 +0200
commit885c75fdaad811017dd8645c0ed3a7234371897d (patch)
tree45d7eb166d225ba8156a634677d7efd9e70c9703 /src/utils/discord.tsx
parentf2a22c5e57515fd6fc41cece083444d4cbc11ebc (diff)
downloadVencord-885c75fdaad811017dd8645c0ed3a7234371897d.tar.gz
Vencord-885c75fdaad811017dd8645c0ed3a7234371897d.tar.bz2
Vencord-885c75fdaad811017dd8645c0ed3a7234371897d.zip
add custom plugin author popouts (#1712)
Diffstat (limited to 'src/utils/discord.tsx')
-rw-r--r--src/utils/discord.tsx37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/utils/discord.tsx b/src/utils/discord.tsx
index 4f4326b..458509b 100644
--- a/src/utils/discord.tsx
+++ b/src/utils/discord.tsx
@@ -18,7 +18,7 @@
import { MessageObject } from "@api/MessageEvents";
import { findByCodeLazy, findByPropsLazy, findLazy } from "@webpack";
-import { ChannelStore, ComponentDispatch, GuildStore, MaskedLink, ModalImageClasses, PrivateChannelsStore, SelectedChannelStore, SelectedGuildStore, UserUtils } from "@webpack/common";
+import { ChannelStore, ComponentDispatch, FluxDispatcher, GuildStore, MaskedLink, ModalImageClasses, PrivateChannelsStore, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileStore, UserUtils } from "@webpack/common";
import { Guild, Message, User } from "discord-types/general";
import { ImageModal, ModalRoot, ModalSize, openModal } from "./modal";
@@ -118,6 +118,41 @@ export async function openUserProfile(id: string) {
});
}
+interface FetchUserProfileOptions {
+ friend_token?: string;
+ connections_role_id?: string;
+ guild_id?: string;
+ with_mutual_guilds?: boolean;
+ with_mutual_friends_count?: boolean;
+}
+
+/**
+ * Fetch a user's profile
+ */
+export async function fetchUserProfile(id: string, options?: FetchUserProfileOptions) {
+ const cached = UserProfileStore.getUserProfile(id);
+ if (cached) return cached;
+
+ FluxDispatcher.dispatch({ type: "USER_PROFILE_FETCH_START", userId: id });
+
+ const { body } = await RestAPI.get({
+ url: `/users/${id}/profile`,
+ query: {
+ with_mutual_guilds: false,
+ with_mutual_friends_count: false,
+ ...options
+ },
+ oldFormErrors: true,
+ });
+
+ FluxDispatcher.dispatch({ type: "USER_UPDATE", user: body.user });
+ await FluxDispatcher.dispatch({ type: "USER_PROFILE_FETCH_SUCCESS", ...body });
+ if (options?.guild_id && body.guild_member)
+ FluxDispatcher.dispatch({ type: "GUILD_MEMBER_PROFILE_UPDATE", guildId: options.guild_id, guildMember: body.guild_member });
+
+ return UserProfileStore.getUserProfile(id);
+}
+
/**
* Get the unique username for a user. Returns user.username for pomelo people, user.tag otherwise
*/