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)
| 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 |
| 279 | func 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 |
no test coverage detected