aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/discord.tsx31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/utils/discord.tsx b/src/utils/discord.tsx
index 2752645..4f4326b 100644
--- a/src/utils/discord.tsx
+++ b/src/utils/discord.tsx
@@ -17,9 +17,9 @@
*/
import { MessageObject } from "@api/MessageEvents";
-import { findByPropsLazy, findLazy } from "@webpack";
-import { ChannelStore, ComponentDispatch, GuildStore, MaskedLink, ModalImageClasses, PrivateChannelsStore, SelectedChannelStore } from "@webpack/common";
-import { Guild, Message } from "discord-types/general";
+import { findByCodeLazy, findByPropsLazy, findLazy } from "@webpack";
+import { ChannelStore, ComponentDispatch, GuildStore, MaskedLink, ModalImageClasses, PrivateChannelsStore, SelectedChannelStore, SelectedGuildStore, UserUtils } from "@webpack/common";
+import { Guild, Message, User } from "discord-types/general";
import { ImageModal, ModalRoot, ModalSize, openModal } from "./modal";
@@ -99,3 +99,28 @@ export function openImageModal(url: string, props?: Partial<React.ComponentProps
</ModalRoot>
));
}
+
+const openProfile = findByCodeLazy("friendToken", "USER_PROFILE_MODAL_OPEN");
+
+export async function openUserProfile(id: string) {
+ const user = await UserUtils.fetchUser(id);
+ if (!user) throw new Error("No such user: " + id);
+
+ const guildId = SelectedGuildStore.getGuildId();
+ openProfile({
+ userId: id,
+ guildId,
+ channelId: SelectedChannelStore.getChannelId(),
+ analyticsLocation: {
+ page: guildId ? "Guild Channel" : "DM Channel",
+ section: "Profile Popout"
+ }
+ });
+}
+
+/**
+ * Get the unique username for a user. Returns user.username for pomelo people, user.tag otherwise
+ */
+export function getUniqueUsername(user: User) {
+ return user.discriminator === "0" ? user.username : user.tag;
+}