From 59f9a1620faf259f91f3bd36bbbcf8b15aa73ba7 Mon Sep 17 00:00:00 2001
From: Linca <lhcfllinca@gmail.com>
Date: Mon, 18 Mar 2024 15:45:24 +0000
Subject: [PATCH] feat: add authorize_interaction page

Co-authored-by: naskya <m@naskya.net>
Co-authored-by: Lhcfl <Lhcfl@outlook.com>
---
 docs/changelog.md                             |  1 +
 .../src/pages/authorize_interaction.vue       | 38 +++++++++++++++++++
 packages/client/src/router.ts                 |  5 +++
 3 files changed, 44 insertions(+)
 create mode 100644 packages/client/src/pages/authorize_interaction.vue

diff --git a/docs/changelog.md b/docs/changelog.md
index b1abd1b04a..46241b97d3 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -12,6 +12,7 @@ Critical security updates are indicated by the :warning: icon.
 - Add a toggleable setting to show a warning when you attempt to post files without alt text
 - Fix bugs
 - Update documents and example config files
+- Added `/authorize_interaction` page, allowing users to jump from a remote Mastodon post/user page to the corresponding page in Firefish (!10702)
 
 ## [v20240301](https://firefish.dev/firefish/firefish/-/compare/v20240229...v20240301?from_project_id=7&straight=false)
 
diff --git a/packages/client/src/pages/authorize_interaction.vue b/packages/client/src/pages/authorize_interaction.vue
new file mode 100644
index 0000000000..22c6627aa0
--- /dev/null
+++ b/packages/client/src/pages/authorize_interaction.vue
@@ -0,0 +1,38 @@
+<template>
+	<MkLoading v-if="!err" />
+	<XNotFound v-else />
+</template>
+
+<script lang="ts" setup>
+import * as os from "@/os";
+import { useRouter } from "@/router";
+import { userPage } from "@/filters/user";
+import { notePage } from "@/filters/note";
+import { onMounted, ref, defineAsyncComponent } from "vue";
+const XNotFound = defineAsyncComponent(() => import("./not-found.vue"));
+
+const err = ref(false);
+const urlParams = new URLSearchParams(window.location.search);
+const uri = urlParams.get("uri");
+const router = useRouter();
+
+onMounted(() => {
+	os.api("ap/show", { uri })
+		.then((res) => {
+			switch (res.type) {
+				case "User":
+					router.push(userPage(res.object));
+					break;
+				case "Note":
+					router.push(notePage(res.object));
+					break;
+				default:
+					err.value = true;
+					break;
+			}
+		})
+		.catch((error) => {
+			err.value = true;
+		});
+});
+</script>
diff --git a/packages/client/src/router.ts b/packages/client/src/router.ts
index cf7ccf516e..35b54b20ec 100644
--- a/packages/client/src/router.ts
+++ b/packages/client/src/router.ts
@@ -320,6 +320,11 @@ export const routes = [
 		component: page(() => import("./pages/follow.vue")),
 		loginRequired: true,
 	},
+	{
+		path: "/authorize_interaction",
+		component: page(() => import("./pages/authorize_interaction.vue")),
+		loginRequired: true,
+	},
 	{
 		path: "/share",
 		component: page(() => import("./pages/share.vue")),