From b2d367faed91caa4079b25e30e2d912cf427b135 Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Mon, 25 Sep 2023 15:38:30 +0200 Subject: [PATCH] fix: favourites on megalodon --- packages/megalodon/src/misskey/api_client.ts | 12 +++++++++--- packages/megalodon/tsconfig.json | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/megalodon/src/misskey/api_client.ts b/packages/megalodon/src/misskey/api_client.ts index 6048d62da..97732d61a 100644 --- a/packages/megalodon/src/misskey/api_client.ts +++ b/packages/megalodon/src/misskey/api_client.ts @@ -265,7 +265,7 @@ namespace MisskeyAPI { url: n.url ? n.url : host ? `https://${host}/notes/${n.id}` : '', 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, + in_reply_to_account_id: n.reply?.userId ?? null, reblog: n.renote ? note(n.renote, n.user.host ? n.user.host : host ? host : null) : null, content: n.text ? n.text @@ -282,9 +282,9 @@ namespace MisskeyAPI { emojis: mapEmojis(n.emojis).concat(mapReactionEmojis(n.reactionEmojis)), replies_count: n.repliesCount, reblogs_count: n.renoteCount, - favourites_count: 0, + favourites_count: getTotalReactions(n.reactions), reblogged: false, - favourited: false, + favourited: !!n.myReaction, muted: false, sensitive: Array.isArray(n.files) ? n.files.some(f => f.isSensitive) : false, spoiler_text: n.cw ? n.cw : '', @@ -313,6 +313,12 @@ namespace MisskeyAPI { } } + export const getTotalReactions = (r: { [key: string]: number }): number => { + return Object.values(r).length > 0 ? Object.values(r).reduce( + (previousValue, currentValue) => previousValue + currentValue, + ) : 0; + }; + export const mapReactions = (r: { [key: string]: number }, myReaction?: string): Array => { return Object.keys(r).map(key => { if (myReaction && key === myReaction) { diff --git a/packages/megalodon/tsconfig.json b/packages/megalodon/tsconfig.json index 7f6943225..b2b4a984b 100644 --- a/packages/megalodon/tsconfig.json +++ b/packages/megalodon/tsconfig.json @@ -3,7 +3,7 @@ /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - "lib": ["es6", "dom"], /* Specify library files to be included in the compilation. */ + "lib": ["es2021", "dom"], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */