From e6f12c4e249644f72591535046063a3fe15000c8 Mon Sep 17 00:00:00 2001 From: fruye Date: Sat, 29 Apr 2023 16:18:55 +0200 Subject: [PATCH] Implement bookmark-related functions to misskey Calckey frontend uses API endpoints with 'favourite' in the name to add bookmarks. For "real" favorites it sends a 'reaction'. --- megalodon/src/misskey.ts | 60 ++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/megalodon/src/misskey.ts b/megalodon/src/misskey.ts index dbe4c52..60af9c6 100644 --- a/megalodon/src/misskey.ts +++ b/megalodon/src/misskey.ts @@ -642,15 +642,37 @@ export default class Misskey implements MegalodonInterface { // ====================================== // accounts/bookmarks // ====================================== - public async getBookmarks(_options?: { + /** + * POST /api/i/favorites + */ + public async getBookmarks(options?: { limit?: number max_id?: string since_id?: string min_id?: string }): Promise>> { - return new Promise((_, reject) => { - const err = new NoImplementedError('misskey does not support') - reject(err) + let params = {} + if (options) { + if (options.limit) { + params = Object.assign(params, { + limit: options.limit + }) + } + if (options.max_id) { + params = Object.assign(params, { + untilId: options.max_id + }) + } + if (options.min_id) { + params = Object.assign(params, { + sinceId: options.min_id + }) + } + } + return this.client.post>('/api/i/favorites', params).then(res => { + return Object.assign(res, { + data: res.data.map(s => MisskeyAPI.Converter.note(s.note, this.baseUrlToHost(this.baseUrl))) + }) }) } @@ -1229,18 +1251,32 @@ export default class Misskey implements MegalodonInterface { .then(res => ({ ...res, data: MisskeyAPI.Converter.note(res.data, this.baseUrlToHost(this.baseUrl)) })) } - public async bookmarkStatus(_id: string): Promise> { - return new Promise((_, reject) => { - const err = new NoImplementedError('misskey does not support') - reject(err) + /** + * POST /api/notes/favorites/create + */ + public async bookmarkStatus(id: string): Promise> { + await this.client.post<{}>('/api/notes/favorites/create', { + noteId: id }) + return this.client + .post('/api/notes/show', { + noteId: id + }) + .then(res => ({ ...res, data: MisskeyAPI.Converter.note(res.data, this.baseUrlToHost(this.baseUrl)) })) } - public async unbookmarkStatus(_id: string): Promise> { - return new Promise((_, reject) => { - const err = new NoImplementedError('misskey does not support') - reject(err) + /** + * POST /api/notes/favorites/delete + */ + public async unbookmarkStatus(id: string): Promise> { + await this.client.post<{}>('/api/notes/favorites/delete', { + noteId: id }) + return this.client + .post('/api/notes/show', { + noteId: id + }) + .then(res => ({ ...res, data: MisskeyAPI.Converter.note(res.data, this.baseUrlToHost(this.baseUrl)) })) } public async muteStatus(_id: string): Promise> {