@@ -329,6 +329,37 @@ type Notifications struct {
329329 SeenAt time.Time `json:"seenAt"`
330330}
331331
332+ type ListInfo struct {
333+ URI string `json:"uri"`
334+ CID string `json:"cid"`
335+ Creator User `json:"creator"`
336+ Name string `json:"name"`
337+ // ignoring purpose
338+
339+ Description string `json:"description"`
340+ DescriptionFacets []Facet `json:"descriptionFacets"`
341+ Avatar string `json:"avatar"`
342+ ListItemCount int `json:"listItemCount"`
343+ IndexedAt time.Time `json:"indexedAt"`
344+ Viewer PostViewer `json:"viewer"`
345+ }
346+
347+ type ListItem struct {
348+ URI string `json:"uri"`
349+ Subject User `json:"subject"`
350+ }
351+
352+ type Lists struct {
353+ Lists []ListInfo `json:"lists"`
354+ Cursor string `json:"cursor"`
355+ }
356+
357+ type ListDetailed struct {
358+ List ListInfo `json:"list"`
359+ Cursor string `json:"cursor"`
360+ Items []ListItem `json:"items"`
361+ }
362+
332363var (
333364 configData * config.Config
334365)
@@ -750,6 +781,40 @@ func GetMediaTimeline(pds string, token string, context string, actor string, li
750781 return nil , & feeds
751782}
752783
784+ // https://docs.bsky.app/docs/api/app-bsky-graph-get-list
785+ func GetListTimeline (pds string , token string , context string , listURI string , limit int ) (error , * Timeline ) {
786+ apiURL := pds + "/xrpc/app.bsky.feed.getListFeed?list=" + url .QueryEscape (listURI ) + "&limit=" + fmt .Sprintf ("%d" , limit )
787+ if context != "" {
788+ apiURL = pds + "/xrpc/app.bsky.feed.getListFeed?list=" + url .QueryEscape (listURI ) + "&cursor=" + context + "&limit=" + fmt .Sprintf ("%d" , limit )
789+ }
790+
791+ resp , err := SendRequest (& token , http .MethodGet , apiURL , nil )
792+ if err != nil {
793+ return err , nil
794+ }
795+ defer resp .Body .Close ()
796+
797+ // // Print the response body for debugging
798+ // bodyBytes, _ := io.ReadAll(resp.Body)
799+ // bodyString := string(bodyBytes)
800+ // fmt.Println("Response Body:", bodyString)
801+
802+ if resp .StatusCode != http .StatusOK {
803+ bodyBytes , _ := io .ReadAll (resp .Body )
804+ bodyString := string (bodyBytes )
805+ fmt .Println ("Response Status:" , resp .StatusCode )
806+ fmt .Println ("Response Body:" , bodyString )
807+ return errors .New ("failed to fetch timeline" ), nil
808+ }
809+
810+ feeds := Timeline {}
811+ if err := json .NewDecoder (resp .Body ).Decode (& feeds ); err != nil {
812+ return err , nil
813+ }
814+
815+ return nil , & feeds
816+ }
817+
753818func GetPost (pds string , token string , uri string , depth int , parentHeight int ) (error , * ThreadRoot ) {
754819 // Example URL at://did:plc:dqibjxtqfn6hydazpetzr2w4/app.bsky.feed.post/3lchbospvbc2j
755820
@@ -1367,7 +1432,7 @@ func GetPostLikes(pds string, token string, uri string, limit int) (*Likes, erro
13671432func GetActorLikes (pds string , token string , context string , actor string , limit int ) (error , * Timeline ) {
13681433 url := fmt .Sprintf (pds + "/xrpc/app.bsky.feed.getActorLikes?limit=%d&actor=%s" , limit , actor )
13691434 if context != "" {
1370- url = fmt .Sprintf (pds + "/xrpc/app.bsky.feed.getActorLikes?limit=%d&actor=%s&context =%s" , limit , actor , context )
1435+ url = fmt .Sprintf (pds + "/xrpc/app.bsky.feed.getActorLikes?limit=%d&actor=%s&cursor =%s" , limit , actor , context )
13711436 }
13721437
13731438 resp , err := SendRequest (& token , http .MethodGet , url , nil )
@@ -1630,6 +1695,72 @@ func GetTrends(pds string, token string) (*TrendingTopics, error) {
16301695 return & trends , nil
16311696}
16321697
1698+ func GetUsersLists (pds string , token string , actor string , limit int , cursor string ) (* Lists , error ) {
1699+ url := fmt .Sprintf (pds + "/xrpc/app.bsky.graph.getLists?limit=%d&actor=%s" , limit , actor )
1700+ if cursor != "" {
1701+ url = fmt .Sprintf (pds + "/xrpc/app.bsky.graph.getLists?limit=%d&actor=%s&cursor=%s" , limit , actor , cursor )
1702+ }
1703+
1704+ resp , err := SendRequest (& token , http .MethodGet , url , nil )
1705+ if err != nil {
1706+ return nil , err
1707+ }
1708+ defer resp .Body .Close ()
1709+
1710+ // // Print the response body
1711+ // bodyBytes, _ := io.ReadAll(resp.Body)
1712+ // bodyString := string(bodyBytes)
1713+ // fmt.Println("Response Body:", bodyString)
1714+
1715+ if resp .StatusCode != http .StatusOK {
1716+ bodyBytes , _ := io .ReadAll (resp .Body )
1717+ bodyString := string (bodyBytes )
1718+ fmt .Println ("Response Status:" , resp .StatusCode )
1719+ fmt .Println ("Response Body:" , bodyString )
1720+ return nil , errors .New ("failed to fetch a user's lists" )
1721+ }
1722+
1723+ lists := Lists {}
1724+ if err := json .NewDecoder (resp .Body ).Decode (& lists ); err != nil {
1725+ return nil , err
1726+ }
1727+
1728+ return & lists , nil
1729+ }
1730+
1731+ func GetList (pds string , token string , listURI string , limit int , cursor string ) (* ListDetailed , error ) {
1732+ url := fmt .Sprintf (pds + "/xrpc/app.bsky.graph.getList?limit=%d&list=%s" , limit , listURI )
1733+ if cursor != "" {
1734+ url = fmt .Sprintf (pds + "/xrpc/app.bsky.graph.getList?limit=%d&list=%s&cursor=%s" , limit , listURI , cursor )
1735+ }
1736+
1737+ resp , err := SendRequest (& token , http .MethodGet , url , nil )
1738+ if err != nil {
1739+ return nil , err
1740+ }
1741+ defer resp .Body .Close ()
1742+
1743+ // // Print the response body
1744+ // bodyBytes, _ := io.ReadAll(resp.Body)
1745+ // bodyString := string(bodyBytes)
1746+ // fmt.Println("Response Body:", bodyString)
1747+
1748+ if resp .StatusCode != http .StatusOK {
1749+ bodyBytes , _ := io .ReadAll (resp .Body )
1750+ bodyString := string (bodyBytes )
1751+ fmt .Println ("Response Status:" , resp .StatusCode )
1752+ fmt .Println ("Response Body:" , bodyString )
1753+ return nil , errors .New ("failed to fetch a user's lists" )
1754+ }
1755+
1756+ list := ListDetailed {}
1757+ if err := json .NewDecoder (resp .Body ).Decode (& list ); err != nil {
1758+ return nil , err
1759+ }
1760+
1761+ return & list , nil
1762+ }
1763+
16331764func GetMySuggestedUsers (pds string , token string , limit int ) ([]User , error ) {
16341765 url := pds + "/xrpc/app.bsky.actor.getSuggestions?limit=" + fmt .Sprintf ("%d" , limit )
16351766
0 commit comments