@@ -286,6 +286,24 @@ type TrendingTopic struct {
286286 Link string `json:"link"`
287287}
288288
289+ type Notification struct {
290+ URI string `json:"uri"`
291+ CID string `json:"cid"`
292+ Author User `json:"author"`
293+ Reason string `json:"reason"`
294+ ReasonSubject string `json:"reasonSubject"`
295+ Record PostInteractionRecord `json:"record"` // i think this is the correct object?
296+ IsRead bool `json:"isRead"`
297+ IndexedAt time.Time `json:"indexedAt"`
298+ }
299+
300+ type Notifications struct {
301+ Notifications []Notification `json:"notifications"`
302+ Cursor string `json:"cursor"`
303+ Priority bool `json:"priority"`
304+ SeenAt time.Time `json:"seenAt"`
305+ }
306+
289307var (
290308 configData * config.Config
291309)
@@ -1350,6 +1368,39 @@ func GetOthersSuggestedUsers(pds string, token string, limit int, actor string)
13501368 return users .Actors , nil
13511369}
13521370
1371+ func GetNotifications (pds string , token string , limit int , context string ) (* Notifications , error ) {
1372+ url := pds + "/xrpc/app.bsky.notification.listNotifications?limit=" + fmt .Sprintf ("%d" , limit )
1373+ if context != "" {
1374+ url = pds + "/xrpc/app.bsky.notification.listNotifications?cursor=" + context + "&limit=" + fmt .Sprintf ("%d" , limit )
1375+ }
1376+
1377+ resp , err := SendRequest (& token , http .MethodGet , url , nil )
1378+ if err != nil {
1379+ return nil , err
1380+ }
1381+ defer resp .Body .Close ()
1382+
1383+ // // Print the response body for debugging
1384+ // bodyBytes, _ := io.ReadAll(resp.Body)
1385+ // bodyString := string(bodyBytes)
1386+ // fmt.Println("Response Body:", bodyString)
1387+
1388+ if resp .StatusCode != http .StatusOK {
1389+ bodyBytes , _ := io .ReadAll (resp .Body )
1390+ bodyString := string (bodyBytes )
1391+ fmt .Println ("Response Status:" , resp .StatusCode )
1392+ fmt .Println ("Response Body:" , bodyString )
1393+ return nil , errors .New ("failed to fetch notifications" )
1394+ }
1395+
1396+ notifications := Notifications {}
1397+ if err := json .NewDecoder (resp .Body ).Decode (& notifications ); err != nil {
1398+ return nil , err
1399+ }
1400+
1401+ return & notifications , nil
1402+ }
1403+
13531404// Gets the URI components
13541405//
13551406// @param uri: The URI to ge split
0 commit comments