]>
Commit | Line | Data |
---|---|---|
d26836cd C |
1 | import { logger } from '@server/helpers/logger' |
2 | import { WEBSERVER } from '@server/initializers/constants' | |
3 | import { getAbuseTargetUrl } from '@server/lib/activitypub/url' | |
4 | import { UserModel } from '@server/models/user/user' | |
5 | import { UserNotificationModel } from '@server/models/user/user-notification' | |
6 | import { MAbuseFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models' | |
7 | import { AbuseState, UserNotificationType } from '@shared/models' | |
8 | import { AbstractNotification } from '../common/abstract-notification' | |
9 | ||
10 | export class AbuseStateChangeForReporter extends AbstractNotification <MAbuseFull> { | |
11 | ||
12 | private user: MUserDefault | |
13 | ||
14 | async prepare () { | |
15 | const reporter = this.abuse.ReporterAccount | |
16 | if (reporter.isOwned() !== true) return | |
17 | ||
18 | this.user = await UserModel.loadByAccountActorId(this.abuse.ReporterAccount.actorId) | |
19 | } | |
20 | ||
21 | log () { | |
22 | logger.info('Notifying reporter of abuse % of state change.', getAbuseTargetUrl(this.abuse)) | |
23 | } | |
24 | ||
25 | getSetting (user: MUserWithNotificationSetting) { | |
26 | return user.NotificationSetting.abuseStateChange | |
27 | } | |
28 | ||
29 | getTargetUsers () { | |
30 | if (!this.user) return [] | |
31 | ||
32 | return [ this.user ] | |
33 | } | |
34 | ||
35 | async createNotification (user: MUserWithNotificationSetting) { | |
36 | const notification = await UserNotificationModel.create<UserNotificationModelForApi>({ | |
37 | type: UserNotificationType.ABUSE_STATE_CHANGE, | |
38 | userId: user.id, | |
39 | abuseId: this.abuse.id | |
40 | }) | |
41 | notification.Abuse = this.abuse | |
42 | ||
43 | return notification | |
44 | } | |
45 | ||
46 | createEmail (to: string) { | |
47 | const text = this.abuse.state === AbuseState.ACCEPTED | |
48 | ? 'Report #' + this.abuse.id + ' has been accepted' | |
49 | : 'Report #' + this.abuse.id + ' has been rejected' | |
50 | ||
51 | const abuseUrl = WEBSERVER.URL + '/my-account/abuses?search=%23' + this.abuse.id | |
52 | ||
53 | const action = { | |
3329325a | 54 | text: 'View report #' + this.abuse.id, |
d26836cd C |
55 | url: abuseUrl |
56 | } | |
57 | ||
58 | return { | |
59 | template: 'abuse-state-change', | |
60 | to, | |
61 | subject: text, | |
62 | locals: { | |
63 | action, | |
64 | abuseId: this.abuse.id, | |
65 | abuseUrl, | |
66 | isAccepted: this.abuse.state === AbuseState.ACCEPTED | |
67 | } | |
68 | } | |
69 | } | |
70 | ||
71 | private get abuse () { | |
72 | return this.payload | |
73 | } | |
74 | } |