From e759864442e2a09562d819e28f526578d4e33993 Mon Sep 17 00:00:00 2001 From: Vyr Cossont Date: Mon, 14 Aug 2023 12:18:57 -0700 Subject: [PATCH] Mastodon API: convert IDs in conversations --- .../backend/src/server/api/mastodon/converters.ts | 10 ++++++++++ .../src/server/api/mastodon/endpoints/timeline.ts | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/converters.ts b/packages/backend/src/server/api/mastodon/converters.ts index 908464379..6469d9c97 100644 --- a/packages/backend/src/server/api/mastodon/converters.ts +++ b/packages/backend/src/server/api/mastodon/converters.ts @@ -74,3 +74,13 @@ export function convertStatus(status: Entity.Status) { return status; } + +export function convertConversation(conversation: Entity.Conversation) { + conversation.id = convertId(conversation.id, IdType.MastodonId); + conversation.accounts = conversation.accounts.map(convertAccount); + if (conversation.last_status) { + conversation.last_status = convertStatus(conversation.last_status); + } + + return conversation; +} diff --git a/packages/backend/src/server/api/mastodon/endpoints/timeline.ts b/packages/backend/src/server/api/mastodon/endpoints/timeline.ts index d54594327..0a4da322d 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/timeline.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/timeline.ts @@ -1,7 +1,12 @@ import Router from "@koa/router"; import { getClient } from "../ApiMastodonCompatibleService.js"; import { ParsedUrlQuery } from "querystring"; -import { convertAccount, convertList, convertStatus } from "../converters.js"; +import { + convertAccount, + convertConversation, + convertList, + convertStatus, +} from "../converters.js"; import { convertId, IdType } from "../../index.js"; export function limitToInt(q: ParsedUrlQuery) { @@ -136,7 +141,9 @@ export function apiTimelineMastodon(router: Router): void { const data = await client.getConversationTimeline( convertTimelinesArgsId(limitToInt(ctx.query)), ); - ctx.body = data.data; + ctx.body = data.data.map((conversation) => + convertConversation(conversation), + ); } catch (e: any) { console.error(e); console.error(e.response.data);