snappy/notes.go

35 lines
605 B
Go
Raw Permalink Normal View History

2023-06-01 00:13:39 +00:00
package sn
import (
"encoding/json"
"fmt"
)
2023-06-01 01:39:07 +00:00
// Check for new notifications
func CheckNotifications() (bool, error) {
2023-06-01 00:13:39 +00:00
body := GraphQLPayload{
Query: `
{
hasNewNotes
}`,
}
resp, err := MakeStackerNewsRequest(body)
if err != nil {
return false, err
}
defer resp.Body.Close()
var respBody HasNewNotesResponse
err = json.NewDecoder(resp.Body).Decode(&respBody)
if err != nil {
err = fmt.Errorf("error decoding SN hasNewNotes: %w", err)
return false, err
}
err = CheckForErrors(respBody.Errors)
if err != nil {
return false, err
}
return respBody.Data.HasNewNotes, nil
}