allow callers to pass in hint objects to admin-user and instance-info

This commit is contained in:
Hazelnoot 2025-05-28 02:06:20 -04:00
parent 645e27fc9e
commit ffa0f06ea0
2 changed files with 33 additions and 15 deletions

View file

@ -273,8 +273,14 @@ import SkBadgeStrip from '@/components/SkBadgeStrip.vue';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
userId: string; userId: string;
initialTab?: string; initialTab?: string;
userHint?: Misskey.entities.UserDetailed;
infoHint?: Misskey.entities.AdminShowUserResponse;
ipsHint?: Misskey.entities.AdminGetUserIpsResponse;
}>(), { }>(), {
initialTab: 'overview', initialTab: 'overview',
userHint: undefined,
infoHint: undefined,
ipsHint: undefined,
}); });
const tab = ref(props.initialTab); const tab = ref(props.initialTab);
@ -405,16 +411,23 @@ const announcementsPagination = {
}; };
const expandedRoles = ref([]); const expandedRoles = ref([]);
function createFetcher() { function createFetcher(withHint = true) {
return () => Promise.all([misskeyApi('users/show', { return () => Promise.all([
userId: props.userId, (withHint && props.userHint) ? props.userHint : misskeyApi('users/show', {
}), misskeyApi('admin/show-user', { userId: props.userId,
userId: props.userId, }),
}), iAmAdmin ? misskeyApi('admin/get-user-ips', { (withHint && props.infoHint) ? props.infoHint : misskeyApi('admin/show-user', {
userId: props.userId, userId: props.userId,
}) : Promise.resolve(null), iAmAdmin ? misskeyApi('ap/get', { }),
uri: `${url}/users/${props.userId}`, iAmAdmin
}).catch(() => null) : null]).then(([_user, _info, _ips, _ap]) => { ? (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; user.value = _user;
info.value = _info; info.value = _info;
ips.value = _ips; ips.value = _ips;
@ -432,7 +445,7 @@ function createFetcher() {
async function refreshUser() { async function refreshUser() {
// Not a typo - createFetcher() returns a function() // Not a typo - createFetcher() returns a function()
await createFetcher()(); await createFetcher(false)();
} }
async function onMandatoryCWChanged(value: string) { async function onMandatoryCWChanged(value: string) {

View file

@ -238,9 +238,14 @@ import SkBadgeStrip from '@/components/SkBadgeStrip.vue';
const $style = useCssModule(); const $style = useCssModule();
const props = defineProps<{ const props = withDefaults(defineProps<{
host: string; host: string;
}>(); metaHint?: Misskey.entities.AdminMetaResponse;
instanceHint?: Misskey.entities.FederationInstance;
}>(), {
metaHint: undefined,
instanceHint: undefined,
});
const tab = ref('overview'); const tab = ref('overview');
@ -365,8 +370,8 @@ async function saveModerationNote() {
async function fetch(): Promise<void> { async function fetch(): Promise<void> {
const [m, i] = await Promise.all([ const [m, i] = await Promise.all([
iAmAdmin ? misskeyApi('admin/meta') : null, props.metaHint ?? (iAmAdmin ? misskeyApi('admin/meta') : null),
misskeyApi('federation/show-instance', { props.instanceHint ?? misskeyApi('federation/show-instance', {
host: props.host, host: props.host,
}), }),
]); ]);