fix userutils (#1861)

This commit is contained in:
AutumnVN 2023-10-25 21:57:50 +07:00 committed by V
parent 788d22f9e9
commit 2478ffb695
6 changed files with 8 additions and 10 deletions

View file

@ -94,7 +94,7 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti
(async () => { (async () => {
for (const user of plugin.authors.slice(0, 6)) { for (const user of plugin.authors.slice(0, 6)) {
const author = user.id const author = user.id
? await UserUtils.fetchUser(`${user.id}`) ? await UserUtils.getUser(`${user.id}`)
.catch(() => makeDummyUser({ username: user.name })) .catch(() => makeDummyUser({ username: user.name }))
: makeDummyUser({ username: user.name }); : makeDummyUser({ username: user.name });

View file

@ -37,7 +37,7 @@ export async function onRelationshipRemove({ relationship: { type, id } }: Relat
return; return;
} }
const user = await UserUtils.fetchUser(id) const user = await UserUtils.getUser(id)
.catch(() => null); .catch(() => null);
if (!user) return; if (!user) return;

View file

@ -68,7 +68,7 @@ export async function syncAndRunChecks() {
for (const id of oldFriends.friends) { for (const id of oldFriends.friends) {
if (friends.friends.includes(id)) continue; if (friends.friends.includes(id)) continue;
const user = await UserUtils.fetchUser(id).catch(() => void 0); const user = await UserUtils.getUser(id).catch(() => void 0);
if (user) if (user)
notify( notify(
`You are no longer friends with ${getUniqueUsername(user)}.`, `You are no longer friends with ${getUniqueUsername(user)}.`,
@ -85,7 +85,7 @@ export async function syncAndRunChecks() {
[RelationshipType.FRIEND, RelationshipType.BLOCKED, RelationshipType.OUTGOING_REQUEST].includes(RelationshipStore.getRelationshipType(id)) [RelationshipType.FRIEND, RelationshipType.BLOCKED, RelationshipType.OUTGOING_REQUEST].includes(RelationshipStore.getRelationshipType(id))
) continue; ) continue;
const user = await UserUtils.fetchUser(id).catch(() => void 0); const user = await UserUtils.getUser(id).catch(() => void 0);
if (user) if (user)
notify( notify(
`Friend request from ${getUniqueUsername(user)} has been revoked.`, `Friend request from ${getUniqueUsername(user)} has been revoked.`,

View file

@ -162,7 +162,7 @@ function Owner(guildId: string, owner: User) {
} }
function ServerInfoTab({ guild }: GuildProps) { function ServerInfoTab({ guild }: GuildProps) {
const [owner] = useAwaiter(() => UserUtils.fetchUser(guild.ownerId), { const [owner] = useAwaiter(() => UserUtils.getUser(guild.ownerId), {
deps: [guild.ownerId], deps: [guild.ownerId],
fallbackValue: null fallbackValue: null
}); });

View file

@ -103,7 +103,7 @@ export function openImageModal(url: string, props?: Partial<React.ComponentProps
const openProfile = findByCodeLazy("friendToken", "USER_PROFILE_MODAL_OPEN"); const openProfile = findByCodeLazy("friendToken", "USER_PROFILE_MODAL_OPEN");
export async function openUserProfile(id: string) { export async function openUserProfile(id: string) {
const user = await UserUtils.fetchUser(id); const user = await UserUtils.getUser(id);
if (!user) throw new Error("No such user: " + id); if (!user) throw new Error("No such user: " + id);
const guildId = SelectedGuildStore.getGuildId(); const guildId = SelectedGuildStore.getGuildId();

View file

@ -20,7 +20,7 @@ import { proxyLazy } from "@utils/lazy";
import type { User } from "discord-types/general"; import type { User } from "discord-types/general";
// eslint-disable-next-line path-alias/no-relative // eslint-disable-next-line path-alias/no-relative
import { _resolveReady, filters, find, findByCodeLazy, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack"; import { _resolveReady, filters, find, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack";
import type * as t from "./types/utils"; import type * as t from "./types/utils";
export let FluxDispatcher: t.FluxDispatcher; export let FluxDispatcher: t.FluxDispatcher;
@ -91,9 +91,7 @@ export function showToast(message: string, type = ToastType.MESSAGE) {
}); });
} }
export const UserUtils = { export const UserUtils = findByPropsLazy("getUser", "fetchCurrentUser") as { getUser: (id: string) => Promise<User>; };
fetchUser: findByCodeLazy(".USER(", "getUser") as (id: string) => Promise<User>,
};
export const Clipboard = mapMangledModuleLazy('document.queryCommandEnabled("copy")||document.queryCommandSupported("copy")', { export const Clipboard = mapMangledModuleLazy('document.queryCommandEnabled("copy")||document.queryCommandSupported("copy")', {
copy: filters.byCode(".copy("), copy: filters.byCode(".copy("),