2017-04-14 17:16:48 +02:00
|
|
|
package mastodon
|
|
|
|
|
|
|
|
import (
|
2017-04-17 04:10:29 +02:00
|
|
|
"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 {
|
2017-10-25 06:47:36 +02:00
|
|
|
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, ¬ifications, 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.
|
2017-10-25 07:35:34 +02:00
|
|
|
func (c *Client) GetNotification(ctx context.Context, id ID) (*Notification, error) {
|
2017-04-14 17:16:48 +02:00
|
|
|
var notification Notification
|
2017-10-25 07:35:34 +02:00
|
|
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/notifications/%v", id), nil, ¬ification, nil)
|
2017-04-14 17:16:48 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ¬ification, 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.
|
2017-04-17 04:10:29 +02:00
|
|
|
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
|
|
|
}
|