]>
Commit | Line | Data |
---|---|---|
d26836cd C |
1 | import { WEBSERVER } from '@server/initializers/constants' |
2 | import { AccountModel } from '@server/models/account/account' | |
3 | import { UserNotificationModel } from '@server/models/user/user-notification' | |
4 | import { MAbuseFull, MAbuseMessage, MAccountDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models' | |
5 | import { UserNotificationType } from '@shared/models' | |
6 | import { AbstractNotification } from '../common/abstract-notification' | |
7 | ||
e815f566 | 8 | type NewAbuseMessagePayload = { |
d26836cd C |
9 | abuse: MAbuseFull |
10 | message: MAbuseMessage | |
11 | } | |
12 | ||
13 | export abstract class AbstractNewAbuseMessage extends AbstractNotification <NewAbuseMessagePayload> { | |
14 | protected messageAccount: MAccountDefault | |
15 | ||
16 | async loadMessageAccount () { | |
17 | this.messageAccount = await AccountModel.load(this.message.accountId) | |
18 | } | |
19 | ||
20 | getSetting (user: MUserWithNotificationSetting) { | |
21 | return user.NotificationSetting.abuseNewMessage | |
22 | } | |
23 | ||
24 | async createNotification (user: MUserWithNotificationSetting) { | |
25 | const notification = await UserNotificationModel.create<UserNotificationModelForApi>({ | |
26 | type: UserNotificationType.ABUSE_NEW_MESSAGE, | |
27 | userId: user.id, | |
28 | abuseId: this.abuse.id | |
29 | }) | |
30 | notification.Abuse = this.abuse | |
31 | ||
32 | return notification | |
33 | } | |
34 | ||
35 | protected createEmailFor (to: string, target: 'moderator' | 'reporter') { | |
36 | const text = 'New message on report #' + this.abuse.id | |
37 | const abuseUrl = target === 'moderator' | |
38 | ? WEBSERVER.URL + '/admin/moderation/abuses/list?search=%23' + this.abuse.id | |
39 | : WEBSERVER.URL + '/my-account/abuses?search=%23' + this.abuse.id | |
40 | ||
41 | const action = { | |
3329325a | 42 | text: 'View report #' + this.abuse.id, |
d26836cd C |
43 | url: abuseUrl |
44 | } | |
45 | ||
46 | return { | |
47 | template: 'abuse-new-message', | |
48 | to, | |
49 | subject: text, | |
50 | locals: { | |
51 | abuseId: this.abuse.id, | |
52 | abuseUrl: action.url, | |
53 | messageAccountName: this.messageAccount.getDisplayName(), | |
54 | messageText: this.message.message, | |
55 | action | |
56 | } | |
57 | } | |
58 | } | |
59 | ||
60 | protected get abuse () { | |
61 | return this.payload.abuse | |
62 | } | |
63 | ||
64 | protected get message () { | |
65 | return this.payload.message | |
66 | } | |
67 | } |