diff options
| author | V <vendicated@riseup.net> | 2023-06-23 18:09:43 +0200 |
|---|---|---|
| committer | V <vendicated@riseup.net> | 2023-06-23 18:09:43 +0200 |
| commit | d7ac418e05f43255c42ea115c9c352cf214753d5 (patch) | |
| tree | cd4c148023aab0aa3ffdd6785e7d22d6ab834613 /src/utils | |
| parent | 214c101740622a8cc1c9cfbce8d51946564441da (diff) | |
| download | Vencord-d7ac418e05f43255c42ea115c9c352cf214753d5.tar.gz Vencord-d7ac418e05f43255c42ea115c9c352cf214753d5.tar.bz2 Vencord-d7ac418e05f43255c42ea115c9c352cf214753d5.zip | |
Fix some plugins displaying legacy discriminators (username#0000)
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/discord.tsx | 31 |
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; +} |
