diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-30 16:51:27 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-02 10:39:51 +0200 |
commit | d26836cd95e981d636006652927773c7943e77ce (patch) | |
tree | 934a4a835bfddbf1c2c7da98d84ebd7623d60d49 /server/lib/notifier/shared/abuse/abstract-new-abuse-message.ts | |
parent | 2bee9db56ade2b3b1bb0efa8716840d87efdb93f (diff) | |
download | PeerTube-d26836cd95e981d636006652927773c7943e77ce.tar.gz PeerTube-d26836cd95e981d636006652927773c7943e77ce.tar.zst PeerTube-d26836cd95e981d636006652927773c7943e77ce.zip |
Refactor notifier
Diffstat (limited to 'server/lib/notifier/shared/abuse/abstract-new-abuse-message.ts')
-rw-r--r-- | server/lib/notifier/shared/abuse/abstract-new-abuse-message.ts | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/server/lib/notifier/shared/abuse/abstract-new-abuse-message.ts b/server/lib/notifier/shared/abuse/abstract-new-abuse-message.ts new file mode 100644 index 000000000..1425c38ec --- /dev/null +++ b/server/lib/notifier/shared/abuse/abstract-new-abuse-message.ts | |||
@@ -0,0 +1,67 @@ | |||
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 | |||
8 | export type NewAbuseMessagePayload = { | ||
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 = { | ||
42 | text, | ||
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 | } | ||