From f29fee74a052709aeabc5f109106b545c10101ac Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 29 Sep 2023 13:06:20 +0200 Subject: [PATCH] [mastodon-client] Use actual default reaction --- .../server/api/mastodon/endpoints/status.ts | 26 ++----------------- .../src/server/api/mastodon/helpers/note.ts | 9 ++++++- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 2d110e13f..5983d3949 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -284,7 +284,7 @@ export function apiStatusMastodon(router: Router): void { 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 = await NoteHelpers.getDefaultReaction(); try { const a = (await client.createEmojiReaction( convertId(ctx.params.id, IdType.IceshrimpId), @@ -306,7 +306,7 @@ export function apiStatusMastodon(router: Router): void { 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 = await NoteHelpers.getDefaultReaction(); try { const data = await client.deleteEmojiReaction( convertId(ctx.params.id, IdType.IceshrimpId), @@ -541,25 +541,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; - } -} diff --git a/packages/backend/src/server/api/mastodon/helpers/note.ts b/packages/backend/src/server/api/mastodon/helpers/note.ts index 0108e90e9..e9a0e5c60 100644 --- a/packages/backend/src/server/api/mastodon/helpers/note.ts +++ b/packages/backend/src/server/api/mastodon/helpers/note.ts @@ -1,5 +1,5 @@ import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js"; -import { Notes } from "@/models/index.js"; +import { Metas, Notes } from "@/models/index.js"; import { generateVisibilityQuery } from "@/server/api/common/generate-visibility-query.js"; import { generateMutedUserQuery } from "@/server/api/common/generate-muted-user-query.js"; import { generateBlockedUserQuery } from "@/server/api/common/generate-block-query.js"; @@ -10,6 +10,13 @@ import { getNote } from "@/server/api/common/getters.js"; import { ObjectLiteral, SelectQueryBuilder } from "typeorm"; export class NoteHelpers { + public static async getDefaultReaction(): Promise { + return Metas.createQueryBuilder() + .select('"defaultReaction"') + .execute() + .then(p => p[0].defaultReaction); + } + public static async getNoteDescendants(note: Note | string, user: ILocalUser | null, limit: number = 10, depth: number = 2): Promise { const noteId = typeof note === "string" ? note : note.id; const query = makePaginationQuery(Notes.createQueryBuilder("note"))