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 () => {
for (const user of plugin.authors.slice(0, 6)) {
const author = user.id
? await UserUtils.fetchUser(`${user.id}`)
? await UserUtils.getUser(`${user.id}`)
.catch(() => makeDummyUser({ username: user.name }))
: makeDummyUser({ username: user.name });

View File

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

View File

@ -68,7 +68,7 @@ export async function syncAndRunChecks() {
for (const id of oldFriends.friends) {
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)
notify(
`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))
) continue;
const user = await UserUtils.fetchUser(id).catch(() => void 0);
const user = await UserUtils.getUser(id).catch(() => void 0);
if (user)
notify(
`Friend request from ${getUniqueUsername(user)} has been revoked.`,

View File

@ -162,7 +162,7 @@ function Owner(guildId: string, owner: User) {
}
function ServerInfoTab({ guild }: GuildProps) {
const [owner] = useAwaiter(() => UserUtils.fetchUser(guild.ownerId), {
const [owner] = useAwaiter(() => UserUtils.getUser(guild.ownerId), {
deps: [guild.ownerId],
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");
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);
const guildId = SelectedGuildStore.getGuildId();

View File

@ -20,7 +20,7 @@ import { proxyLazy } from "@utils/lazy";
import type { User } from "discord-types/general";
// 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";
export let FluxDispatcher: t.FluxDispatcher;
@ -91,9 +91,7 @@ export function showToast(message: string, type = ToastType.MESSAGE) {
});
}
export const UserUtils = {
fetchUser: findByCodeLazy(".USER(", "getUser") as (id: string) => Promise<User>,
};
export const UserUtils = findByPropsLazy("getUser", "fetchCurrentUser") as { getUser: (id: string) => Promise<User>; };
export const Clipboard = mapMangledModuleLazy('document.queryCommandEnabled("copy")||document.queryCommandSupported("copy")', {
copy: filters.byCode(".copy("),