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/blacklist/new-blacklist-for-owner.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/blacklist/new-blacklist-for-owner.ts')
-rw-r--r-- | server/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/server/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts b/server/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts new file mode 100644 index 000000000..45bc30eb2 --- /dev/null +++ b/server/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts | |||
@@ -0,0 +1,58 @@ | |||
1 | import { logger } from '@server/helpers/logger' | ||
2 | import { CONFIG } from '@server/initializers/config' | ||
3 | import { WEBSERVER } from '@server/initializers/constants' | ||
4 | import { UserModel } from '@server/models/user/user' | ||
5 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
6 | import { MUserDefault, MUserWithNotificationSetting, MVideoBlacklistVideo, UserNotificationModelForApi } from '@server/types/models' | ||
7 | import { UserNotificationType } from '@shared/models' | ||
8 | import { AbstractNotification } from '../common/abstract-notification' | ||
9 | |||
10 | export class NewBlacklistForOwner extends AbstractNotification <MVideoBlacklistVideo> { | ||
11 | private user: MUserDefault | ||
12 | |||
13 | async prepare () { | ||
14 | this.user = await UserModel.loadByVideoId(this.payload.videoId) | ||
15 | } | ||
16 | |||
17 | log () { | ||
18 | logger.info('Notifying user %s that its video %s has been blacklisted.', this.user.username, this.payload.Video.url) | ||
19 | } | ||
20 | |||
21 | getSetting (user: MUserWithNotificationSetting) { | ||
22 | return user.NotificationSetting.blacklistOnMyVideo | ||
23 | } | ||
24 | |||
25 | getTargetUsers () { | ||
26 | if (!this.user) return [] | ||
27 | |||
28 | return [ this.user ] | ||
29 | } | ||
30 | |||
31 | async createNotification (user: MUserWithNotificationSetting) { | ||
32 | const notification = await UserNotificationModel.create<UserNotificationModelForApi>({ | ||
33 | type: UserNotificationType.BLACKLIST_ON_MY_VIDEO, | ||
34 | userId: user.id, | ||
35 | videoBlacklistId: this.payload.id | ||
36 | }) | ||
37 | notification.VideoBlacklist = this.payload | ||
38 | |||
39 | return notification | ||
40 | } | ||
41 | |||
42 | createEmail (to: string) { | ||
43 | const videoName = this.payload.Video.name | ||
44 | const videoUrl = WEBSERVER.URL + this.payload.Video.getWatchStaticPath() | ||
45 | |||
46 | const reasonString = this.payload.reason ? ` for the following reason: ${this.payload.reason}` : '' | ||
47 | const blockedString = `Your video ${videoName} (${videoUrl} on ${CONFIG.INSTANCE.NAME} has been blacklisted${reasonString}.` | ||
48 | |||
49 | return { | ||
50 | to, | ||
51 | subject: `Video ${videoName} blacklisted`, | ||
52 | text: blockedString, | ||
53 | locals: { | ||
54 | title: 'Your video was blacklisted' | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | } | ||