misskey/packages/frontend/src/pages/follow.vue

68 lines
1.3 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
2023-05-19 16:20:53 +09:00
<div>
</div>
</template>
2022-09-02 00:22:31 +09:00
<script lang="ts" setup>
import { } from 'vue';
import * as Misskey from 'misskey-js';
2023-09-19 16:37:43 +09:00
import * as os from '@/os.js';
import { mainRouter } from '@/router.js';
import { i18n } from '@/i18n.js';
2022-09-02 00:22:31 +09:00
async function follow(user): Promise<void> {
const { canceled } = await os.confirm({
type: 'question',
text: i18n.t('followConfirm', { name: user.name || user.username }),
});
2022-09-02 00:22:31 +09:00
if (canceled) {
window.close();
return;
}
2022-09-02 00:22:31 +09:00
os.apiWithDialog('following/create', {
userId: user.id,
});
}
2022-09-02 00:22:31 +09:00
const acct = new URL(location.href).searchParams.get('acct');
if (acct == null) {
throw new Error('acct required');
}
2020-10-18 10:11:34 +09:00
2022-09-02 00:22:31 +09:00
let promise;
2022-09-02 00:22:31 +09:00
if (acct.startsWith('https://')) {
promise = os.api('ap/show', {
uri: acct,
});
promise.then(res => {
if (res.type === 'User') {
follow(res.object);
} else if (res.type === 'Note') {
mainRouter.push(`/notes/${res.object.id}`);
} else {
os.alert({
type: 'error',
text: 'Not a user',
}).then(() => {
window.close();
});
2022-09-02 00:22:31 +09:00
}
});
} else {
promise = os.api('users/show', Misskey.acct.parse(acct));
2022-09-02 00:22:31 +09:00
promise.then(user => {
follow(user);
});
}
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
</script>