summaryrefslogtreecommitdiff
path: root/packages/frontend/src/pages/follow.vue
blob: a0a4a480b577d9ef48a55941433af5fc164a992d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div>
</div>
</template>

<script lang="ts" setup>
import { } from 'vue';
import * as Misskey from 'misskey-js';
import * as os from '@/os.js';
import { mainRouter } from '@/router.js';
import { i18n } from '@/i18n.js';
import { defaultStore } from "@/store.js";

async function follow(user): Promise<void> {
	const { canceled } = await os.confirm({
		type: 'question',
		text: i18n.t('followConfirm', { name: user.name || user.username }),
	});

	if (canceled) {
		window.close();
		return;
	}

	os.apiWithDialog('following/create', {
		userId: user.id,
		withReplies: defaultStore.state.defaultWithReplies,
	});
	user.withReplies = defaultStore.state.defaultWithReplies;
}

const acct = new URL(location.href).searchParams.get('acct');
if (acct == null) {
	throw new Error('acct required');
}

let promise;

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();
			});
		}
	});
} else {
	promise = os.api('users/show', Misskey.acct.parse(acct));
	promise.then(user => {
		follow(user);
	});
}

os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
</script>