diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-13 16:57:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-14 09:27:18 +0200 |
commit | 26b7305a232e547709f433a6edf700bf495935d8 (patch) | |
tree | b5676090c61df72f864735bcc881d5ee256cffbd /server/lib/emailer.ts | |
parent | efc9e8450a8bbeeef9cd18e3ad6037abc0f815c3 (diff) | |
download | PeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.gz PeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.zst PeerTube-26b7305a232e547709f433a6edf700bf495935d8.zip |
Add blacklist reason field
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r-- | server/lib/emailer.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 3faeffd77..a1212878f 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts | |||
@@ -108,6 +108,55 @@ class Emailer { | |||
108 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 108 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
109 | } | 109 | } |
110 | 110 | ||
111 | async addVideoBlacklistReportJob (videoId: number, reason?: string) { | ||
112 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) | ||
113 | if (!video) throw new Error('Unknown Video id during Blacklist report.') | ||
114 | // It's not our user | ||
115 | if (video.remote === true) return | ||
116 | |||
117 | const user = await UserModel.loadById(video.VideoChannel.Account.userId) | ||
118 | |||
119 | const reasonString = reason ? ` for the following reason: ${reason}` : '' | ||
120 | const blockedString = `Your video ${video.name} on ${CONFIG.WEBSERVER.HOST} has been blacklisted${reasonString}.` | ||
121 | |||
122 | const text = 'Hi,\n\n' + | ||
123 | blockedString + | ||
124 | '\n\n' + | ||
125 | 'Cheers,\n' + | ||
126 | `PeerTube.` | ||
127 | |||
128 | const to = user.email | ||
129 | const emailPayload: EmailPayload = { | ||
130 | to: [ to ], | ||
131 | subject: `[PeerTube] Video ${video.name} blacklisted`, | ||
132 | text | ||
133 | } | ||
134 | |||
135 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | ||
136 | } | ||
137 | |||
138 | async addVideoUnblacklistReportJob (videoId: number) { | ||
139 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) | ||
140 | if (!video) throw new Error('Unknown Video id during Blacklist report.') | ||
141 | |||
142 | const user = await UserModel.loadById(video.VideoChannel.Account.userId) | ||
143 | |||
144 | const text = 'Hi,\n\n' + | ||
145 | `Your video ${video.name} on ${CONFIG.WEBSERVER.HOST} has been unblacklisted.` + | ||
146 | '\n\n' + | ||
147 | 'Cheers,\n' + | ||
148 | `PeerTube.` | ||
149 | |||
150 | const to = user.email | ||
151 | const emailPayload: EmailPayload = { | ||
152 | to: [ to ], | ||
153 | subject: `[PeerTube] Video ${video.name} unblacklisted`, | ||
154 | text | ||
155 | } | ||
156 | |||
157 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | ||
158 | } | ||
159 | |||
111 | addUserBlockJob (user: UserModel, blocked: boolean, reason?: string) { | 160 | addUserBlockJob (user: UserModel, blocked: boolean, reason?: string) { |
112 | const reasonString = reason ? ` for the following reason: ${reason}` : '' | 161 | const reasonString = reason ? ` for the following reason: ${reason}` : '' |
113 | const blockedWord = blocked ? 'blocked' : 'unblocked' | 162 | const blockedWord = blocked ? 'blocked' : 'unblocked' |