MCPcopy Index your code
hub / github.com/Preloading/TwitterAPIBridge / TranslatePostToTweet

Function TranslatePostToTweet

twitterv1/post_viewing.go:279–747  ·  view source on GitHub ↗

This gigantic function is used to convert the bluesky post format, into a format that is compatible with the twitter API. https://web.archive.org/web/20120506182126/https://dev.twitter.com/docs/platform-objects/tweets

(tweet blueskyapi.Post, replyMsgBskyURI string, replyUserBskyId string, replyUserHandle string, replyTimeStamp *time.Time, postReason *blueskyapi.PostReason, token string, pds string)

Source from the content-addressed store, hash-verified

277// This gigantic function is used to convert the bluesky post format, into a format that is compatible with the twitter API.
278// https://web.archive.org/web/20120506182126/https://dev.twitter.com/docs/platform-objects/tweets
279func TranslatePostToTweet(tweet blueskyapi.Post, replyMsgBskyURI string, replyUserBskyId string, replyUserHandle string, replyTimeStamp *time.Time, postReason *blueskyapi.PostReason, token string, pds string) bridge.Tweet {
280 var err error
281 textOffset := 0
282
283 isRetweet := false
284 bsky_retweet_og_author := tweet.Author
285
286 // Checking if this tweet is a retweet
287 if postReason != nil {
288 // This might contain other things in the future, idk
289 if postReason.Type == "app.bsky.feed.defs#reasonRepost" {
290 // We are a retweet.
291 isRetweet = true
292
293 }
294 }
295
296 if len(tweet.Record.Langs) > 0 {
297 db_controller.StoreAnalyticData(db_controller.AnalyticData{
298 DataType: "postviewing",
299 Timestamp: time.Now(),
300 Language: tweet.Record.Langs[0],
301 })
302 } else {
303 db_controller.StoreAnalyticData(db_controller.AnalyticData{
304 DataType: "postviewing",
305 Timestamp: time.Now(),
306 })
307 }
308
309 processedText := func() string {
310 // This fucks up all the entities :crying:
311
312 if isRetweet {
313 retweetedText := "RT @" + bsky_retweet_og_author.Handle + ": "
314 textOffset += utf8.RuneCountInString(retweetedText)
315 return retweetedText + tweet.Record.Text
316 }
317 return tweet.Record.Text
318 }()
319
320 if isRetweet {
321 tweet.Author = postReason.By
322 }
323
324 tweetEntities := bridge.Entities{
325 Hashtags: nil,
326 Urls: nil,
327 UserMentions: []bridge.UserMention{},
328 Media: []bridge.Media{},
329 }
330
331 id := 1
332 for _, image := range tweet.Record.Embed.Images {
333 // Add the image "url" to the text
334 startLen, endLen := 0, 0
335 formattedImageURL := configData.ImgURLText
336 displayURL := configData.ImgDisplayText

Callers 13

GetMyActivityFunction · 0.85
convert_timelineFunction · 0.85
RelatedResultsFunction · 0.85
GetStatusFromIdFunction · 0.85
mentions_timelineFunction · 0.85
InternalSearchFunction · 0.85
discoveryFunction · 0.85
status_updateFunction · 0.85
status_update_with_mediaFunction · 0.85
retweetFunction · 0.85
favouriteFunction · 0.85
UnfavouriteFunction · 0.85

Calls 6

StoreAnalyticDataFunction · 0.92
BlueSkyToTwitterIDFunction · 0.92
TwitterTimeConverterFunction · 0.92
BskyMsgToTwitterIDFunction · 0.92
CreateShortLinkFunction · 0.85
GetUserInfoFromTweetDataFunction · 0.85

Tested by

no test coverage detected