fix: 🐛 when favorouting/unfavouriting with Mastodon API, send instance default reaction
This commit is contained in:
parent
081d723cff
commit
284795fdf5
1 changed files with 5 additions and 24 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue