From a7778e6425b26628f862a811e21c7491de111cd4 Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Mon, 25 Sep 2023 03:55:21 +0200 Subject: [PATCH] fix: megalodon reblogged and favourited user info, add createdAt to note --- .../backend/src/server/api/mastodon/endpoints/status.ts | 4 ++-- packages/megalodon/src/entities/status.ts | 1 + packages/megalodon/src/megalodon.ts | 4 ++-- packages/megalodon/src/misskey.ts | 8 ++++---- packages/megalodon/src/misskey/api_client.ts | 3 ++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 5764938c07..9d4fa23b84 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -71,7 +71,7 @@ export class ApiStatusMastodon { const accessTokens = _request.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - const data = await client.getStatusRebloggedBy(convertId(_request.params.id, IdType.SharkeyId)); + const data = await client.getStatusRebloggedBy(convertId(_request.params.id, IdType.SharkeyId), BASE_URL); reply.send(data.data.map((account: Entity.Account) => convertAccount(account))); } catch (e: any) { console.error(e); @@ -86,7 +86,7 @@ export class ApiStatusMastodon { const accessTokens = _request.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - const data = await client.getStatusFavouritedBy(convertId(_request.params.id, IdType.SharkeyId)); + const data = await client.getStatusFavouritedBy(convertId(_request.params.id, IdType.SharkeyId), BASE_URL); reply.send(data.data.map((account: Entity.Account) => convertAccount(account))); } catch (e: any) { console.error(e); diff --git a/packages/megalodon/src/entities/status.ts b/packages/megalodon/src/entities/status.ts index 295703e57c..073b58932c 100644 --- a/packages/megalodon/src/entities/status.ts +++ b/packages/megalodon/src/entities/status.ts @@ -19,6 +19,7 @@ namespace Entity { content: string plain_content: string | null created_at: string + createdAt?: string emojis: Emoji[] replies_count: number reblogs_count: number diff --git a/packages/megalodon/src/megalodon.ts b/packages/megalodon/src/megalodon.ts index d75d13cf22..a7a387f379 100644 --- a/packages/megalodon/src/megalodon.ts +++ b/packages/megalodon/src/megalodon.ts @@ -734,14 +734,14 @@ export interface MegalodonInterface { * @param id The target status id. * @return Array of accounts. */ - getStatusRebloggedBy(id: string): Promise>> + getStatusRebloggedBy(id: string, host?: string): Promise>> /** * See who favourited a status * * @param id The target status id. * @return Array of accounts. */ - getStatusFavouritedBy(id: string): Promise>> + getStatusFavouritedBy(id: string, host?: string): Promise>> /** * Favourite a status. * diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index f9858214d9..7bfe4a622a 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -1177,25 +1177,25 @@ export default class Misskey implements MegalodonInterface { /** * POST /api/notes/renotes */ - public async getStatusRebloggedBy(id: string): Promise>> { + public async getStatusRebloggedBy(id: string, host?: string): Promise>> { return this.client .post>('/api/notes/renotes', { noteId: id }) .then(res => ({ ...res, - data: res.data.map(n => MisskeyAPI.Converter.user(n.user)) + data: res.data.map(n => MisskeyAPI.Converter.user(n.user, host)) })) } - public async getStatusFavouritedBy(_id: string): Promise>> { + public async getStatusFavouritedBy(_id: string, host?: string): Promise>> { return this.client.post>("/api/notes/reactions", { noteId: _id, }) .then(async (res) => ({ ...res, data: ( - await Promise.all(res.data.map((n) => this.getAccount(n.user.id))) + await Promise.all(res.data.map((n) => this.getAccount(n.user.id, host))) ).map((p) => p.data), })); } diff --git a/packages/megalodon/src/misskey/api_client.ts b/packages/megalodon/src/misskey/api_client.ts index 364f08f775..f7ecb3bd5b 100644 --- a/packages/megalodon/src/misskey/api_client.ts +++ b/packages/megalodon/src/misskey/api_client.ts @@ -256,7 +256,7 @@ namespace MisskeyAPI { account: user(n.user, n.user.host ? n.user.host : host ? host : null), in_reply_to_id: n.replyId, in_reply_to_account_id: null, - reblog: n.renote ? note(n.renote) : null, + reblog: n.renote ? note(n.renote, n.user.host ? n.user.host : host ? host : null) : null, content: n.text ? n.text .replace(/&/g, '&') @@ -269,6 +269,7 @@ namespace MisskeyAPI { : '', plain_content: n.text ? n.text : null, created_at: n.createdAt, + createdAt: n.createdAt, emojis: mapEmojis(n.emojis).concat(mapReactionEmojis(n.reactionEmojis)), replies_count: n.repliesCount, reblogs_count: n.renoteCount,