@@ -316,6 +316,30 @@ export class MisskeyHttpClient implements MastodonApi {
316316 return data . map ( ( item ) => mapMisskeyStatusWithInstance ( item , account . instanceUrl ) ) ;
317317 }
318318
319+ async fetchBookmarks ( account : Account , limit : number = 20 , maxId ?: string ) : Promise < Status [ ] > {
320+ const response = await fetch ( `${ normalizeInstanceUrl ( account . instanceUrl ) } /api/i/favorites` , {
321+ method : "POST" ,
322+ headers : {
323+ "Content-Type" : "application/json"
324+ } ,
325+ body : JSON . stringify (
326+ buildBody ( account , {
327+ limit,
328+ untilId : maxId
329+ } )
330+ )
331+ } ) ;
332+ if ( ! response . ok ) {
333+ throw new Error ( "북마크를 불러오지 못했습니다." ) ;
334+ }
335+ const data = ( await response . json ( ) ) as unknown [ ] ;
336+ return data . map ( ( item ) => {
337+ const typed = item && typeof item === "object" ? ( item as Record < string , unknown > ) : null ;
338+ const note = typed && typed . note ? typed . note : item ;
339+ return mapMisskeyStatusWithInstance ( note , account . instanceUrl ) ;
340+ } ) ;
341+ }
342+
319343 async uploadMedia ( account : Account , file : File ) : Promise < string > {
320344 const formData = new FormData ( ) ;
321345 formData . append ( "i" , account . accessToken ) ;
@@ -338,6 +362,10 @@ export class MisskeyHttpClient implements MastodonApi {
338362 return id ;
339363 }
340364
365+ async fetchThreadContext ( account : Account , statusId : string ) : Promise < ThreadContext > {
366+ return this . fetchConversation ( account , statusId ) ;
367+ }
368+
341369 async fetchConversation ( account : Account , noteId : string ) : Promise < ThreadContext > {
342370 const response = await fetch ( `${ normalizeInstanceUrl ( account . instanceUrl ) } /api/notes/conversation` , {
343371 method : "POST" ,
@@ -432,6 +460,16 @@ export class MisskeyHttpClient implements MastodonApi {
432460 return this . fetchNote ( account , statusId ) ;
433461 }
434462
463+ async bookmark ( account : Account , statusId : string ) : Promise < Status > {
464+ await this . postSimple ( account , "/api/notes/favorites/create" , { noteId : statusId } ) ;
465+ return this . fetchNote ( account , statusId ) ;
466+ }
467+
468+ async unbookmark ( account : Account , statusId : string ) : Promise < Status > {
469+ await this . postSimple ( account , "/api/notes/favorites/delete" , { noteId : statusId } ) ;
470+ return this . fetchNote ( account , statusId ) ;
471+ }
472+
435473 async unfavourite ( account : Account , statusId : string ) : Promise < Status > {
436474 try {
437475 await this . postSimple ( account , "/api/notes/reactions/delete" , { noteId : statusId } ) ;
@@ -454,6 +492,19 @@ export class MisskeyHttpClient implements MastodonApi {
454492 return this . fetchNote ( account , statusId ) ;
455493 }
456494
495+ async fetchNoteState (
496+ account : Account ,
497+ noteId : string
498+ ) : Promise < { isFavourited : boolean ; isReblogged : boolean ; bookmarked : boolean } > {
499+ const note = await this . fetchNoteRaw ( account , noteId ) ;
500+ const isFavorited = Boolean ( note . isFavorited ?? false ) ;
501+ return {
502+ isFavourited : isFavorited ,
503+ isReblogged : Boolean ( note . myRenoteId ) ,
504+ bookmarked : isFavorited
505+ } ;
506+ }
507+
457508 async reblog ( account : Account , statusId : string ) : Promise < Status > {
458509 await this . postSimple ( account , "/api/notes/create" , { renoteId : statusId } ) ;
459510 return this . fetchNote ( account , statusId ) ;
0 commit comments