@@ -9,8 +9,6 @@ import dayjs from 'dayjs';
99import { SocialAbstract } from '@gitroom/nestjs-libraries/integrations/social.abstract' ;
1010import { NeynarAPIClient } from '@neynar/nodejs-sdk' ;
1111import { Integration } from '@prisma/client' ;
12- import { AuthService } from '@gitroom/helpers/auth/auth.service' ;
13- import { groupBy } from 'lodash' ;
1412import { FarcasterDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/farcaster.dto' ;
1513import { Tool } from '@gitroom/nestjs-libraries/integrations/tool.decorator' ;
1614import { Rules } from '@gitroom/nestjs-libraries/chat/rules.description.decorator' ;
@@ -81,48 +79,83 @@ export class FarcasterProvider
8179 accessToken : string ,
8280 postDetails : PostDetails < FarcasterDto > [ ]
8381 ) : Promise < PostResponse [ ] > {
84- const ids = [ ] ;
85- const subreddit =
86- ! postDetails ?. [ 0 ] ?. settings ?. subreddit ||
87- postDetails ?. [ 0 ] ?. settings ?. subreddit . length === 0
82+ const [ firstPost ] = postDetails ;
83+ const ids : { releaseURL : string ; postId : string } [ ] = [ ] ;
84+
85+ const channels =
86+ ! firstPost ?. settings ?. subreddit ||
87+ firstPost ?. settings ?. subreddit . length === 0
8888 ? [ undefined ]
89- : postDetails ?. [ 0 ] ?. settings ?. subreddit ;
90-
91- for ( const channel of subreddit ) {
92- let idHash = '' ;
93- for ( const post of postDetails ) {
94- const data = await client . publishCast ( {
95- embeds :
96- post ?. media ?. map ( ( media ) => ( {
97- url : media . path ,
98- } ) ) || [ ] ,
99- signerUuid : accessToken ,
100- text : post . message ,
101- ...( idHash ? { parent : idHash } : { } ) ,
102- ...( channel ?. value ?. id ? { channelId : channel ?. value ?. id } : { } ) ,
103- } ) ;
104- idHash = data . cast . hash ;
105-
106- ids . push ( {
107- // @ts -ignore
108- releaseURL : `https://warpcast.com/${ data . cast . author . username } /${ idHash } ` ,
109- status : 'success' ,
110- id : post . id ,
111- postId : data . cast . hash ,
112- // @ts -ignore
113- author : data . cast . author . username ,
114- } ) ;
115- }
89+ : firstPost ?. settings ?. subreddit ;
90+
91+ for ( const channel of channels ) {
92+ const data = await client . publishCast ( {
93+ embeds :
94+ firstPost ?. media ?. map ( ( media ) => ( {
95+ url : media . path ,
96+ } ) ) || [ ] ,
97+ signerUuid : accessToken ,
98+ text : firstPost . message ,
99+ ...( channel ?. value ?. id ? { channelId : channel ?. value ?. id } : { } ) ,
100+ } ) ;
101+
102+ ids . push ( {
103+ // @ts -ignore
104+ releaseURL : `https://warpcast.com/${ data . cast . author . username } /${ data . cast . hash } ` ,
105+ postId : data . cast . hash ,
106+ } ) ;
116107 }
117108
118- const list = Object . values ( groupBy ( ids , ( p ) => p . id ) ) . map ( ( p ) => ( {
119- id : p [ 0 ] . id ,
120- postId : p . map ( ( p ) => String ( p . postId ) ) . join ( ',' ) ,
121- releaseURL : p . map ( ( p ) => p . releaseURL ) . join ( ',' ) ,
122- status : 'published' ,
123- } ) ) ;
109+ return [
110+ {
111+ id : firstPost . id ,
112+ postId : ids . map ( ( p ) => p . postId ) . join ( ',' ) ,
113+ releaseURL : ids . map ( ( p ) => p . releaseURL ) . join ( ',' ) ,
114+ status : 'published' ,
115+ } ,
116+ ] ;
117+ }
118+
119+ async comment (
120+ id : string ,
121+ postId : string ,
122+ lastCommentId : string | undefined ,
123+ accessToken : string ,
124+ postDetails : PostDetails < FarcasterDto > [ ] ,
125+ integration : Integration
126+ ) : Promise < PostResponse [ ] > {
127+ const [ commentPost ] = postDetails ;
128+ const ids : { releaseURL : string ; postId : string } [ ] = [ ] ;
129+
130+ // postId can be comma-separated if posted to multiple channels
131+ const parentIds = ( lastCommentId || postId ) . split ( ',' ) ;
132+
133+ for ( const parentHash of parentIds ) {
134+ const data = await client . publishCast ( {
135+ embeds :
136+ commentPost ?. media ?. map ( ( media ) => ( {
137+ url : media . path ,
138+ } ) ) || [ ] ,
139+ signerUuid : accessToken ,
140+ text : commentPost . message ,
141+ parent : parentHash ,
142+ } ) ;
143+
144+ ids . push ( {
145+ // @ts -ignore
146+ releaseURL : `https://warpcast.com/${ data . cast . author . username } /${ data . cast . hash } ` ,
147+ postId : data . cast . hash ,
148+ } ) ;
149+ }
124150
125- return list ;
151+ return [
152+ {
153+ id : commentPost . id ,
154+ postId : ids . map ( ( p ) => p . postId ) . join ( ',' ) ,
155+ releaseURL : ids . map ( ( p ) => p . releaseURL ) . join ( ',' ) ,
156+ status : 'published' ,
157+ } ,
158+ ] ;
126159 }
127160
128161 @Tool ( {
0 commit comments