From 02ddbe2363661cd12ab485559a4c5e6432d23683 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 10 Jul 2023 00:05:52 +0200 Subject: [PATCH] [mastodon-client] return actual status bookmark state --- packages/megalodon/src/misskey.ts | 8 ++++++++ packages/megalodon/src/misskey/api_client.ts | 3 ++- packages/megalodon/src/misskey/entities/state.ts | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 packages/megalodon/src/misskey/entities/state.ts diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index fd765b3dc..026b8e9b7 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -1243,9 +1243,17 @@ export default class Misskey implements MegalodonInterface { public async noteWithDetails(n: MisskeyAPI.Entity.Note, host: string, cache: AccountCache): Promise { const status = await this.addUserDetailsToStatus(this.converter.note(n, host), cache); + status.bookmarked = await this.isStatusBookmarked(n.id); return this.addMentionsToStatus(status, cache); } + public async isStatusBookmarked(id: string) : Promise { + return this.client + .post('/api/notes/state', { + noteId: id + }).then(p => p.data.isFavorited ?? false); + } + public async addUserDetailsToStatus(status: Entity.Status, cache: AccountCache) : Promise { if (status.account.followers_count === 0 && status.account.followers_count === 0 && status.account.statuses_count === 0) status.account = await this.getAccountCached(status.account.id, status.account.acct, cache) ?? status.account; diff --git a/packages/megalodon/src/misskey/api_client.ts b/packages/megalodon/src/misskey/api_client.ts index 813ffe08a..f80d5a442 100644 --- a/packages/megalodon/src/misskey/api_client.ts +++ b/packages/megalodon/src/misskey/api_client.ts @@ -40,7 +40,8 @@ namespace MisskeyAPI { export type GetAll = MisskeyEntity.GetAll export type UserKey = MisskeyEntity.UserKey export type Session = MisskeyEntity.Session - export type Stats = MisskeyEntity.Stats + export type Stats = MisskeyEntity.Stats + export type State = MisskeyEntity.State export type APIEmoji = { emojis: Emoji[] } } diff --git a/packages/megalodon/src/misskey/entities/state.ts b/packages/megalodon/src/misskey/entities/state.ts new file mode 100644 index 000000000..4538fb461 --- /dev/null +++ b/packages/megalodon/src/misskey/entities/state.ts @@ -0,0 +1,7 @@ +namespace MisskeyEntity { + export type State = { + isFavorited: boolean + isMutedThread: boolean + isWatching: boolean + } +}