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

Function retweet

twitterv1/interaction.go:165–224  ·  view source on GitHub ↗

https://web.archive.org/web/20120407091252/https://dev.twitter.com/docs/api/1/post/statuses/retweet/%3Aid

(c *fiber.Ctx)

Source from the content-addressed store, hash-verified

163
164// https://web.archive.org/web/20120407091252/https://dev.twitter.com/docs/api/1/post/statuses/retweet/%3Aid
165func retweet(c *fiber.Ctx) error {
166 postId := c.Params("id")
167 user_did, pds, _, oauthToken, err := GetAuthFromReq(c)
168
169 if err != nil {
170 return MissingAuth(c, err)
171 }
172
173 // Get our IDs
174 idBigInt, err := strconv.ParseInt(postId, 10, 64)
175 if err != nil {
176 return ReturnError(c, "Invalid ID format", 195, 403)
177 }
178 postIdPtr, _, _, err := bridge.TwitterMsgIdToBluesky(&idBigInt)
179 if err != nil {
180 return ReturnError(c, "Id not found.", 144, fiber.StatusNotFound)
181 }
182 postId = *postIdPtr
183
184 originalPost, blueskyRepostURI, err := blueskyapi.ReTweet(*pds, *oauthToken, postId, *user_did)
185
186 if err != nil {
187 fmt.Println("Error:", err)
188 return HandleBlueskyError(c, err.Error(), "com.atproto.repo.createRecord", retweet)
189 }
190
191 var retweet bridge.Tweet
192 if originalPost.Thread.Parent == nil {
193 retweet = TranslatePostToTweet(originalPost.Thread.Post, "", "", "", nil, nil, *oauthToken, *pds)
194 } else {
195 retweet = TranslatePostToTweet(originalPost.Thread.Post, originalPost.Thread.Parent.Post.URI, originalPost.Thread.Parent.Post.Author.DID, originalPost.Thread.Parent.Post.Author.Handle, &originalPost.Thread.Parent.Post.Record.CreatedAt.Time, nil, *oauthToken, *pds)
196 }
197 retweet.Retweeted = true
198 now := time.Now() // pain, also fix this to use the proper timestamp according to the server.
199 retweetId := bridge.BskyMsgToTwitterID(originalPost.Thread.Post.URI, &now, user_did)
200 retweet.ID = *retweetId
201 retweet.IDStr = strconv.FormatInt(retweet.ID, 10)
202 originalPost.Thread.Post.Viewer.Repost = blueskyRepostURI
203
204 db_controller.StoreAnalyticData(db_controller.AnalyticData{
205 DataType: "retweeted",
206 IPAddress: c.IP(),
207 UserAgent: c.Get("User-Agent"),
208 Language: c.Get("Accept-Language"),
209 TwitterClient: c.Get("X-Twitter-Client"),
210 TwitterClientVersion: c.Get("X-Twitter-Client-Version"),
211 Timestamp: time.Now(),
212 })
213
214 return EncodeAndSend(c, bridge.Retweet{
215 Tweet: retweet,
216 RetweetedStatus: func() bridge.Tweet { // TODO: make this respond with proper retweet data
217 if originalPost.Thread.Parent == nil {
218 return TranslatePostToTweet(originalPost.Thread.Post, "", "", "", nil, nil, *oauthToken, *pds)
219 } else {
220 return TranslatePostToTweet(originalPost.Thread.Post, originalPost.Thread.Parent.Post.URI, originalPost.Thread.Parent.Post.Author.DID, originalPost.Thread.Parent.Post.Author.Handle, &originalPost.Thread.Parent.Post.Record.CreatedAt.Time, nil, *oauthToken, *pds)
221 }
222 }(),

Callers

nothing calls this directly

Calls 10

TwitterMsgIdToBlueskyFunction · 0.92
BskyMsgToTwitterIDFunction · 0.92
StoreAnalyticDataFunction · 0.92
GetAuthFromReqFunction · 0.85
MissingAuthFunction · 0.85
ReturnErrorFunction · 0.85
HandleBlueskyErrorFunction · 0.85
TranslatePostToTweetFunction · 0.85
EncodeAndSendFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected