fix: favourites on megalodon

This commit is contained in:
Mar0xy 2023-09-25 15:38:30 +02:00
parent 84fcf9efc7
commit b2d367faed
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
2 changed files with 10 additions and 4 deletions

View file

@ -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<MegalodonEntity.Reaction> => {
return Object.keys(r).map(key => {
if (myReaction && key === myReaction) {

View file

@ -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'. */