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

Function favourite

twitterv1/interaction.go:227–271  ·  view source on GitHub ↗

https://web.archive.org/web/20120412065707/https://dev.twitter.com/docs/api/1/post/favorites/create/%3Aid

(c *fiber.Ctx)

Source from the content-addressed store, hash-verified

225
226// https://web.archive.org/web/20120412065707/https://dev.twitter.com/docs/api/1/post/favorites/create/%3Aid
227func favourite(c *fiber.Ctx) error {
228 postId := c.Params("id")
229 user_did, pds, _, oauthToken, err := GetAuthFromReq(c)
230
231 if err != nil {
232 return MissingAuth(c, err)
233 }
234
235 // Fetch ID
236 idBigInt, err := strconv.ParseInt(postId, 10, 64)
237 if err != nil {
238 return ReturnError(c, "Invalid ID format", 195, 403)
239 }
240 postIdPtr, _, _, err := bridge.TwitterMsgIdToBluesky(&idBigInt)
241 if err != nil {
242 return ReturnError(c, "Id not found.", 144, fiber.StatusNotFound)
243 }
244 postId = *postIdPtr
245
246 post, err := blueskyapi.LikePost(*pds, *oauthToken, postId, *user_did)
247
248 if err != nil {
249 fmt.Println("Error:", err)
250 return HandleBlueskyError(c, err.Error(), "com.atproto.repo.createRecord", favourite)
251 }
252
253 var newTweet bridge.Tweet
254 if post.Thread.Parent == nil {
255 newTweet = TranslatePostToTweet(post.Thread.Post, "", "", "", nil, nil, *oauthToken, *pds)
256 } else {
257 newTweet = TranslatePostToTweet(post.Thread.Post, post.Thread.Parent.Post.URI, post.Thread.Parent.Post.Author.DID, post.Thread.Parent.Post.Author.Handle, &post.Thread.Parent.Post.Record.CreatedAt.Time, nil, *oauthToken, *pds)
258 }
259
260 db_controller.StoreAnalyticData(db_controller.AnalyticData{
261 DataType: "favorited",
262 IPAddress: c.IP(),
263 UserAgent: c.Get("User-Agent"),
264 Language: c.Get("Accept-Language"),
265 TwitterClient: c.Get("X-Twitter-Client"),
266 TwitterClientVersion: c.Get("X-Twitter-Client-Version"),
267 Timestamp: time.Now(),
268 })
269
270 return EncodeAndSend(c, newTweet)
271}
272
273// https://web.archive.org/web/20120412041153/https://dev.twitter.com/docs/api/1/post/favorites/destroy/%3Aid
274func Unfavourite(c *fiber.Ctx) error { // yes i am canadian

Callers

nothing calls this directly

Calls 9

TwitterMsgIdToBlueskyFunction · 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