1
0
mirror of https://git.boykissers.com/pawkey/pawkey-sk.git synced 2025-12-20 04:04:16 +00:00

support reactions in mastodon API

This commit is contained in:
Hazelnoot
2025-03-22 18:18:54 -04:00
parent fbdee815da
commit 3c54680860
8 changed files with 82 additions and 54 deletions

View File

@@ -6,5 +6,7 @@ namespace Entity {
me: boolean
name: string
accounts?: Array<Account>
url?: string
static_url?: string
}
}

View File

@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
/// <reference path="account.ts" />
namespace MastodonEntity {
export type Reaction = {
name: string
count: number
me?: boolean
url?: string
static_url?: string
}
}

View File

@@ -6,6 +6,7 @@
/// <reference path="emoji.ts" />
/// <reference path="card.ts" />
/// <reference path="poll.ts" />
/// <reference path="reaction.ts" />
namespace MastodonEntity {
export type Status = {
@@ -41,6 +42,8 @@ namespace MastodonEntity {
// These parameters are unique parameters in fedibird.com for quote.
quote_id?: string
quote?: Status | null
// These parameters are unique to glitch-soc for emoji reactions.
reactions?: Reaction[]
}
export type StatusTag = {

View File

@@ -22,6 +22,7 @@
/// <reference path="./entities/poll_option.ts" />
/// <reference path="./entities/preferences.ts" />
/// <reference path="./entities/push_subscription.ts" />
/// <reference path="./entities/reaction.ts" />
/// <reference path="./entities/relationship.ts" />
/// <reference path="./entities/report.ts" />
/// <reference path="./entities/results.ts" />

View File

@@ -2555,6 +2555,7 @@ export default class Misskey implements MegalodonInterface {
}))
}
// TODO implement
public async getEmojiReaction(_id: string, _emoji: string): Promise<Response<Entity.Reaction>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')

View File

@@ -286,6 +286,7 @@ namespace MisskeyAPI {
plain_content: n.text ? n.text : null,
created_at: n.createdAt,
edited_at: n.updatedAt || null,
// TODO this is probably wrong
emojis: mapEmojis(n.emojis).concat(mapReactionEmojis(n.reactionEmojis)),
replies_count: n.repliesCount,
reblogs_count: n.renoteCount,
@@ -304,7 +305,7 @@ namespace MisskeyAPI {
application: null,
language: null,
pinned: null,
emoji_reactions: typeof n.reactions === 'object' ? mapReactions(n.reactions, n.myReaction) : [],
emoji_reactions: typeof n.reactions === 'object' ? mapReactions(n.reactions, n.reactionEmojis, n.myReaction) : [],
bookmarked: false,
quote: n.renote && n.text ? note(n.renote, n.user.host ? n.user.host : host ? host : null) : null
}
@@ -334,23 +335,20 @@ namespace MisskeyAPI {
) : 0;
};
export const mapReactions = (r: { [key: string]: number }, myReaction?: string): Array<MegalodonEntity.Reaction> => {
export const mapReactions = (r: { [key: string]: number }, e: Record<string, string | undefined>, myReaction?: string): Array<MegalodonEntity.Reaction> => {
return Object.keys(r).map(key => {
if (myReaction && key === myReaction) {
return {
count: r[key],
me: true,
name: key
}
}
return {
count: r[key],
me: false,
name: key
}
const me = myReaction != null && key === myReaction;
return {
count: r[key],
me,
name: key,
url: e[key],
static_url: e[key],
}
})
}
// TODO implement other properties
const mapReactionEmojis = (r: { [key: string]: string }): Array<MegalodonEntity.Emoji> => {
return Object.keys(r).map(key => ({
shortcode: key,
@@ -371,7 +369,7 @@ namespace MisskeyAPI {
result.push({
count: 1,
me: false,
name: e.type
name: e.type,
})
}
})