iceshrimp/packages/client/src/pages/follow.vue

62 lines
1.2 KiB
Vue
Raw Normal View History

<template>
2023-04-08 09:01:42 +09:00
<div class="mk-follow-page"></div>
</template>
2022-09-02 00:22:31 +09:00
<script lang="ts" setup>
2023-04-08 09:01:42 +09:00
import {} from "vue";
import * as Acct from "calckey-js/built/acct";
import * as os from "@/os";
import { mainRouter } from "@/router";
import { i18n } from "@/i18n";
2022-09-02 00:22:31 +09:00
async function follow(user): Promise<void> {
const { canceled } = await os.confirm({
2023-04-08 09:01:42 +09:00
type: "question",
text: i18n.t("followConfirm", { name: user.name || user.username }),
2022-09-02 00:22:31 +09:00
});
2022-09-02 00:22:31 +09:00
if (canceled) {
window.close();
return;
}
2022-10-28 07:01:38 +09:00
2023-04-08 09:01:42 +09:00
os.apiWithDialog("following/create", {
2022-09-02 00:22:31 +09:00
userId: user.id,
});
}
2023-04-08 09:01:42 +09:00
const acct = new URL(location.href).searchParams.get("acct");
if (acct == null) {
2023-04-08 09:01:42 +09:00
throw new Error("acct required");
}
2020-10-18 10:11:34 +09:00
2022-09-02 00:22:31 +09:00
let promise;
2023-04-08 09:01:42 +09:00
if (acct.startsWith("https://")) {
promise = os.api("ap/show", {
2022-09-02 00:22:31 +09:00
uri: acct,
});
2023-04-08 09:01:42 +09:00
promise.then((res) => {
if (res.type === "User") {
2022-09-02 00:22:31 +09:00
follow(res.object);
2023-04-08 09:01:42 +09:00
} else if (res.type === "Note") {
2022-09-02 00:22:31 +09:00
mainRouter.push(`/notes/${res.object.id}`);
} else {
os.alert({
2023-04-08 09:01:42 +09:00
type: "error",
text: "Not a user",
2022-09-02 00:22:31 +09:00
}).then(() => {
window.close();
});
2022-09-02 00:22:31 +09:00
}
});
} else {
2023-04-08 09:01:42 +09:00
promise = os.api("users/show", Acct.parse(acct));
promise.then((user) => {
2022-09-02 00:22:31 +09:00
follow(user);
});
}
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
</script>