From 284795fdf53e468051a3a920027d6afc61bfed0f Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 23 Sep 2023 22:05:25 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20when=20favorouting/unfavo?= =?UTF-8?q?uriting=20with=20Mastodon=20API,=20send=20instance=20default=20?= =?UTF-8?q?reaction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/api/mastodon/endpoints/status.ts | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index c3e6946e2f..bc95d77769 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -12,6 +12,7 @@ import { convertPoll, convertStatus, } from "../converters.js"; +import { fetchMeta } from "@/misc/fetch-meta.js"; function normalizeQuery(data: any) { const str = querystring.stringify(data); @@ -216,10 +217,11 @@ export function apiStatusMastodon(router: Router): void { router.post<{ Params: { id: string } }>( "/v1/statuses/:id/favourite", async (ctx) => { + const meta = await fetchMeta(); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); - const react = await getFirstReaction(BASE_URL, accessTokens); + const react = meta.defaultReaction; try { const a = (await client.createEmojiReaction( convertId(ctx.params.id, IdType.FirefishId), @@ -238,10 +240,11 @@ export function apiStatusMastodon(router: Router): void { router.post<{ Params: { id: string } }>( "/v1/statuses/:id/unfavourite", async (ctx) => { + const meta = await fetchMeta(); const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); - const react = await getFirstReaction(BASE_URL, accessTokens); + const react = meta.defaultReaction; try { const data = await client.deleteEmojiReaction( convertId(ctx.params.id, IdType.FirefishId), @@ -476,25 +479,3 @@ export function apiStatusMastodon(router: Router): void { }, ); } - -async function getFirstReaction( - BASE_URL: string, - accessTokens: string | undefined, -) { - const accessTokenArr = accessTokens?.split(" ") ?? [null]; - const accessToken = accessTokenArr[accessTokenArr.length - 1]; - let react = "⭐"; - try { - const api = await axios.post(`${BASE_URL}/api/i/registry/get-unsecure`, { - scope: ["client", "base"], - key: "reactions", - i: accessToken, - }); - const reactRaw = api.data; - react = Array.isArray(reactRaw) ? api.data[0] : "⭐"; - console.log(api.data); - return react; - } catch (e) { - return react; - } -}