diff --git a/example/typescript/src/misskey/note.ts b/example/typescript/src/misskey/note.ts new file mode 100644 index 000000000..1cbe34b8c --- /dev/null +++ b/example/typescript/src/misskey/note.ts @@ -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)) diff --git a/example/typescript/src/misskey/timeline.ts b/example/typescript/src/misskey/timeline.ts index 7d3103be8..d5473bf24 100644 --- a/example/typescript/src/misskey/timeline.ts +++ b/example/typescript/src/misskey/timeline.ts @@ -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>) => { console.log(resp.data) }) diff --git a/megalodon/src/misskey/api_client.ts b/megalodon/src/misskey/api_client.ts index 15e39d988..207a70a90 100644 --- a/megalodon/src/misskey/api_client.ts +++ b/megalodon/src/misskey/api_client.ts @@ -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, @@ -294,6 +294,16 @@ namespace MisskeyAPI { }) } + const mapReactionEmojis = (r: { [key: string]: string }): Array => { + 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): Array => { const result: Array = [] r.map(e => { diff --git a/megalodon/src/misskey/entities/note.ts b/megalodon/src/misskey/entities/note.ts index 1d7207de1..25c867bc8 100644 --- a/megalodon/src/misskey/entities/note.ts +++ b/megalodon/src/misskey/entities/note.ts @@ -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 fileIds: Array files: Array diff --git a/megalodon/test/integration/misskey.spec.ts b/megalodon/test/integration/misskey.spec.ts index af52c7d7b..03a2bc0da 100644 --- a/megalodon/test/integration/misskey.spec.ts +++ b/megalodon/test/integration/misskey.spec.ts @@ -27,6 +27,7 @@ const note: MisskeyEntity.Note = { renoteCount: 0, repliesCount: 0, reactions: {}, + reactionEmojis: {}, emojis: [], fileIds: [], files: [], diff --git a/megalodon/test/unit/misskey/api_client.spec.ts b/megalodon/test/unit/misskey/api_client.spec.ts index c728e0768..d0bd1d7ea 100644 --- a/megalodon/test/unit/misskey/api_client.spec.ts +++ b/megalodon/test/unit/misskey/api_client.spec.ts @@ -192,6 +192,7 @@ describe('api_client', () => { renoteCount: 0, repliesCount: 0, reactions: {}, + reactionEmojis: {}, emojis: [], fileIds: [], files: [], @@ -216,6 +217,7 @@ describe('api_client', () => { renoteCount: 0, repliesCount: 0, reactions: {}, + reactionEmojis: {}, emojis: [], fileIds: [], files: [], @@ -227,5 +229,55 @@ describe('api_client', () => { expect(megalodonStatus.content).toEqual(content) }) }) + describe('emoji reaction', () => { + it('reactionEmojis should be parsed', () => { + const plainContent = 'hoge\nfuga\nfuga' + const note: MisskeyEntity.Note = { + id: '1', + createdAt: '2021-02-01T01:49:29', + userId: '1', + user: user, + text: plainContent, + cw: null, + visibility: 'public', + renoteCount: 0, + repliesCount: 0, + reactions: { + ':example1@.:': 1, + ':example2@example.com:': 2 + }, + reactionEmojis: { + 'example2@example.com': 'https://example.com/emoji.png' + }, + emojis: [], + fileIds: [], + files: [], + replyId: null, + renoteId: null + } + const megalodonStatus = MisskeyAPI.Converter.note(note) + expect(megalodonStatus.emojis).toEqual([ + { + shortcode: 'example2@example.com', + static_url: 'https://example.com/emoji.png', + url: 'https://example.com/emoji.png', + visible_in_picker: true, + category: '' + } + ]) + expect(megalodonStatus.emoji_reactions).toEqual([ + { + count: 1, + me: false, + name: ':example1@.:' + }, + { + count: 2, + me: false, + name: ':example2@example.com:' + } + ]) + }) + }) }) })