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"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Notification hold information for mastodon notification.
|
|
|
|
type Notification struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
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-12 03:25:15 +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-04-17 04:10:29 +02:00
|
|
|
func (c *Client) GetNotification(ctx context.Context, id int64) (*Notification, error) {
|
2017-04-14 17:16:48 +02:00
|
|
|
var notification Notification
|
2017-05-12 03:25:15 +02:00
|
|
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("api/v1/notifications/%d", id), nil, ¬ification, nil)
|
2017-04-14 17:16:48 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ¬ification, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearNotifications clear notifications.
|
2017-04-17 04:10:29 +02:00
|
|
|
func (c *Client) ClearNotifications(ctx context.Context) error {
|
2017-05-12 03:25:15 +02:00
|
|
|
return c.doAPI(ctx, http.MethodPost, "api/v1/notifications/clear", nil, nil, nil)
|
2017-04-14 17:16:48 +02:00
|
|
|
}
|