-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_live_activity.go
54 lines (46 loc) · 1.15 KB
/
push_live_activity.go
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
package jpushclient
import "encoding/json"
type LiveActivity struct {
Event string `json:"event"`
ContentState map[string]any `json:"content-state"`
Alert Alert `json:"alert,omitempty"`
BadgeAddNum int `json:"dismissal-date,omitempty"`
}
type Alert struct {
Title string `json:"title,omitempty"`
Body string `json:"body,omitempty"`
Sound string `json:"sound,omitempty"`
}
func (a *LiveActivity) SetEvent(c string) *LiveActivity {
a.Event = c
return a
}
func (a *LiveActivity) SetBadgeAddNum(b int) *LiveActivity {
a.BadgeAddNum = b
return a
}
func (a *LiveActivity) AddContentState(key string, value any) *LiveActivity {
if a.ContentState == nil {
a.ContentState = make(map[string]any)
}
a.ContentState[key] = value
return a
}
func (a *LiveActivity) SetAlert(alert Alert) *LiveActivity {
a.Alert = alert
return a
}
func (a *LiveActivity) ToJson() (string, error) {
content, err := json.Marshal(a)
if err != nil {
return "", err
}
return string(content), nil
}
func (a *LiveActivity) ToBytes() ([]byte, error) {
content, err := json.Marshal(a)
if err != nil {
return nil, err
}
return content, nil
}