summaryrefslogtreecommitdiff
path: root/packages/client/src/pages/follow.vue
blob: e8eaad73bfe681dde520fac167fe1f9043bb5401 (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
<template>
<div class="mk-follow-page">
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import * as os from '@/os';
import * as Acct from 'misskey-js/built/acct';

export default defineComponent({
	created() {
		const acct = new URL(location.href).searchParams.get('acct');
		if (acct == null) return;

		let promise;

		if (acct.startsWith('https://')) {
			promise = os.api('ap/show', {
				uri: acct
			});
			promise.then(res => {
				if (res.type == 'User') {
					this.follow(res.object);
				} else if (res.type === 'Note') {
					this.$router.push(`/notes/${res.object.id}`);
				} else {
					os.dialog({
						type: 'error',
						text: 'Not a user'
					}).then(() => {
						window.close();
					});
				}
			});
		} else {
			promise = os.api('users/show', Acct.parse(acct));
			promise.then(user => {
				this.follow(user);
			});
		}

		os.promiseDialog(promise, null, null, this.$ts.fetchingAsApObject);
	},

	methods: {
		async follow(user) {
			const { canceled } = await os.dialog({
				type: 'question',
				text: this.$t('followConfirm', { name: user.name || user.username }),
				showCancelButton: true
			});

			if (canceled) {
				window.close();
				return;
			}
			
			os.apiWithDialog('following/create', {
				userId: user.id
			});
		}
	}
});
</script>