From d7ac418e05f43255c42ea115c9c352cf214753d5 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 23 Jun 2023 18:09:43 +0200 Subject: Fix some plugins displaying legacy discriminators (username#0000) --- src/utils/discord.tsx | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/utils') 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 )); } + +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; +} -- cgit