@@ -19,6 +19,7 @@ import type { FetchListService } from '../../service/fetchList.js';
1919import type { FetchListMemberService } from '../../service/fetchMember.js' ;
2020import type { HomeTimelineService } from '../../service/home.js' ;
2121import type { ListTimelineService } from '../../service/list.js' ;
22+ import type { PublicTimelineService } from '../../service/public.js' ;
2223import type { RemoveListMemberService } from '../../service/removeMember.js' ;
2324import type {
2425 CreateListResponseSchema ,
@@ -30,6 +31,7 @@ import type {
3031 GetHomeTimelineResponseSchema ,
3132 GetListMemberResponseSchema ,
3233 GetListTimelineResponseSchema ,
34+ GetPublicTimelineResponseSchema ,
3335} from '../validator/timeline.js' ;
3436
3537export class TimelineController {
@@ -47,6 +49,7 @@ export class TimelineController {
4749 private readonly removeListMemberService : RemoveListMemberService ;
4850 private readonly fetchBookmarkTimelineService : FetchBookmarkService ;
4951 private readonly fetchConversationService : FetchConversationService ;
52+ private readonly publicTimelineService : PublicTimelineService ;
5053
5154 constructor ( args : {
5255 accountTimelineService : AccountTimelineService ;
@@ -63,6 +66,7 @@ export class TimelineController {
6366 removeListMemberService : RemoveListMemberService ;
6467 fetchBookmarkTimelineService : FetchBookmarkService ;
6568 fetchConversationService : FetchConversationService ;
69+ publicTimelineService : PublicTimelineService ;
6670 } ) {
6771 this . accountTimelineService = args . accountTimelineService ;
6872 this . accountModule = args . accountModule ;
@@ -78,6 +82,7 @@ export class TimelineController {
7882 this . removeListMemberService = args . removeListMemberService ;
7983 this . fetchBookmarkTimelineService = args . fetchBookmarkTimelineService ;
8084 this . fetchConversationService = args . fetchConversationService ;
85+ this . publicTimelineService = args . publicTimelineService ;
8186 }
8287
8388 private async getNoteAdditionalData ( notes : readonly Note [ ] ) : Promise <
@@ -625,4 +630,66 @@ export class TimelineController {
625630 } ) ,
626631 ) ;
627632 }
633+
634+ async getPublicTimeline (
635+ hasAttachment : boolean ,
636+ noNsfw : boolean ,
637+ beforeId ?: string ,
638+ afterId ?: string ,
639+ ) : Promise <
640+ Result . Result < Error , z . infer < typeof GetPublicTimelineResponseSchema > >
641+ > {
642+ const res = await this . publicTimelineService . fetchPublicTimeline ( {
643+ hasAttachment,
644+ noNsfw,
645+ beforeId : beforeId as NoteID | undefined ,
646+ afterID : afterId as NoteID | undefined ,
647+ } ) ;
648+ if ( Result . isErr ( res ) ) {
649+ return res ;
650+ }
651+ const publicNotes = Result . unwrap ( res ) ;
652+
653+ const noteAdditionalDataRes = await this . getNoteAdditionalData ( publicNotes ) ;
654+ if ( Result . isErr ( noteAdditionalDataRes ) ) {
655+ return noteAdditionalDataRes ;
656+ }
657+ const noteAdditionalData = Result . unwrap ( noteAdditionalDataRes ) ;
658+
659+ const result = noteAdditionalData . map ( ( v ) => {
660+ return {
661+ id : v . note . getID ( ) ,
662+ content : v . note . getContent ( ) ,
663+ contents_warning_comment : v . note . getCwComment ( ) ,
664+ visibility : v . note . getVisibility ( ) ,
665+ created_at : v . note . getCreatedAt ( ) . toUTCString ( ) ,
666+ reactions : v . reactions . map ( ( reaction ) => ( {
667+ emoji : reaction . getEmoji ( ) ,
668+ reacted_by : reaction . getAccountID ( ) ,
669+ } ) ) ,
670+ attachment_files : v . attachments . map ( ( file ) => ( {
671+ id : file . getId ( ) ,
672+ name : file . getName ( ) ,
673+ author_id : file . getAuthorId ( ) ,
674+ hash : file . getHash ( ) ,
675+ mime : file . getMime ( ) ,
676+ nsfw : file . isNsfw ( ) ,
677+ url : file . getUrl ( ) ,
678+ thumbnail : file . getThumbnailUrl ( ) ,
679+ } ) ) ,
680+ author : {
681+ id : v . author . getID ( ) ,
682+ name : v . author . getName ( ) ,
683+ display_name : v . author . getNickname ( ) ,
684+ bio : v . author . getBio ( ) ,
685+ avatar : v . avatar ,
686+ header : v . header ,
687+ followed_count : v . followCount . followed ,
688+ following_count : v . followCount . following ,
689+ } ,
690+ } ;
691+ } ) ;
692+
693+ return Result . ok ( result ) ;
694+ }
628695}
0 commit comments