@@ -25,7 +25,7 @@ type AuthRequest struct {
2525 Password string `json:"password"`
2626}
2727
28- type Author struct {
28+ type User struct {
2929 DID string `json:"did"`
3030 Handle string `json:"handle"`
3131 DisplayName string `json:"displayName"`
@@ -58,7 +58,7 @@ type PostRecord struct {
5858// Specifically for reposts
5959type PostReason struct {
6060 Type string `json:"$type"`
61- By Author `json:"by"`
61+ By User `json:"by"`
6262 IndexedAt time.Time `json:"indexedAt"`
6363}
6464
@@ -118,7 +118,7 @@ type PostViewer struct {
118118}
119119type Post struct {
120120 Subject
121- Author Author `json:"author"`
121+ Author User `json:"author"`
122122 Record PostRecord `json:"record"`
123123 // Embed Embed `json:"embed"`
124124 ReplyCount int `json:"replyCount"`
@@ -193,8 +193,8 @@ type CreateRecordResult struct {
193193
194194type RepostedBy struct {
195195 Subject
196- Cursor string `json:"cursor"`
197- RepostedBy []Author `json:"repostedBy"`
196+ Cursor string `json:"cursor"`
197+ RepostedBy []User `json:"repostedBy"`
198198}
199199type Likes struct {
200200 Subject
@@ -205,7 +205,11 @@ type Likes struct {
205205type ItemByWithDate struct {
206206 IndexedAt time.Time `json:"indexedAt"`
207207 CreatedAt time.Time `json:"createdAt"`
208- Actor Author `json:"actor"`
208+ Actor User `json:"actor"`
209+ }
210+
211+ type UserSearchResult struct {
212+ Actors []User `json:"actors"`
209213}
210214
211215func SendRequest (token * string , method string , url string , body io.Reader ) (* http.Response , error ) {
@@ -303,7 +307,7 @@ func GetUserInfo(token string, screen_name string) (*bridge.TwitterUser, error)
303307 return nil , errors .New ("failed to fetch user info" )
304308 }
305309
306- author := Author {}
310+ author := User {}
307311 if err := json .NewDecoder (resp .Body ).Decode (& author ); err != nil {
308312 return nil , err
309313 }
@@ -328,7 +332,7 @@ func GetUsersInfo(token string, items []string) ([]*bridge.TwitterUser, error) {
328332 }
329333
330334 var authors struct {
331- Profiles []Author `json:"profiles"`
335+ Profiles []User `json:"profiles"`
332336 }
333337 if err := json .NewDecoder (resp .Body ).Decode (& authors ); err != nil {
334338 return nil , err
@@ -342,7 +346,7 @@ func GetUsersInfo(token string, items []string) ([]*bridge.TwitterUser, error) {
342346 return users , nil
343347}
344348
345- func AuthorTTB (author Author ) * bridge.TwitterUser {
349+ func AuthorTTB (author User ) * bridge.TwitterUser {
346350 return & bridge.TwitterUser {
347351 ProfileSidebarFillColor : "e0ff92" ,
348352 Name : func () string {
@@ -666,6 +670,31 @@ func GetRetweetAuthors(token string, uri string, limit int) (*RepostedBy, error)
666670 return & retweetAuthors , nil
667671}
668672
669- // func UserSearch(token string, query string) (bridge.TwitterUser, error) {
673+ func UserSearch (token string , query string ) ([]User , error ) {
674+ url := "https://public.bsky.social/xrpc/app.bsky.actor.searchActors?q=" + query
675+
676+ resp , err := SendRequest (& token , http .MethodGet , url , nil )
677+ if err != nil {
678+ return nil , err
679+ }
680+ defer resp .Body .Close ()
670681
671- // }
682+ // // Print the response body
683+ // bodyBytes, _ := io.ReadAll(resp.Body)
684+ // bodyString := string(bodyBytes)
685+ // fmt.Println("Response Body:", bodyString)
686+
687+ if resp .StatusCode != http .StatusOK {
688+ bodyBytes , _ := io .ReadAll (resp .Body )
689+ bodyString := string (bodyBytes )
690+ fmt .Println ("Response Status:" , resp .StatusCode )
691+ fmt .Println ("Response Body:" , bodyString )
692+ return nil , errors .New ("failed to fetch search results" )
693+ }
694+
695+ users := UserSearchResult {}
696+ if err := json .NewDecoder (resp .Body ).Decode (& users ); err != nil {
697+ return nil , err
698+ }
699+ return users .Actors , nil
700+ }
0 commit comments