From b61e52757e252c6351f0cfc5143a669f8c859f04 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sun, 4 Jun 2023 00:17:47 +0900
Subject: [PATCH 1/2] refs #1717 Change custom emoji endpoint for misskey
---
example/typescript/src/misskey/emojis.ts | 18 +++++++++++++
megalodon/src/misskey.ts | 4 +--
megalodon/src/misskey/api_client.ts | 32 ++++++++++++++++++++++--
megalodon/src/misskey/entities/emoji.ts | 2 +-
4 files changed, 51 insertions(+), 5 deletions(-)
create mode 100644 example/typescript/src/misskey/emojis.ts
diff --git a/example/typescript/src/misskey/emojis.ts b/example/typescript/src/misskey/emojis.ts
new file mode 100644
index 000000000..1e8687591
--- /dev/null
+++ b/example/typescript/src/misskey/emojis.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
+ .getInstanceCustomEmojis()
+ .then(res => console.log(res.data))
+ .catch(err => console.error(err))
diff --git a/megalodon/src/misskey.ts b/megalodon/src/misskey.ts
index 5a03e01cf..3a3a00976 100644
--- a/megalodon/src/misskey.ts
+++ b/megalodon/src/misskey.ts
@@ -2104,11 +2104,11 @@ export default class Misskey implements MegalodonInterface {
// instance/custom_emojis
// ======================================
/**
- * POST /api/meta
+ * GET /api/emojis
*/
public async getInstanceCustomEmojis(): Promise>> {
return this.client
- .post('/api/meta')
+ .get<{ emojis: Array }>('/api/emojis')
.then(res => ({ ...res, data: res.data.emojis.map(e => MisskeyAPI.Converter.emoji(e)) }))
}
diff --git a/megalodon/src/misskey/api_client.ts b/megalodon/src/misskey/api_client.ts
index 407a4cfae..15e39d988 100644
--- a/megalodon/src/misskey/api_client.ts
+++ b/megalodon/src/misskey/api_client.ts
@@ -64,7 +64,7 @@ namespace MisskeyAPI {
static_url: e.url,
url: e.url,
visible_in_picker: true,
- category: ''
+ category: e.category
}
}
@@ -460,6 +460,7 @@ namespace MisskeyAPI {
* Interface
*/
export interface Interface {
+ get(path: string, params?: any, headers?: { [key: string]: string }): Promise>
post(path: string, params?: any, headers?: { [key: string]: string }): Promise>
cancel(): void
socket(channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation' | 'list', listId?: string): WebSocket
@@ -493,7 +494,34 @@ namespace MisskeyAPI {
}
/**
- * POST request to mastodon REST API.
+ * GET request to misskey API.
+ **/
+ public async get(path: string, params: any = {}, headers: { [key: string]: string } = {}): Promise> {
+ let options: AxiosRequestConfig = {
+ params: params,
+ headers: headers,
+ maxContentLength: Infinity,
+ maxBodyLength: Infinity
+ }
+ if (this.proxyConfig) {
+ options = Object.assign(options, {
+ httpAgent: proxyAgent(this.proxyConfig),
+ httpsAgent: proxyAgent(this.proxyConfig)
+ })
+ }
+ return axios.get(this.baseUrl + path, options).then((resp: AxiosResponse) => {
+ const res: Response = {
+ data: resp.data,
+ status: resp.status,
+ statusText: resp.statusText,
+ headers: resp.headers
+ }
+ return res
+ })
+ }
+
+ /**
+ * POST request to misskey REST API.
* @param path relative path from baseUrl
* @param params Form data
* @param headers Request header object
diff --git a/megalodon/src/misskey/entities/emoji.ts b/megalodon/src/misskey/entities/emoji.ts
index e0bcfe09b..2bd4c8c73 100644
--- a/megalodon/src/misskey/entities/emoji.ts
+++ b/megalodon/src/misskey/entities/emoji.ts
@@ -1,8 +1,8 @@
namespace MisskeyEntity {
export type Emoji = {
name: string
- host: string | null
url: string
aliases: Array
+ category: string
}
}
From 4114c2ec2bf3b4d8292c62bd162a6e12e2425d7f Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sun, 4 Jun 2023 00:42:50 +0900
Subject: [PATCH 2/2] refs #1717 Parse reactionEmojis field for Misskey emoji
---
example/typescript/src/misskey/note.ts | 18 +++++++
example/typescript/src/misskey/timeline.ts | 2 +-
megalodon/src/misskey/api_client.ts | 12 ++++-
megalodon/src/misskey/entities/note.ts | 2 +
megalodon/test/integration/misskey.spec.ts | 1 +
.../test/unit/misskey/api_client.spec.ts | 52 +++++++++++++++++++
6 files changed, 85 insertions(+), 2 deletions(-)
create mode 100644 example/typescript/src/misskey/note.ts
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:'
+ }
+ ])
+ })
+ })
})
})