/
form.ts
440 lines (411 loc) · 10.8 KB
/
form.ts
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
import { Component, Prop } from 'vue-property-decorator';
import { arrayRemove } from '../../../utils/array';
import { Api } from '../../api/api.service';
import { FiresidePost } from '../../fireside/post/post-model';
import AppFormControlTextarea from '../../form-vue/control/textarea/textarea.vue';
import { BaseForm, FormOnSubmit } from '../../form-vue/form.service';
import { Game } from '../../game/game.model';
interface FormModel {
reason: string;
context: string[];
description: string;
source: string;
}
@Component({
components: {
AppFormControlTextarea,
},
})
export default class AppReportForm extends BaseForm<FormModel> implements FormOnSubmit {
@Prop(String) type!: string;
@Prop(Object) resource!: any;
warnOnDiscard = false;
// Default values, get overwritten from backend.
maxLengthDescription = 200;
maxLengthSource = 255;
get isDescriptionOptional() {
if (!this.formModel.reason) {
return true;
}
// When "other" is selected as reason, they have to provide a description.
if (this.formModel.reason === 'other') {
return false;
}
// When "other" is selected as context, they have to provide a description.
if (this.formModel.context && this.formModel.context.includes('other')) {
return false;
}
return true;
}
get reasons(): any[] {
switch (this.type) {
case 'Game':
return [
{
radioValue: 'spam',
text: this.$gettext('It is spam or unwanted commercial content'),
},
{
radioValue: 'abuse',
text: this.$gettext(
'Incorrect maturity rating for the content in the game'
),
},
{
radioValue: 'explicit',
text: this.$gettext(
'It is pornographic or contains sexually explicit material'
),
},
{
radioValue: 'stolen',
text: this.$gettext('Game does not belong to this developer'),
source: {
placeholder: this.$gettext('Tell us where this game was stolen from'),
},
},
{
radioValue: 'no-info',
text: this.$gettext(
'No information on game page (no screenshots, sparse description, placeholder page, etc.)'
),
},
{
radioValue: 'malware',
text: this.$gettext('Virus or other form of malware'),
},
{
radioValue: 'other',
text: this.$gettext('Other'),
},
];
case 'Fireside_Post': {
const reasons = [
{
radioValue: 'spam',
text: this.$gettext('It is spam or unwanted commercial content'),
},
{
radioValue: 'abuse',
text: this.$gettext('It is hate speech or contains graphic content'),
},
{
radioValue: 'explicit',
text: this.$gettext(
'It is pornographic or contains sexually explicit material'
),
},
{
radioValue: 'harassment',
text: this.$gettext('It is harassment or bullying'),
},
{
radioValue: 'stolen',
text: this.$gettext('Content in this post does not belong to the author'),
source: {
placeholder: this.$gettext(
'Tell us where content in this post was stolen from'
),
},
},
{
radioValue: 'other',
text: this.$gettext('Other'),
},
];
// For a devlog post of a game that is maturity restricted, we don't want to show the "explicit" report option.
// Those devlog posts can be explicit, and we don't want to encourage false reports.
const isAdultGamePost =
this.resource instanceof FiresidePost &&
this.resource.game instanceof Game &&
this.resource.game.tigrs_age === 3;
// However, in cases where the post may be shown outside of the game page, we won't disable reporting.
const onlyShowsOnGame =
!this.resource.post_to_user_profile && this.resource.communities.length === 0;
if (isAdultGamePost && onlyShowsOnGame) {
arrayRemove(reasons, i => i.radioValue === 'explicit');
}
return reasons;
}
case 'Comment':
case 'Forum_Topic':
case 'Forum_Post':
return [
{
radioValue: 'spam',
text: this.$gettext('It is spam or unwanted commercial content'),
},
{
radioValue: 'abuse',
text: this.$gettext('It is hate speech or contains graphic content'),
},
{
radioValue: 'explicit',
text: this.$gettext(
'It is pornographic or contains sexually explicit material'
),
},
{
radioValue: 'harassment',
text: this.$gettext('It is harassment or bullying'),
},
{
radioValue: 'other',
text: this.$gettext('Other'),
},
];
case 'Community':
return [
{
radioValue: 'spam',
text: this.$gettext(`It is spam or unwanted commercial content`),
},
{
radioValue: 'abuse',
text: this.$gettext('Encourages posting of hate speech or graphic content'),
},
{
radioValue: 'harassment',
text: this.$gettext(
`This community is used to create targeted harassment or bullying`
),
},
{
radioValue: 'no-moderation',
text: this.$gettext(
'This community is not actively moderated by its moderators'
),
},
{
radioValue: 'other',
text: this.$gettext('Other'),
},
];
case 'Fireside':
return [
{
radioValue: 'abuse',
text: this.$gettext(
'Fireside is used to show/promote hate speech or graphic content'
),
contexts: [
{
checkValue: 'fireside/title',
text: this.$gettext('Title'),
},
{
checkValue: 'fireside/chat',
text: this.$gettext('Chat messages'),
},
{
checkValue: 'fireside/audio-video',
text: this.$gettext('Audio or video stream'),
},
],
},
{
radioValue: 'explicit',
text: this.$gettext('Fireside contains explicit or sensitive material'),
contexts: [
{
checkValue: 'fireside/title',
text: this.$gettext('Title'),
},
{
checkValue: 'fireside/chat',
text: this.$gettext('Chat messages'),
},
{
checkValue: 'fireside/audio-video',
text: this.$gettext('Audio or video stream'),
},
],
},
{
radioValue: 'no-moderation',
text: this.$gettext(
"This fireside's chat is not actively moderated by its moderators"
),
},
{
radioValue: 'other',
text: this.$gettext('Other'),
},
];
case 'User':
return [
{
radioValue: 'spam',
text: this.$gettext('Spammer'),
contexts: [
{
checkValue: 'user/posts',
text: this.$gettext('Posts'),
},
{
checkValue: 'user/comments',
text: this.$gettext('Comments'),
},
{
checkValue: 'user/games',
text: this.$gettext('Games'),
},
{
checkValue: 'user/chat',
text: this.$gettext('Chat Messages'),
},
{
checkValue: 'user/bio',
text: this.$gettext('Bio'),
},
{
checkValue: 'user/website',
text: this.$gettext('Website'),
},
{
checkValue: 'other',
text: this.$gettext('Other (please describe below)'),
},
],
},
{
radioValue: 'explicit',
text: this.$gettext(
'Profile or username contains explicit or sensitive material'
),
contexts: [
{
checkValue: 'user/header',
text: this.$gettext('Header'),
},
{
checkValue: 'user/avatar',
text: this.$gettext('Avatar'),
},
{
checkValue: 'user/name',
text: this.$gettext('Username or display name'),
},
{
checkValue: 'user/posts',
text: this.$gettext('Posts'),
},
{
checkValue: 'user/comments',
text: this.$gettext('Comments'),
},
{
checkValue: 'user/chat',
text: this.$gettext('Chat Messages'),
},
{
checkValue: 'user/bio',
text: this.$gettext('Bio'),
},
{
checkValue: 'user/website',
text: this.$gettext('Website or socials'),
},
{
checkValue: 'other',
text: this.$gettext('Other (please describe below)'),
},
],
},
{
radioValue: 'harassment',
text: this.$gettext('This user is harassing or bullying others'),
contexts: [
{
checkValue: 'user/posts',
text: this.$gettext('Posts'),
},
{
checkValue: 'user/comments',
text: this.$gettext('Comments'),
},
{
checkValue: 'user/chat',
text: this.$gettext('Chat Messages'),
},
{
checkValue: 'user/bio',
text: this.$gettext('Bio'),
},
{
checkValue: 'other',
text: this.$gettext('Other (please describe below)'),
},
],
},
{
radioValue: 'impersonation',
text: this.$gettext('Impersonating'),
source: {
placeholder: this.$gettext(
'Tell us which person this user is impersonating'
),
},
},
{
radioValue: 'other',
text: this.$gettext('Other'),
},
];
}
throw new Error('Resource has no reasons defined.');
}
async mounted() {
const payload = await Api.sendRequest('/web/report');
this.maxLengthDescription = payload.maxLengthDescription;
this.maxLengthSource = payload.maxLengthSource;
}
onChangeReason() {
this.setField('context', []);
this.validateContextSelected();
}
onChangeContext() {
this.validateContextSelected();
}
private validateContextSelected() {
let hasErrors = false;
// Check that if we have contexts to choose from, at least one of them is selected.
if (this.formModel.reason) {
const reason = this.reasons.find(i => i.radioValue === this.formModel.reason);
if (!reason) {
throw new Error('Invalid reason selected.');
}
if (reason.contexts && reason.contexts.length > 0) {
if (!this.formModel.context || this.formModel.context.length === 0) {
hasErrors = true;
}
}
}
if (hasErrors) {
this.setCustomError('context');
} else {
this.clearCustomError('context');
}
}
onSubmit() {
const data = {
resourceName: this.type,
resourceId: this.resource.id,
reason: this.formModel.reason,
context: this.formModel.context as string[] | undefined,
description: this.formModel.description,
source: this.formModel.source as string | undefined,
};
// Clear out context if the current reason doesn't have a context option.
if (!data.context || !this.reasons.find(i => i.radioValue === data.reason)!.contexts) {
delete data.context;
}
// Clear out source if the current reason doesn't have a source option.
if (!data.source || !this.reasons.find(i => i.radioValue === data.reason)!.source) {
delete data.source;
}
return Api.sendRequest('/web/report/submit', data, {
allowComplexData: ['context'],
});
}
}