re-implement suspension toggle to match other controls

This commit is contained in:
Hazelnoot 2024-10-11 10:16:57 -04:00
parent 5a49955064
commit f496d4b88b

View file

@ -47,7 +47,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkButton inline :disabled="!instance" danger @click="deleteAllFiles">{{ i18n.ts.deleteAllFiles }}</MkButton>
<MkButton inline :disabled="!instance" danger @click="severAllFollowRelations">{{ i18n.ts.severAllFollowRelations }}</MkButton>
</div>
<MkSwitch v-model="isSuspended" :disabled="!instance">{{ i18n.ts._delivery.stop }}</MkSwitch>
<MkSwitch v-model="isSuspended" :disabled="!instance" @update:modelValue="toggleSuspended">{{ i18n.ts._delivery.stop }}</MkSwitch>
<MkInfo v-if="isBaseBlocked" warn>{{ i18n.ts.blockedByBase }}</MkInfo>
<MkSwitch v-model="isBlocked" :disabled="!meta || !instance || isBaseBlocked" @update:modelValue="toggleBlock">{{ i18n.ts.blockThisInstance }}</MkSwitch>
<MkInfo v-if="isBaseSilenced" warn>{{ i18n.ts.silencedByBase }}</MkInfo>
@ -205,6 +205,7 @@ const chartSrc = ref('instance-requests');
const meta = ref<Misskey.entities.AdminMetaResponse | null>(null);
const instance = ref<Misskey.entities.FederationInstance | null>(null);
const suspensionState = ref<'none' | 'manuallySuspended' | 'goneSuspended' | 'autoSuspendedForNotResponding'>('none');
const isSuspended = ref(false);
const isBlocked = ref(false);
const isSilenced = ref(false);
const isNSFW = ref(false);
@ -213,11 +214,6 @@ const isMediaSilenced = ref(false);
const faviconUrl = ref<string | null>(null);
const moderationNote = ref('');
const isSuspended = computed({
get: () => suspensionState.value !== 'none',
set: value => value ? stopDelivery() : resumeDelivery(),
});
const baseDomains = computed(() => {
const domains: string[] = [];
@ -276,6 +272,7 @@ async function fetch(): Promise<void> {
host: props.host,
});
suspensionState.value = instance.value?.suspensionState ?? 'none';
isSuspended.value = instance.value?.suspensionState !== 'none';
isBlocked.value = instance.value?.isBlocked ?? false;
isSilenced.value = instance.value?.isSilenced ?? false;
isNSFW.value = instance.value?.isNSFW ?? false;
@ -314,21 +311,12 @@ async function toggleMediaSilenced(): Promise<void> {
});
}
async function stopDelivery(): Promise<void> {
async function toggleSuspended(): Promise<void> {
if (!instance.value) throw new Error('No instance?');
suspensionState.value = 'manuallySuspended';
suspensionState.value = isSuspended.value ? 'manuallySuspended' : 'none';
await misskeyApi('admin/federation/update-instance', {
host: instance.value.host,
isSuspended: true,
});
}
async function resumeDelivery(): Promise<void> {
if (!instance.value) throw new Error('No instance?');
suspensionState.value = 'none';
await misskeyApi('admin/federation/update-instance', {
host: instance.value.host,
isSuspended: false,
isSuspended: isSuspended.value,
});
}