aboutsummaryrefslogtreecommitdiff
path: root/internal/pushgateway/pushgateway.go
blob: 88c326eb2f9463f8c90dd4cbe4d17f635bf11de6 (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
57
58
59
60
61
62
package pushgateway

import (
	"context"
	"encoding/json"

	"github.com/matrix-org/gomatrixserverlib"
)

// A Client is how interactions with a Push Gateway is done.
type Client interface {
	// Notify sends a notification to the gateway at the given URL.
	Notify(ctx context.Context, url string, req *NotifyRequest, resp *NotifyResponse) error
}

type NotifyRequest struct {
	Notification Notification `json:"notification"` // Required
}

type NotifyResponse struct {
	// Rejected is the list of device push keys that were rejected
	// during the push. The caller should remove the push keys so they
	// are not used again.
	Rejected []string `json:"rejected"` // Required
}

type Notification struct {
	Content           json.RawMessage `json:"content,omitempty"`
	Counts            *Counts         `json:"counts,omitempty"`
	Devices           []*Device       `json:"devices"` // Required
	EventID           string          `json:"event_id,omitempty"`
	ID                string          `json:"id,omitempty"`         // Deprecated name for EventID.
	Membership        string          `json:"membership,omitempty"` // UNSPEC: required for Sytest.
	Prio              Prio            `json:"prio,omitempty"`
	RoomAlias         string          `json:"room_alias,omitempty"`
	RoomID            string          `json:"room_id,omitempty"`
	RoomName          string          `json:"room_name,omitempty"`
	Sender            string          `json:"sender,omitempty"`
	SenderDisplayName string          `json:"sender_display_name,omitempty"`
	Type              string          `json:"type,omitempty"`
	UserIsTarget      bool            `json:"user_is_target,omitempty"`
}

type Counts struct {
	MissedCalls int `json:"missed_calls,omitempty"`
	Unread      int `json:"unread"` // TODO: UNSPEC: the spec says zero must be omitted, but Sytest 61push/01message-pushed.pl requires it.
}

type Device struct {
	AppID     string                      `json:"app_id"`  // Required
	Data      map[string]interface{}      `json:"data"`    // Required. UNSPEC: Sytests require this to allow unknown keys.
	PushKey   string                      `json:"pushkey"` // Required
	PushKeyTS gomatrixserverlib.Timestamp `json:"pushkey_ts,omitempty"`
	Tweaks    map[string]interface{}      `json:"tweaks,omitempty"`
}

type Prio string

const (
	HighPrio Prio = "high"
	LowPrio  Prio = "low"
)