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

Function GetUsersRelationship

twitterv1/user.go:203–305  ·  view source on GitHub ↗

Gets the relationship between two users https://web.archive.org/web/20120516154953/https://dev.twitter.com/docs/api/1/get/friendships/show

(c *fiber.Ctx)

Source from the content-addressed store, hash-verified

201// Gets the relationship between two users
202// https://web.archive.org/web/20120516154953/https://dev.twitter.com/docs/api/1/get/friendships/show
203func GetUsersRelationship(c *fiber.Ctx) error {
204 // Get the actors
205 sourceActor := c.Query("source_id")
206 if sourceActor == "" {
207 sourceActor = c.Query("source_screen_name")
208 if sourceActor == "" {
209 return ReturnError(c, "No source user was specified", 195, 403)
210 }
211 } else {
212 sourceIDInt, err := strconv.ParseInt(sourceActor, 10, 64)
213 if err != nil {
214 return ReturnError(c, "Invalid source ID format", 195, 403)
215 }
216 sourceActorPtr, err := bridge.TwitterIDToBlueSky(&sourceIDInt)
217 if err != nil {
218 return ReturnError(c, "Source ID not found.", 144, fiber.StatusNotFound)
219 }
220 if sourceActorPtr == nil {
221 return ReturnError(c, "Source ID not found.", 144, fiber.StatusNotFound)
222 }
223 sourceActor = *sourceActorPtr
224 }
225
226 targetActor := c.Query("target_id")
227 if targetActor == "" {
228 targetActor = c.Query("target_screen_name")
229 if targetActor == "" {
230 return ReturnError(c, "No target user was specified", 195, 403)
231 }
232 } else {
233 targetIDInt, err := strconv.ParseInt(targetActor, 10, 64)
234 if err != nil {
235 return ReturnError(c, "Invalid target ID format", 195, 403)
236 }
237 targetActorPtr, err := bridge.TwitterIDToBlueSky(&targetIDInt)
238 if err != nil {
239 return ReturnError(c, "Target ID not found.", 144, fiber.StatusNotFound)
240 }
241 if targetActorPtr == nil {
242 return ReturnError(c, "Target ID not found.", 144, fiber.StatusNotFound)
243 }
244 targetActor = *targetActorPtr
245 }
246
247 // auth
248 _, pds, _, oauthToken, err := GetAuthFromReq(c)
249 if err != nil {
250 blankstring := "" // I. Hate. This.
251 oauthToken = &blankstring
252 }
253
254 // It looks like there's a bug where I can't pass handles into GetRelationships, but we need to get the handle anyways, so this shouldn't impact that much
255
256 targetUser, err := blueskyapi.GetUserInfo(*pds, *oauthToken, targetActor, false)
257 if err != nil {
258 return HandleBlueskyError(c, err.Error(), "app.bsky.actor.getProfile", GetUsersRelationship)
259 }
260 // Possible optimization: if the source user is us, we can skip the api call, and just use viewer info

Callers

nothing calls this directly

Calls 5

TwitterIDToBlueSkyFunction · 0.92
ReturnErrorFunction · 0.85
GetAuthFromReqFunction · 0.85
HandleBlueskyErrorFunction · 0.85
EncodeAndSendFunction · 0.85

Tested by

no test coverage detected