[mastodon-client] return actual status bookmark state

This commit is contained in:
Laura Hausmann 2023-07-10 00:05:52 +02:00
parent c1e43407d5
commit 02ddbe2363
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
3 changed files with 17 additions and 1 deletions

View File

@ -1243,9 +1243,17 @@ export default class Misskey implements MegalodonInterface {
public async noteWithDetails(n: MisskeyAPI.Entity.Note, host: string, cache: AccountCache): Promise<MegalodonEntity.Status> { public async noteWithDetails(n: MisskeyAPI.Entity.Note, host: string, cache: AccountCache): Promise<MegalodonEntity.Status> {
const status = await this.addUserDetailsToStatus(this.converter.note(n, host), cache); const status = await this.addUserDetailsToStatus(this.converter.note(n, host), cache);
status.bookmarked = await this.isStatusBookmarked(n.id);
return this.addMentionsToStatus(status, cache); return this.addMentionsToStatus(status, cache);
} }
public async isStatusBookmarked(id: string) : Promise<boolean> {
return this.client
.post<MisskeyAPI.Entity.State>('/api/notes/state', {
noteId: id
}).then(p => p.data.isFavorited ?? false);
}
public async addUserDetailsToStatus(status: Entity.Status, cache: AccountCache) : Promise<Entity.Status> { public async addUserDetailsToStatus(status: Entity.Status, cache: AccountCache) : Promise<Entity.Status> {
if (status.account.followers_count === 0 && status.account.followers_count === 0 && status.account.statuses_count === 0) 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; status.account = await this.getAccountCached(status.account.id, status.account.acct, cache) ?? status.account;

View File

@ -41,6 +41,7 @@ namespace MisskeyAPI {
export type UserKey = MisskeyEntity.UserKey export type UserKey = MisskeyEntity.UserKey
export type Session = MisskeyEntity.Session 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[] } export type APIEmoji = { emojis: Emoji[] }
} }

View File

@ -0,0 +1,7 @@
namespace MisskeyEntity {
export type State = {
isFavorited: boolean
isMutedThread: boolean
isWatching: boolean
}
}