Skip to content

Commit

Permalink
refs #1717 Parse reactionEmojis field for Misskey emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
h3poteto committed Jun 3, 2023
1 parent b61e527 commit 1a4913b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
18 changes: 18 additions & 0 deletions example/typescript/src/misskey/note.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import generator, { MegalodonInterface } from 'megalodon'

declare var process: {
env: {
MISSKEY_ACCESS_TOKEN: string
}
}

const BASE_URL: string = 'https://misskey.io'

const access_token: string = process.env.MISSKEY_ACCESS_TOKEN

const client: MegalodonInterface = generator('misskey', BASE_URL, access_token)

client
.getStatus('9fjp2aknrm')
.then(res => console.log(res.data))
.catch(err => console.error(err))
2 changes: 1 addition & 1 deletion example/typescript/src/misskey/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const access_token: string = process.env.MISSKEY_ACCESS_TOKEN
const client: MegalodonInterface = generator('misskey', BASE_URL, access_token)

client
.getHomeTimeline()
.getLocalTimeline()
.then((resp: Response<Array<Entity.Status>>) => {
console.log(resp.data)
})
Expand Down
12 changes: 11 additions & 1 deletion megalodon/src/misskey/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ namespace MisskeyAPI {
: '',
plain_content: n.text ? n.text : null,
created_at: n.createdAt,
emojis: Array.isArray(n.emojis) ? n.emojis.map(e => emoji(e)) : [],
emojis: (Array.isArray(n.emojis) ? n.emojis.map(e => emoji(e)) : []).concat(mapReactionEmojis(n.reactionEmojis)),
replies_count: n.repliesCount,
reblogs_count: n.renoteCount,
favourites_count: 0,
Expand Down Expand Up @@ -294,6 +294,16 @@ namespace MisskeyAPI {
})
}

const mapReactionEmojis = (r: { [key: string]: string }): Array<MegalodonEntity.Emoji> => {
return Object.keys(r).map(key => ({
shortcode: key,
static_url: r[key],
url: r[key],
visible_in_picker: true,
category: ''
}))
}

export const reactions = (r: Array<Entity.Reaction>): Array<MegalodonEntity.Reaction> => {
const result: Array<MegalodonEntity.Reaction> = []
r.map(e => {
Expand Down
2 changes: 2 additions & 0 deletions megalodon/src/misskey/entities/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace MisskeyEntity {
renoteCount: number
repliesCount: number
reactions: { [key: string]: number }
// This field includes only remote emojis
reactionEmojis: { [key: string]: string }
emojis: Array<Emoji>
fileIds: Array<string>
files: Array<File>
Expand Down
1 change: 1 addition & 0 deletions megalodon/test/integration/misskey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const note: MisskeyEntity.Note = {
renoteCount: 0,
repliesCount: 0,
reactions: {},
reactionEmojis: {},
emojis: [],
fileIds: [],
files: [],
Expand Down
2 changes: 2 additions & 0 deletions megalodon/test/unit/misskey/api_client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ describe('api_client', () => {
renoteCount: 0,
repliesCount: 0,
reactions: {},
reactionEmojis: {},
emojis: [],
fileIds: [],
files: [],
Expand All @@ -216,6 +217,7 @@ describe('api_client', () => {
renoteCount: 0,
repliesCount: 0,
reactions: {},
reactionEmojis: {},
emojis: [],
fileIds: [],
files: [],
Expand Down

0 comments on commit 1a4913b

Please sign in to comment.