go-mastodon/notification.go

55 lines
1.5 KiB
Go
Raw Normal View History

2017-04-14 17:16:48 +02:00
package mastodon
import (
"context"
2017-04-14 17:16:48 +02:00
"fmt"
"net/http"
2019-05-16 01:59:33 +02:00
"net/url"
2017-04-14 17:16:48 +02:00
"time"
)
// Notification hold information for mastodon notification.
type Notification struct {
ID ID `json:"id"`
2017-04-14 17:16:48 +02:00
Type string `json:"type"`
CreatedAt time.Time `json:"created_at"`
Account Account `json:"account"`
Status *Status `json:"status"`
}
// GetNotifications return notifications.
2017-05-06 16:03:19 +02:00
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error) {
2017-04-14 17:16:48 +02:00
var notifications []*Notification
2017-05-06 16:03:19 +02:00
err := c.doAPI(ctx, http.MethodGet, "/api/v1/notifications", nil, &notifications, pg)
2017-04-14 17:16:48 +02:00
if err != nil {
2017-05-06 16:03:19 +02:00
return nil, err
2017-04-14 17:16:48 +02:00
}
2017-05-06 16:03:19 +02:00
return notifications, nil
2017-04-14 17:16:48 +02:00
}
2017-04-20 14:20:40 +02:00
// GetNotification return notification.
func (c *Client) GetNotification(ctx context.Context, id ID) (*Notification, error) {
2017-04-14 17:16:48 +02:00
var notification Notification
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/notifications/%v", id), nil, &notification, nil)
2017-04-14 17:16:48 +02:00
if err != nil {
return nil, err
}
return &notification, nil
}
2019-05-16 01:59:33 +02:00
// DismissNotification deletes a single notification.
func (c *Client) DismissNotification(ctx context.Context, id ID) error {
params := url.Values{}
params.Add("id", string(id))
err := c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/dismiss", params, nil, nil)
if err != nil {
return err
}
return nil
}
2017-04-14 17:16:48 +02:00
// ClearNotifications clear notifications.
func (c *Client) ClearNotifications(ctx context.Context) error {
2017-05-06 16:03:19 +02:00
return c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/clear", nil, nil, nil)
2017-04-14 17:16:48 +02:00
}