From ffa0f06ea032ff6c5fd9daf5baa216cc8431ae94 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Wed, 28 May 2025 02:06:20 -0400 Subject: [PATCH] allow callers to pass in hint objects to admin-user and instance-info --- packages/frontend/src/pages/admin-user.vue | 35 +++++++++++++------ packages/frontend/src/pages/instance-info.vue | 13 ++++--- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/packages/frontend/src/pages/admin-user.vue b/packages/frontend/src/pages/admin-user.vue index 0596b165fd..f629078aac 100644 --- a/packages/frontend/src/pages/admin-user.vue +++ b/packages/frontend/src/pages/admin-user.vue @@ -273,8 +273,14 @@ import SkBadgeStrip from '@/components/SkBadgeStrip.vue'; const props = withDefaults(defineProps<{ userId: string; initialTab?: string; + userHint?: Misskey.entities.UserDetailed; + infoHint?: Misskey.entities.AdminShowUserResponse; + ipsHint?: Misskey.entities.AdminGetUserIpsResponse; }>(), { initialTab: 'overview', + userHint: undefined, + infoHint: undefined, + ipsHint: undefined, }); const tab = ref(props.initialTab); @@ -405,16 +411,23 @@ const announcementsPagination = { }; const expandedRoles = ref([]); -function createFetcher() { - return () => Promise.all([misskeyApi('users/show', { - userId: props.userId, - }), misskeyApi('admin/show-user', { - userId: props.userId, - }), iAmAdmin ? misskeyApi('admin/get-user-ips', { - userId: props.userId, - }) : Promise.resolve(null), iAmAdmin ? misskeyApi('ap/get', { - uri: `${url}/users/${props.userId}`, - }).catch(() => null) : null]).then(([_user, _info, _ips, _ap]) => { +function createFetcher(withHint = true) { + return () => Promise.all([ + (withHint && props.userHint) ? props.userHint : misskeyApi('users/show', { + userId: props.userId, + }), + (withHint && props.infoHint) ? props.infoHint : misskeyApi('admin/show-user', { + userId: props.userId, + }), + iAmAdmin + ? (withHint && props.ipsHint) ? props.ipsHint : misskeyApi('admin/get-user-ips', { + userId: props.userId, + }) + : null, + iAmAdmin ? misskeyApi('ap/get', { + uri: `${url}/users/${props.userId}`, + }).catch(() => null) : null], + ).then(([_user, _info, _ips, _ap]) => { user.value = _user; info.value = _info; ips.value = _ips; @@ -432,7 +445,7 @@ function createFetcher() { async function refreshUser() { // Not a typo - createFetcher() returns a function() - await createFetcher()(); + await createFetcher(false)(); } async function onMandatoryCWChanged(value: string) { diff --git a/packages/frontend/src/pages/instance-info.vue b/packages/frontend/src/pages/instance-info.vue index b60bdf3a72..93f673288c 100644 --- a/packages/frontend/src/pages/instance-info.vue +++ b/packages/frontend/src/pages/instance-info.vue @@ -238,9 +238,14 @@ import SkBadgeStrip from '@/components/SkBadgeStrip.vue'; const $style = useCssModule(); -const props = defineProps<{ +const props = withDefaults(defineProps<{ host: string; -}>(); + metaHint?: Misskey.entities.AdminMetaResponse; + instanceHint?: Misskey.entities.FederationInstance; +}>(), { + metaHint: undefined, + instanceHint: undefined, +}); const tab = ref('overview'); @@ -365,8 +370,8 @@ async function saveModerationNote() { async function fetch(): Promise { const [m, i] = await Promise.all([ - iAmAdmin ? misskeyApi('admin/meta') : null, - misskeyApi('federation/show-instance', { + props.metaHint ?? (iAmAdmin ? misskeyApi('admin/meta') : null), + props.instanceHint ?? misskeyApi('federation/show-instance', { host: props.host, }), ]);