@@ -422,33 +422,17 @@ func UnfollowUserParams(c *fiber.Ctx) error {
422422// At the moment we are not doing pagination, so this will only return the first ~50 followers.
423423func GetStatusesFollowers (c * fiber.Ctx ) error {
424424 // auth
425- _ , pds , _ , oauthToken , err := GetAuthFromReq (c )
425+ userDID , pds , _ , oauthToken , err := GetAuthFromReq (c )
426426 if err != nil {
427427 return MissingAuth (c , err )
428428 }
429429
430430 // lets go get our user data
431-
432- actor := c .FormValue ("user_id" )
433- if actor == "" {
434- actor = c .FormValue ("screen_name" )
435- if actor == "" {
436- return ReturnError (c , "No user was specified" , 195 , 403 )
437- }
438- } else {
439- id , err := strconv .ParseInt (actor , 10 , 64 )
440- if err != nil {
441- return ReturnError (c , "Invalid ID format" , 195 , 403 )
442- }
443- actorPtr , err := bridge .TwitterIDToBlueSky (& id )
444- if err != nil {
445- return ReturnError (c , "ID not found." , 144 , fiber .StatusNotFound )
446- }
447- if actorPtr == nil {
448- return ReturnError (c , "ID not found." , 144 , fiber .StatusNotFound )
449- }
450- actor = * actorPtr
431+ actorPtr , err := GetUserSpecifiedInRequest (c , userDID )
432+ if err != nil {
433+ return err
451434 }
435+ actor := * actorPtr
452436
453437 // fetch followers
454438 followers , err := blueskyapi .GetFollowers (* pds , * oauthToken , "" , actor )
@@ -489,30 +473,11 @@ func GetFollowers(c *fiber.Ctx) error {
489473 }
490474
491475 // lets go get our user data
492- actor := c .FormValue ("user_id" )
493- if actor == "" {
494- actor = c .FormValue ("screen_name" )
495- if actor == "" {
496- if userDID != nil {
497- actor = * userDID
498- } else {
499- return ReturnError (c , "No user was specified" , 195 , 403 )
500- }
501- }
502- } else {
503- id , err := strconv .ParseInt (actor , 10 , 64 )
504- if err != nil {
505- return ReturnError (c , "Invalid ID format" , 195 , 403 )
506- }
507- actorPtr , err := bridge .TwitterIDToBlueSky (& id )
508- if err != nil {
509- return ReturnError (c , "ID not found." , 144 , fiber .StatusNotFound )
510- }
511- if actorPtr == nil {
512- return ReturnError (c , "ID not found." , 144 , fiber .StatusNotFound )
513- }
514- actor = * actorPtr
476+ actorPtr , err := GetUserSpecifiedInRequest (c , userDID )
477+ if err != nil {
478+ return err
515479 }
480+ actor := * actorPtr
516481
517482 cursor := ""
518483 var cursorInt int64
@@ -598,33 +563,17 @@ func GetFollowers(c *fiber.Ctx) error {
598563// https://web.archive.org/web/20120407214017/https://dev.twitter.com/docs/api/1/get/statuses/friends
599564func GetStatusesFollows (c * fiber.Ctx ) error {
600565 // auth
601- _ , pds , _ , oauthToken , err := GetAuthFromReq (c )
566+ userDID , pds , _ , oauthToken , err := GetAuthFromReq (c )
602567 if err != nil {
603568 return MissingAuth (c , err )
604569 }
605570
606571 // lets go get our user data
607-
608- actor := c .FormValue ("user_id" )
609- if actor == "" {
610- actor = c .FormValue ("screen_name" )
611- if actor == "" {
612- return ReturnError (c , "No user was specified" , 195 , 403 )
613- }
614- } else {
615- id , err := strconv .ParseInt (actor , 10 , 64 )
616- if err != nil {
617- return ReturnError (c , "Invalid ID format" , 195 , 403 )
618- }
619- actorPtr , err := bridge .TwitterIDToBlueSky (& id )
620- if err != nil {
621- return ReturnError (c , "ID not found." , 144 , fiber .StatusNotFound )
622- }
623- if actorPtr == nil {
624- return ReturnError (c , "ID not found." , 144 , fiber .StatusNotFound )
625- }
626- actor = * actorPtr
572+ actorPtr , err := GetUserSpecifiedInRequest (c , userDID )
573+ if err != nil {
574+ return err
627575 }
576+ actor := * actorPtr
628577
629578 // fetch follows
630579 followers , err := blueskyapi .GetFollows (* pds , * oauthToken , "" , actor )
@@ -777,31 +726,88 @@ func GetFollowingIds(c *fiber.Ctx) error {
777726 }
778727
779728 // lets go get our user data
780- actor := c .FormValue ("user_id" )
781- if actor == "" {
782- actor = c .FormValue ("screen_name" )
783- if actor == "" {
784- if userDID != nil {
785- actor = * userDID
786- } else {
787- return ReturnError (c , "No user was specified" , 195 , 403 )
729+ actorPtr , err := GetUserSpecifiedInRequest (c , userDID )
730+ if err != nil {
731+ return err
732+ }
733+ actor := * actorPtr
734+
735+ cursor := ""
736+ var cursorInt int64
737+
738+ cursorStr := c .FormValue ("cursor" )
739+ if cursorStr != "" {
740+ cursorInt , err = strconv .ParseInt (cursorStr , 10 , 64 )
741+ if err != nil || cursorInt > 1 {
742+ cursor , err = bridge .NumToTid (uint64 (cursorInt ))
743+ if err != nil {
744+ fmt .Println ("Error when converting Followers Cursor:" , err )
745+ cursor = ""
788746 }
747+ } else {
748+ cursor = ""
789749 }
790750 } else {
791- id , err := strconv .ParseInt (actor , 10 , 64 )
792- if err != nil {
793- return ReturnError (c , "Invalid ID format" , 195 , 403 )
794- }
795- actorPtr , err := bridge .TwitterIDToBlueSky (& id )
796- if err != nil {
797- return ReturnError (c , "ID not found." , 144 , fiber .StatusNotFound )
798- }
799- if actorPtr == nil {
800- return ReturnError (c , "ID not found." , 144 , fiber .StatusNotFound )
801- }
802- actor = * actorPtr
751+ cursor = ""
752+ }
753+
754+ if cursorInt == 0 {
755+ return EncodeAndSend (c , struct {
756+ Users []bridge.TwitterUser `json:"users" xml:"users"`
757+ bridge.Cursors
758+ }{
759+ Users : []bridge.TwitterUser {},
760+ Cursors : bridge.Cursors {
761+ NextCursor : 0 ,
762+ PreviousCursor : 0 , // Unimplemented. This could probably be figured out if i could figure out what the TID corrisponds to, if it corrisponds to anything at all.
763+ NextCursorStr : "0" ,
764+ PreviousCursorStr : "0" ,
765+ },
766+ })
803767 }
804768
769+ // fetch follows
770+ followers , err := blueskyapi .GetFollows (* pds , * oauthToken , cursor , actor )
771+ if err != nil {
772+ fmt .Println ("Error:" , err )
773+ return HandleBlueskyError (c , err .Error (), "app.bsky.graph.getFollows" , GetFollowingIds )
774+ }
775+
776+ var userIDs []int64
777+ for _ , user := range followers .Followers {
778+ userIDs = append (userIDs , * bridge .BlueSkyToTwitterID (user .DID ))
779+ }
780+
781+ next_cursor , err := bridge .TidToNum (followers .Cursor )
782+ if err != nil {
783+ next_cursor = 0
784+ }
785+
786+ return EncodeAndSend (c , bridge.IdsWithCursor {
787+ Ids : userIDs ,
788+ Cursors : bridge.Cursors {
789+ NextCursor : next_cursor ,
790+ PreviousCursor : 0 , // Unimplemented. This could probably be figured out if i could figure out what the TID corrisponds to, if it corrisponds to anything at all.
791+ NextCursorStr : strconv .FormatUint (next_cursor , 10 ),
792+ PreviousCursorStr : "0" ,
793+ },
794+ })
795+ }
796+
797+ func GetFollowersIds (c * fiber.Ctx ) error {
798+ // auth
799+ userDID , pds , _ , oauthToken , err := GetAuthFromReq (c )
800+ if err != nil {
801+ return MissingAuth (c , err )
802+ }
803+
804+ // lets go get our user data
805+ actorPtr , err := GetUserSpecifiedInRequest (c , userDID )
806+ if err != nil {
807+ return err
808+ }
809+ actor := * actorPtr
810+
805811 cursor := ""
806812 var cursorInt int64
807813
@@ -837,10 +843,10 @@ func GetFollowingIds(c *fiber.Ctx) error {
837843 }
838844
839845 // fetch follows
840- followers , err := blueskyapi .GetFollows (* pds , * oauthToken , cursor , actor )
846+ followers , err := blueskyapi .GetFollowers (* pds , * oauthToken , cursor , actor )
841847 if err != nil {
842848 fmt .Println ("Error:" , err )
843- return HandleBlueskyError (c , err .Error (), "app.bsky.graph.getFollows " , GetFollows )
849+ return HandleBlueskyError (c , err .Error (), "app.bsky.graph.getFollowers " , GetFollowersIds )
844850 }
845851
846852 var userIDs []int64
0 commit comments