-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmoderation.go
272 lines (230 loc) · 8.75 KB
/
moderation.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package commentapi
import (
"net/http"
"time"
"github.com/OdyseeTeam/commentron/validator"
"github.com/lbryio/lbry.go/v2/extras/api"
"github.com/lbryio/lbry.go/v2/extras/errors"
v "github.com/lbryio/ozzo-validation"
)
// BlockArgs Arguments to block identities from commenting for both publisher and moderators
type BlockArgs struct {
ModAuthorization
//Offender being blocked
BlockedChannelID string `json:"blocked_channel_id"`
BlockedChannelName string `json:"blocked_channel_name"`
// ID of comment to remove as part of this block
OffendingCommentID string `json:"offending_comment_id"`
// Blocks identity from comment universally, requires Admin rights on commentron instance
BlockAll bool `json:"block_all"`
// Measured in seconds for the amount of time a channel is blocked for.
TimeOut uint64 `json:"time_out"`
// If true will delete all comments of the offender, requires Admin rights on commentron for universal delete
DeleteAll bool `json:"delete_all"`
}
// Validate validates the data in the list args
func (b BlockArgs) Validate() api.StatusError {
err := v.ValidateStruct(&b,
v.Field(&b.BlockedChannelID, validator.ClaimID, v.Required),
v.Field(&b.BlockedChannelName, v.Required),
v.Field(&b.ModChannelID, validator.ClaimID, v.Required),
v.Field(&b.ModChannelName, v.Required),
)
if err != nil {
return api.StatusError{Err: errors.Err(err), Status: http.StatusBadRequest}
}
return api.StatusError{}
}
// BlockResponse for the moderation.Block rpc call
type BlockResponse struct {
DeletedCommentIDs []string `json:"deleted_comment_ids"`
BannedChannelID string `json:"banned_channel_id"`
AllBlocked bool `json:"all_blocked"`
//Publisher banned from if not universally banned
BannedFrom *string `json:"banned_from"`
}
// AmIArgs Arguments to check whether a user is a moderator or not
type AmIArgs struct {
Authorization
}
// AmIResponse for the moderation.AmI rpc call
type AmIResponse struct {
ChannelName string `json:"channel_name"`
ChannelID string `json:"channel_id"`
Type string `json:"type"`
AuthorizedChannels map[string]string `json:"authorized_channels"`
}
// UnBlockArgs Arguments to un-block identities from commenting for both publisher and moderators
type UnBlockArgs struct {
ModAuthorization
//Offender being unblocked
UnBlockedChannelID string `json:"un_blocked_channel_id"`
UnBlockedChannelName string `json:"un_blocked_channel_name"`
// Unblocks identity from commenting universally, requires Admin rights on commentron instance
GlobalUnBlock bool `json:"global_un_block"`
}
// UnBlockResponse for the moderation.UnBlock rpc call
type UnBlockResponse struct {
UnBlockedChannelID string `json:"un_blocked_channel_id"`
GlobalUnBlock bool `json:"global_un_block"`
//Publisher ban removed from if not universally unblocked
UnBlockedFrom *string `json:"un_blocked_from"`
}
// BlockedListArgs Arguments to block identities from commenting for both publisher and moderators
type BlockedListArgs struct {
ModAuthorization
}
// BlockedListResponse for the moderation.Block rpc call
type BlockedListResponse struct {
BlockedChannels []BlockedChannel `json:"blocked_channels"`
DelegatedBlockedChannels []BlockedChannel `json:"delegated_blocked_channels"`
GloballyBlockedChannels []BlockedChannel `json:"globally_blocked_channels"`
}
// BlockedChannel contains information about the blockee blocked by the creator
type BlockedChannel struct {
BlockedChannelID string `json:"blocked_channel_id"`
BlockedChannelName string `json:"blocked_channel_name"`
//In cases of moderation delegation this could be "other than" the creator
BlockedByChannelID string `json:"blocked_by_channel_id"`
BlockedByChannelName string `json:"blocked_by_channel_name"`
BlockedAt time.Time `json:"blocked_at"`
BlockedFor time.Duration `json:"banned_for,omitempty"`
BlcokRemaining time.Duration `json:"ban_remaining"`
}
// AddDelegateArgs Arguments to delagate moderation to another channel for your channel.
type AddDelegateArgs struct {
Authorization
//This is for backwards compatibility, Authorization parameters should be used, not these!
CreatorChannelID string `json:"creator_channel_id"`
CreatorChannelName string `json:"creator_channel_name"`
//Who is being delegated authority?
ModChannelID string `json:"mod_channel_id"`
ModChannelName string `json:"mod_channel_name"`
}
// Validate validates the data in the AddDelegate args
func (ad *AddDelegateArgs) Validate() api.StatusError {
if ad.CreatorChannelID != "" {
ad.ChannelID = ad.CreatorChannelID
}
if ad.CreatorChannelName != "" {
ad.ChannelName = ad.CreatorChannelName
}
err := v.ValidateStruct(ad,
v.Field(&ad.ChannelID, validator.ClaimID, v.Required),
v.Field(&ad.ChannelName, v.Required),
)
if err != nil {
return api.StatusError{Err: errors.Err(err), Status: http.StatusBadRequest}
}
return api.StatusError{}
}
// RemoveDelegateArgs Arguments to remove a delegated moderator.
type RemoveDelegateArgs struct {
Authorization
//This is for backwards compatibility, Authorization parameters should be used, not these!
CreatorChannelID string `json:"creator_channel_id"`
CreatorChannelName string `json:"creator_channel_name"`
//Who is being removed from delegated authority?
ModChannelID string `json:"mod_channel_id"`
ModChannelName string `json:"mod_channel_name"`
}
// Validate validates the data in the RemoveDelegate args
func (rd *RemoveDelegateArgs) Validate() api.StatusError {
if rd.CreatorChannelID != "" {
rd.ChannelID = rd.CreatorChannelID
}
if rd.CreatorChannelName != "" {
rd.ChannelName = rd.CreatorChannelName
}
err := v.ValidateStruct(rd,
v.Field(&rd.ChannelID, validator.ClaimID, v.Required),
v.Field(&rd.ChannelName, v.Required),
)
if err != nil {
return api.StatusError{Err: errors.Err(err), Status: http.StatusBadRequest}
}
return api.StatusError{}
}
// ListDelegatesArgs Arguments to list delegates
type ListDelegatesArgs struct {
Authorization
CreatorChannelID string `json:"creator_channel_id"`
CreatorChannelName string `json:"creator_channel_name"`
}
// Validate validates the data in the ListDelegates args
func (ld *ListDelegatesArgs) Validate() api.StatusError {
if ld.CreatorChannelID != "" {
ld.ChannelID = ld.CreatorChannelID
}
if ld.CreatorChannelName != "" {
ld.ChannelName = ld.CreatorChannelName
}
err := v.ValidateStruct(ld,
v.Field(&ld.ChannelID, validator.ClaimID, v.Required),
v.Field(&ld.ChannelName, v.Required),
)
if err != nil {
return api.StatusError{Err: errors.Err(err), Status: http.StatusBadRequest}
}
return api.StatusError{}
}
// ListDelegateResponse response for modifying the delegates
type ListDelegateResponse struct {
Delegates []Delegate
}
// Delegate a particular channel thats delegated moderation capabilities
type Delegate struct {
ChannelID string `json:"channel_id"`
ChannelName string `json:"channel_name"`
}
// ActOnClassificationArgs Arguments to confirm or ignore a comment's classifications
type ActOnClassificationArgs struct {
// CommentID is the ID of the comment to act on
CommentID string `json:"comment_id"`
// Confirm is true if the classification should be confirmed, false if it should be ignored (default)
Confirm bool `json:"confirm"`
// DoDelete is true if the comment should be deleted, false if it should be left alone (default)
DoDelete bool `json:"do_delete"`
}
// Validate validates the data in the ActOnClassificationArgs
func (a ActOnClassificationArgs) Validate() api.StatusError {
err := v.ValidateStruct(&a,
v.Field(&a.CommentID, v.Required),
)
if err != nil {
return api.StatusError{Err: errors.Err(err), Status: http.StatusBadRequest}
}
return api.StatusError{}
}
// ActOnClassificationResponse response for moderation.ActOnClassification
type ActOnClassificationResponse struct {
Status string `json:"status"`
}
// AdminAlgoCallbacksArgs Arguments to modify the algo_callbacks table
type AdminAlgoCallbacksArgs struct {
ChannelID string `json:"channel_id"`
WatcherID uint `json:"watcher_id"`
Add bool `json:"add"`
}
// InternalWatcherID is the ID of the internal watcher
const InternalWatcherID = 0
// Validate validates the data in the AdminAlgoCallbacksArgs
func (a AdminAlgoCallbacksArgs) Validate() api.StatusError {
err := v.ValidateStruct(&a,
v.Field(&a.ChannelID, v.Required),
)
if err != nil {
return api.StatusError{Err: errors.Err(err), Status: http.StatusBadRequest}
}
if a.WatcherID != InternalWatcherID {
return api.StatusError{
Err: errors.Err("user-defined watchers are not supported"),
Status: http.StatusBadRequest,
}
}
return api.StatusError{}
}
// AdminAlgoCallbacksResponse response for moderation.AdminAlgoCallbacks
type AdminAlgoCallbacksResponse struct {
Status string `json:"status"`
}