@@ -62,7 +62,7 @@ func home_timeline(c *fiber.Ctx) error {
6262 tweets := []bridge.Tweet {}
6363
6464 for _ , item := range res .Feed {
65- tweets = append (tweets , TranslatePostToTweet (item .Post , item .Reply .Parent .URI , item .Reply .Parent .Author .DID , & item .Reply .Parent .Record .CreatedAt , item .Reason ))
65+ tweets = append (tweets , TranslatePostToTweet (item .Post , item .Reply .Parent .URI , item .Reply .Parent .Author .DID , & item .Reply .Parent .Record .CreatedAt , item .Reason , * oauthToken ))
6666 }
6767
6868 // Store the oldest message id, along with our context in the DB
@@ -105,9 +105,6 @@ func RelatedResults(c *fiber.Ctx) error {
105105 return c .Status (fiber .StatusBadRequest ).SendString ("Invalid ID format" )
106106 }
107107 uri := * uriPtr
108- if err != nil {
109- return c .Status (fiber .StatusBadRequest ).SendString ("Invalid ID format" )
110- }
111108
112109 _ , _ , oauthToken , err := GetAuthFromReq (c )
113110 if err != nil {
@@ -120,6 +117,17 @@ func RelatedResults(c *fiber.Ctx) error {
120117 return err
121118 }
122119
120+ // Caching the user DIDs efficiently
121+ userDIDs := []string {}
122+
123+ for _ , item := range * thread .Thread .Replies {
124+ if ! slices .Contains (userDIDs , item .Post .Author .DID ) {
125+ userDIDs = append (userDIDs , item .Post .Author .DID )
126+ }
127+ }
128+
129+ blueskyapi .GetUsersInfo (* oauthToken , userDIDs )
130+
123131 postAuthor := bridge .BlueSkyToTwitterID (thread .Thread .Post .Author .DID )
124132
125133 twitterReplies := bridge.RelatedResultsQuery {
@@ -134,7 +142,7 @@ func RelatedResults(c *fiber.Ctx) error {
134142 twitterReplies .Results = append (twitterReplies .Results , bridge.Results {
135143 Kind : "Tweet" ,
136144 Score : 1.0 ,
137- Value : TranslatePostToTweet (reply .Post , uri , postAuthor .String (), & thread .Thread .Post .Record .CreatedAt , nil ),
145+ Value : TranslatePostToTweet (reply .Post , uri , postAuthor .String (), & thread .Thread .Post .Record .CreatedAt , nil , * oauthToken ),
138146 Annotations : []bridge.Annotations {
139147 {
140148 ConversationRole : "Descendant" ,
@@ -160,9 +168,6 @@ func GetStatusFromId(c *fiber.Ctx) error {
160168 return c .Status (fiber .StatusBadRequest ).SendString ("Invalid ID format" )
161169 }
162170 uri := * uriPtr
163- if err != nil {
164- return c .Status (fiber .StatusBadRequest ).SendString ("Invalid ID format" )
165- }
166171
167172 fmt .Println ("URI:" , uri )
168173 _ , _ , oauthToken , err := GetAuthFromReq (c )
@@ -179,13 +184,13 @@ func GetStatusFromId(c *fiber.Ctx) error {
179184
180185 // TODO: Some things may be needed for reposts to show up correctly. thats a later problem :)
181186 if thread .Thread .Parent == nil {
182- return c .JSON (TranslatePostToTweet (thread .Thread .Post , "" , "" , nil , nil ))
187+ return c .JSON (TranslatePostToTweet (thread .Thread .Post , "" , "" , nil , nil , * oauthToken ))
183188 } else {
184- return c .JSON (TranslatePostToTweet (thread .Thread .Post , thread .Thread .Parent .URI , thread .Thread .Parent .Author .DID , & thread .Thread .Parent .Record .CreatedAt , nil ))
189+ return c .JSON (TranslatePostToTweet (thread .Thread .Post , thread .Thread .Parent .URI , thread .Thread .Parent .Author .DID , & thread .Thread .Parent .Record .CreatedAt , nil , * oauthToken ))
185190 }
186191}
187192
188- func TranslatePostToTweet (tweet blueskyapi.Post , replyMsgBskyURI string , replyUserBskyId string , replyTimeStamp * time.Time , postReason * blueskyapi.PostReason ) bridge.Tweet {
193+ func TranslatePostToTweet (tweet blueskyapi.Post , replyMsgBskyURI string , replyUserBskyId string , replyTimeStamp * time.Time , postReason * blueskyapi.PostReason , token string ) bridge.Tweet {
189194 tweetEntities := bridge.Entities {
190195 Hashtags : nil ,
191196 Urls : nil ,
@@ -256,6 +261,16 @@ func TranslatePostToTweet(tweet blueskyapi.Post, replyMsgBskyURI string, replyUs
256261 }
257262 }
258263
264+ // Get the user info
265+ var author * bridge.TwitterUser
266+ author , err := blueskyapi .GetUserInfo (token , tweet .Author .DID )
267+ if err != nil {
268+ fmt .Println ("Error:" , err )
269+ // fallback
270+ authorPtr := GetUserInfoFromTweetData (tweet )
271+ author = & authorPtr
272+ }
273+
259274 convertedTweet := bridge.Tweet {
260275 Coordinates : nil ,
261276 Favourited : tweet .Viewer .Like != nil ,
@@ -306,56 +321,8 @@ func TranslatePostToTweet(tweet blueskyapi.Post, replyMsgBskyURI string, replyUs
306321 return & idStr
307322 }(),
308323 InReplyToScreenName : & tweet .Author .DisplayName ,
309- User : bridge.TwitterUser {
310- Name : func () string {
311- if tweet .Author .DisplayName == "" {
312- return tweet .Author .Handle
313- }
314- return tweet .Author .DisplayName
315- }(),
316- ProfileSidebarBorderColor : "eeeeee" ,
317- ProfileBackgroundTile : false ,
318- ProfileSidebarFillColor : "efefef" ,
319- CreatedAt : bridge .TwitterTimeConverter (tweet .Author .Associated .CreatedAt ),
320- ProfileImageURL : "http://10.0.0.77:3000/cdn/img/?url=" + url .QueryEscape (tweet .Author .Avatar ) + "&width=128&height=128" ,
321- // ProfileImageURLHttps: "https://10.0.0.77:3000/cdn/img/?url=" + url.QueryEscape(tweet.Author.Avatar) + "&width=128&height=128",
322- Location : "Twitter" ,
323- ProfileLinkColor : "009999" ,
324- FollowRequestSent : false ,
325- URL : "" ,
326- ScreenName : tweet .Author .Handle ,
327- ContributorsEnabled : false ,
328- UtcOffset : nil ,
329- IsTranslator : false ,
330- ID : * bridge .BlueSkyToTwitterID (tweet .URI ),
331- // IDStr: bridge.BlueSkyToTwitterID(tweet.URI).String(),
332- ProfileUseBackgroundImage : false ,
333- ProfileTextColor : "333333" ,
334- Protected : false ,
335- Lang : "en" ,
336- Notifications : nil ,
337- TimeZone : nil ,
338- Verified : false ,
339- ProfileBackgroundColor : "C0DEED" ,
340- GeoEnabled : true ,
341- Description : "" ,
342- ProfileBackgroundImageURL : "http://a0.twimg.com/images/themes/theme1/bg.png" ,
343- // ProfileBackgroundImageURLHttps: "http://a0.twimg.com/images/themes/theme1/bg.png",
344- Following : nil ,
345-
346- // huh
347- DefaultProfile : false ,
348- DefaultProfileImage : false ,
349- ShowAllInlineMedia : false ,
350-
351- // User Stats
352- // ListedCount: 0,
353- // FavouritesCount: 0,
354- // FollowersCount: 200,
355- // FriendsCount: 100,
356- // StatusesCount: 333,
357- },
358- Source : "Bluesky" ,
324+ User : * author ,
325+ Source : "Bluesky" ,
359326 InReplyToStatusID : func () * big.Int {
360327 if replyMsgBskyURI == "" {
361328 return nil
@@ -375,7 +342,7 @@ func TranslatePostToTweet(tweet blueskyapi.Post, replyMsgBskyURI string, replyUs
375342 if isRetweet {
376343 retweet_bsky := tweet
377344 retweet_bsky .Author = bsky_retweet_author
378- translatedTweet := TranslatePostToTweet (retweet_bsky , replyMsgBskyURI , replyUserBskyId , replyTimeStamp , nil )
345+ translatedTweet := TranslatePostToTweet (retweet_bsky , replyMsgBskyURI , replyUserBskyId , replyTimeStamp , nil , token )
379346 return & translatedTweet
380347 }
381348 return nil
@@ -384,6 +351,59 @@ func TranslatePostToTweet(tweet blueskyapi.Post, replyMsgBskyURI string, replyUs
384351 return convertedTweet
385352}
386353
354+ // This is "depercated"/a togglable option in the config (eventually)
355+ func GetUserInfoFromTweetData (tweet blueskyapi.Post ) bridge.TwitterUser {
356+ return bridge.TwitterUser {
357+ Name : func () string {
358+ if tweet .Author .DisplayName == "" {
359+ return tweet .Author .Handle
360+ }
361+ return tweet .Author .DisplayName
362+ }(),
363+ ProfileSidebarBorderColor : "eeeeee" ,
364+ ProfileBackgroundTile : false ,
365+ ProfileSidebarFillColor : "efefef" ,
366+ CreatedAt : bridge .TwitterTimeConverter (tweet .Author .Associated .CreatedAt ),
367+ ProfileImageURL : "http://10.0.0.77:3000/cdn/img/?url=" + url .QueryEscape (tweet .Author .Avatar ) + "&width=128&height=128" ,
368+ // ProfileImageURLHttps: "https://10.0.0.77:3000/cdn/img/?url=" + url.QueryEscape(tweet.Author.Avatar) + "&width=128&height=128",
369+ Location : "Twitter" ,
370+ ProfileLinkColor : "009999" ,
371+ FollowRequestSent : false ,
372+ URL : "" ,
373+ ScreenName : tweet .Author .Handle ,
374+ ContributorsEnabled : false ,
375+ UtcOffset : nil ,
376+ IsTranslator : false ,
377+ ID : * bridge .BlueSkyToTwitterID (tweet .URI ),
378+ // IDStr: bridge.BlueSkyToTwitterID(tweet.URI).String(),
379+ ProfileUseBackgroundImage : false ,
380+ ProfileTextColor : "333333" ,
381+ Protected : false ,
382+ Lang : "en" ,
383+ Notifications : nil ,
384+ TimeZone : nil ,
385+ Verified : false ,
386+ ProfileBackgroundColor : "C0DEED" ,
387+ GeoEnabled : true ,
388+ Description : "" ,
389+ ProfileBackgroundImageURL : "http://a0.twimg.com/images/themes/theme1/bg.png" ,
390+ // ProfileBackgroundImageURLHttps: "http://a0.twimg.com/images/themes/theme1/bg.png",
391+ Following : nil ,
392+
393+ // huh
394+ DefaultProfile : false ,
395+ DefaultProfileImage : false ,
396+ ShowAllInlineMedia : false ,
397+
398+ // User Stats
399+ // ListedCount: 0,
400+ // FavouritesCount: 0,
401+ // FollowersCount: 200,
402+ // FriendsCount: 100,
403+ // StatusesCount: 333,
404+ }
405+ }
406+
387407// This request is an "internal" request, and thus, these are very little to no docs. this is a problem.
388408// The most docs I could find: https://blog.fgribreau.com/2012/01/twitter-unofficial-api-getting-tweets.html
389409func TweetInfo (c * fiber.Ctx ) error {
0 commit comments