aboutsummaryrefslogtreecommitdiff
path: root/mastodon/notification.go
blob: d793905be8d27080f3b2b6dacf3c47fb2dfd0c00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package mastodon

import (
	"context"
	"fmt"
	"net/http"
	"net/url"
	"time"
)

type NotificationPleroma struct {
	IsSeen bool `json:"is_seen"`
}

// Notification hold information for mastodon notification.
type Notification struct {
	ID        string               `json:"id"`
	Type      string               `json:"type"`
	CreatedAt time.Time            `json:"created_at"`
	Account   Account              `json:"account"`
	Status    *Status              `json:"status"`
	Pleroma   *NotificationPleroma `json:"pleroma"`
}

// GetNotifications return notifications.
func (c *Client) GetNotifications(ctx context.Context, pg *Pagination) ([]*Notification, error) {
	var notifications []*Notification
	err := c.doAPI(ctx, http.MethodGet, "/api/v1/notifications", nil, &notifications, pg)
	if err != nil {
		return nil, err
	}
	return notifications, nil
}

// GetNotification return notification.
func (c *Client) GetNotification(ctx context.Context, id string) (*Notification, error) {
	var notification Notification
	err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/notifications/%v", id), nil, &notification, nil)
	if err != nil {
		return nil, err
	}
	return &notification, nil
}

// ClearNotifications clear notifications.
func (c *Client) ClearNotifications(ctx context.Context) error {
	return c.doAPI(ctx, http.MethodPost, "/api/v1/notifications/clear", nil, nil, nil)
}

// ReadNotifications marks notifications as read
// Currenly only works for Pleroma
func (c *Client) ReadNotifications(ctx context.Context, maxID string) error {
	params := url.Values{}
	params.Set("max_id", maxID)
	return c.doAPI(ctx, http.MethodPost, "/api/v1/pleroma/notifications/read", params, nil, nil)
}