Add workaround for guild role api changes on canary/ptb

fixes RoleColorEverywhere, ServerInfo, PermissionViewer, BetterRoleContext
This commit is contained in:
Vendicated 2024-03-11 16:13:07 +01:00
parent 497f0de9a1
commit 34390e0365
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
8 changed files with 35 additions and 18 deletions

View file

@ -18,7 +18,7 @@
import { MessageObject } from "@api/MessageEvents";
import { ChannelStore, ComponentDispatch, FluxDispatcher, GuildStore, InviteActions, MaskedLink, MessageActions, ModalImageClasses, PrivateChannelsStore, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common";
import { Guild, Message, User } from "discord-types/general";
import { Guild, Message, Role, User } from "discord-types/general";
import { ImageModal, ModalRoot, ModalSize, openModal } from "./modal";
@ -185,3 +185,11 @@ export async function fetchUserProfile(id: string, options?: FetchUserProfileOpt
export function getUniqueUsername(user: User) {
return user.discriminator === "0" ? user.username : user.tag;
}
// FIXME: remove this once discord merges the role change into stable
export function getGuildRoles(guildId: string): Record<string, Role> {
if ("getRoles" in GuildStore)
return (GuildStore as any).getRoles(guildId);
return GuildStore.getGuild(guildId)?.roles ?? {};
}