-
Notifications
You must be signed in to change notification settings - Fork 5
/
newsletter.go
191 lines (151 loc) · 5.06 KB
/
newsletter.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package types
import (
"bytes"
"encoding/json"
"fmt"
"go.mau.fi/util/jsontime"
waProto "github.com/amiruldev20/waSocket/binary/proto"
)
type NewsletterVerificationState string
func (nvs *NewsletterVerificationState) UnmarshalText(text []byte) error {
*nvs = NewsletterVerificationState(bytes.ToLower(text))
return nil
}
const (
NewsletterVerificationStateVerified NewsletterVerificationState = "verified"
NewsletterVerificationStateUnverified NewsletterVerificationState = "unverified"
)
type NewsletterPrivacy string
func (np *NewsletterPrivacy) UnmarshalText(text []byte) error {
*np = NewsletterPrivacy(bytes.ToLower(text))
return nil
}
const (
NewsletterPrivacyPrivate NewsletterPrivacy = "private"
NewsletterPrivacyPublic NewsletterPrivacy = "public"
)
type NewsletterReactionsMode string
const (
NewsletterReactionsModeAll NewsletterReactionsMode = "all"
NewsletterReactionsModeBasic NewsletterReactionsMode = "basic"
NewsletterReactionsModeNone NewsletterReactionsMode = "none"
NewsletterReactionsModeBlocklist NewsletterReactionsMode = "blocklist"
)
type NewsletterState string
func (ns *NewsletterState) UnmarshalText(text []byte) error {
*ns = NewsletterState(bytes.ToLower(text))
return nil
}
const (
NewsletterStateActive NewsletterState = "active"
NewsletterStateSuspended NewsletterState = "suspended"
NewsletterStateGeoSuspended NewsletterState = "geosuspended"
)
type NewsletterMuted struct {
Muted bool
}
type WrappedNewsletterState struct {
Type NewsletterState `json:"type"`
}
type NewsletterMuteState string
func (nms *NewsletterMuteState) UnmarshalText(text []byte) error {
*nms = NewsletterMuteState(bytes.ToLower(text))
return nil
}
const (
NewsletterMuteOn NewsletterMuteState = "on"
NewsletterMuteOff NewsletterMuteState = "off"
)
type NewsletterRole string
func (nr *NewsletterRole) UnmarshalText(text []byte) error {
*nr = NewsletterRole(bytes.ToLower(text))
return nil
}
const (
NewsletterRoleSubscriber NewsletterRole = "subscriber"
NewsletterRoleGuest NewsletterRole = "guest"
NewsletterRoleAdmin NewsletterRole = "admin"
NewsletterRoleOwner NewsletterRole = "owner"
)
type NewsletterMetadata struct {
ID JID `json:"id"`
State WrappedNewsletterState `json:"state"`
ThreadMeta NewsletterThreadMetadata `json:"thread_metadata"`
ViewerMeta *NewsletterViewerMetadata `json:"viewer_metadata"`
}
type NewsletterViewerMetadata struct {
Mute NewsletterMuteState `json:"mute"`
Role NewsletterRole `json:"role"`
}
type NewsletterKeyType string
const (
NewsletterKeyTypeJID NewsletterKeyType = "JID"
NewsletterKeyTypeInvite NewsletterKeyType = "INVITE"
)
type NewsletterReactionSettings struct {
Value NewsletterReactionsMode `json:"value"`
}
type NewsletterSettings struct {
ReactionCodes NewsletterReactionSettings `json:"reaction_codes"`
}
type NewsletterThreadMetadata struct {
CreationTime jsontime.UnixString `json:"creation_time"`
InviteCode string `json:"invite"`
Name NewsletterText `json:"name"`
Description NewsletterText `json:"description"`
SubscriberCount int `json:"subscribers_count,string"`
VerificationState NewsletterVerificationState `json:"verification"`
Picture *ProfilePictureInfo `json:"picture"`
Preview ProfilePictureInfo `json:"preview"`
Settings NewsletterSettings `json:"settings"`
//NewsletterMuted `json:"-"`
//PrivacyType NewsletterPrivacy `json:"-"`
//ReactionsMode NewsletterReactionsMode `json:"-"`
//State NewsletterState `json:"-"`
}
type NewsletterText struct {
Text string `json:"text"`
ID string `json:"id"`
UpdateTime jsontime.UnixMicroString `json:"update_time"`
}
type NewsletterMessage struct {
MessageServerID MessageServerID
ViewsCount int
ReactionCounts map[string]int
// This is only present when fetching messages, not in live updates
Message *waProto.Message
}
type GraphQLErrorExtensions struct {
ErrorCode int `json:"error_code"`
IsRetryable bool `json:"is_retryable"`
Severity string `json:"severity"`
}
type GraphQLError struct {
Extensions GraphQLErrorExtensions `json:"extensions"`
Message string `json:"message"`
Path []string `json:"path"`
}
func (gqle GraphQLError) Error() string {
return fmt.Sprintf("%d %s (%s)", gqle.Extensions.ErrorCode, gqle.Message, gqle.Extensions.Severity)
}
type GraphQLErrors []GraphQLError
func (gqles GraphQLErrors) Unwrap() []error {
errs := make([]error, len(gqles))
for i, gqle := range gqles {
errs[i] = gqle
}
return errs
}
func (gqles GraphQLErrors) Error() string {
if len(gqles) == 0 {
return ""
} else if len(gqles) == 1 {
return gqles[0].Error()
} else {
return fmt.Sprintf("%v (and %d other errors)", gqles[0], len(gqles)-1)
}
}
type GraphQLResponse struct {
Data json.RawMessage `json:"data"`
Errors GraphQLErrors `json:"errors"`
}