aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/emailer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r--server/lib/emailer.ts63
1 files changed, 41 insertions, 22 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 10e7d0479..bd3d4f252 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -2,17 +2,20 @@ import { createTransport, Transporter } from 'nodemailer'
2import { isTestInstance } from '../helpers/core-utils' 2import { isTestInstance } from '../helpers/core-utils'
3import { bunyanLogger, logger } from '../helpers/logger' 3import { bunyanLogger, logger } from '../helpers/logger'
4import { CONFIG } from '../initializers/config' 4import { CONFIG } from '../initializers/config'
5import { UserModel } from '../models/account/user'
6import { VideoModel } from '../models/video/video'
7import { JobQueue } from './job-queue' 5import { JobQueue } from './job-queue'
8import { EmailPayload } from './job-queue/handlers/email' 6import { EmailPayload } from './job-queue/handlers/email'
9import { readFileSync } from 'fs-extra' 7import { readFileSync } from 'fs-extra'
10import { VideoCommentModel } from '../models/video/video-comment'
11import { VideoAbuseModel } from '../models/video/video-abuse'
12import { VideoBlacklistModel } from '../models/video/video-blacklist'
13import { VideoImportModel } from '../models/video/video-import'
14import { ActorFollowModel } from '../models/activitypub/actor-follow'
15import { WEBSERVER } from '../initializers/constants' 8import { WEBSERVER } from '../initializers/constants'
9import {
10 MCommentOwnerVideo,
11 MVideo,
12 MVideoAbuseVideo,
13 MVideoAccountLight,
14 MVideoBlacklistLightVideo,
15 MVideoBlacklistVideo
16} from '../typings/models/video'
17import { MActorFollowActors, MActorFollowFull, MUser } from '../typings/models'
18import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import'
16 19
17type SendEmailOptions = { 20type SendEmailOptions = {
18 to: string[] 21 to: string[]
@@ -90,7 +93,7 @@ class Emailer {
90 } 93 }
91 } 94 }
92 95
93 addNewVideoFromSubscriberNotification (to: string[], video: VideoModel) { 96 addNewVideoFromSubscriberNotification (to: string[], video: MVideoAccountLight) {
94 const channelName = video.VideoChannel.getDisplayName() 97 const channelName = video.VideoChannel.getDisplayName()
95 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() 98 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
96 99
@@ -111,7 +114,7 @@ class Emailer {
111 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 114 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
112 } 115 }
113 116
114 addNewFollowNotification (to: string[], actorFollow: ActorFollowModel, followType: 'account' | 'channel') { 117 addNewFollowNotification (to: string[], actorFollow: MActorFollowFull, followType: 'account' | 'channel') {
115 const followerName = actorFollow.ActorFollower.Account.getDisplayName() 118 const followerName = actorFollow.ActorFollower.Account.getDisplayName()
116 const followingName = (actorFollow.ActorFollowing.VideoChannel || actorFollow.ActorFollowing.Account).getDisplayName() 119 const followingName = (actorFollow.ActorFollowing.VideoChannel || actorFollow.ActorFollowing.Account).getDisplayName()
117 120
@@ -130,7 +133,7 @@ class Emailer {
130 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 133 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
131 } 134 }
132 135
133 addNewInstanceFollowerNotification (to: string[], actorFollow: ActorFollowModel) { 136 addNewInstanceFollowerNotification (to: string[], actorFollow: MActorFollowActors) {
134 const awaitingApproval = actorFollow.state === 'pending' ? ' awaiting manual approval.' : '' 137 const awaitingApproval = actorFollow.state === 'pending' ? ' awaiting manual approval.' : ''
135 138
136 const text = `Hi dear admin,\n\n` + 139 const text = `Hi dear admin,\n\n` +
@@ -148,7 +151,23 @@ class Emailer {
148 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 151 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
149 } 152 }
150 153
151 myVideoPublishedNotification (to: string[], video: VideoModel) { 154 addAutoInstanceFollowingNotification (to: string[], actorFollow: MActorFollowActors) {
155 const text = `Hi dear admin,\n\n` +
156 `Your instance automatically followed a new instance: ${actorFollow.ActorFollowing.url}` +
157 `\n\n` +
158 `Cheers,\n` +
159 `${CONFIG.EMAIL.BODY.SIGNATURE}`
160
161 const emailPayload: EmailPayload = {
162 to,
163 subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'Auto instance following',
164 text
165 }
166
167 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
168 }
169
170 myVideoPublishedNotification (to: string[], video: MVideo) {
152 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() 171 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
153 172
154 const text = `Hi dear user,\n\n` + 173 const text = `Hi dear user,\n\n` +
@@ -168,7 +187,7 @@ class Emailer {
168 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 187 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
169 } 188 }
170 189
171 myVideoImportSuccessNotification (to: string[], videoImport: VideoImportModel) { 190 myVideoImportSuccessNotification (to: string[], videoImport: MVideoImportVideo) {
172 const videoUrl = WEBSERVER.URL + videoImport.Video.getWatchStaticPath() 191 const videoUrl = WEBSERVER.URL + videoImport.Video.getWatchStaticPath()
173 192
174 const text = `Hi dear user,\n\n` + 193 const text = `Hi dear user,\n\n` +
@@ -188,7 +207,7 @@ class Emailer {
188 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 207 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
189 } 208 }
190 209
191 myVideoImportErrorNotification (to: string[], videoImport: VideoImportModel) { 210 myVideoImportErrorNotification (to: string[], videoImport: MVideoImport) {
192 const importUrl = WEBSERVER.URL + '/my-account/video-imports' 211 const importUrl = WEBSERVER.URL + '/my-account/video-imports'
193 212
194 const text = `Hi dear user,\n\n` + 213 const text = `Hi dear user,\n\n` +
@@ -208,7 +227,7 @@ class Emailer {
208 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 227 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
209 } 228 }
210 229
211 addNewCommentOnMyVideoNotification (to: string[], comment: VideoCommentModel) { 230 addNewCommentOnMyVideoNotification (to: string[], comment: MCommentOwnerVideo) {
212 const accountName = comment.Account.getDisplayName() 231 const accountName = comment.Account.getDisplayName()
213 const video = comment.Video 232 const video = comment.Video
214 const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() 233 const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath()
@@ -230,7 +249,7 @@ class Emailer {
230 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 249 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
231 } 250 }
232 251
233 addNewCommentMentionNotification (to: string[], comment: VideoCommentModel) { 252 addNewCommentMentionNotification (to: string[], comment: MCommentOwnerVideo) {
234 const accountName = comment.Account.getDisplayName() 253 const accountName = comment.Account.getDisplayName()
235 const video = comment.Video 254 const video = comment.Video
236 const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() 255 const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath()
@@ -252,7 +271,7 @@ class Emailer {
252 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 271 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
253 } 272 }
254 273
255 addVideoAbuseModeratorsNotification (to: string[], videoAbuse: VideoAbuseModel) { 274 addVideoAbuseModeratorsNotification (to: string[], videoAbuse: MVideoAbuseVideo) {
256 const videoUrl = WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() 275 const videoUrl = WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath()
257 276
258 const text = `Hi,\n\n` + 277 const text = `Hi,\n\n` +
@@ -269,9 +288,9 @@ class Emailer {
269 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 288 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
270 } 289 }
271 290
272 addVideoAutoBlacklistModeratorsNotification (to: string[], video: VideoModel) { 291 addVideoAutoBlacklistModeratorsNotification (to: string[], videoBlacklist: MVideoBlacklistLightVideo) {
273 const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' 292 const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list'
274 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() 293 const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath()
275 294
276 const text = `Hi,\n\n` + 295 const text = `Hi,\n\n` +
277 `A recently added video was auto-blacklisted and requires moderator review before publishing.` + 296 `A recently added video was auto-blacklisted and requires moderator review before publishing.` +
@@ -292,7 +311,7 @@ class Emailer {
292 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 311 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
293 } 312 }
294 313
295 addNewUserRegistrationNotification (to: string[], user: UserModel) { 314 addNewUserRegistrationNotification (to: string[], user: MUser) {
296 const text = `Hi,\n\n` + 315 const text = `Hi,\n\n` +
297 `User ${user.username} just registered on ${WEBSERVER.HOST} PeerTube instance.\n\n` + 316 `User ${user.username} just registered on ${WEBSERVER.HOST} PeerTube instance.\n\n` +
298 `Cheers,\n` + 317 `Cheers,\n` +
@@ -307,7 +326,7 @@ class Emailer {
307 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 326 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
308 } 327 }
309 328
310 addVideoBlacklistNotification (to: string[], videoBlacklist: VideoBlacklistModel) { 329 addVideoBlacklistNotification (to: string[], videoBlacklist: MVideoBlacklistVideo) {
311 const videoName = videoBlacklist.Video.name 330 const videoName = videoBlacklist.Video.name
312 const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() 331 const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath()
313 332
@@ -329,7 +348,7 @@ class Emailer {
329 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 348 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
330 } 349 }
331 350
332 addVideoUnblacklistNotification (to: string[], video: VideoModel) { 351 addVideoUnblacklistNotification (to: string[], video: MVideo) {
333 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() 352 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
334 353
335 const text = 'Hi,\n\n' + 354 const text = 'Hi,\n\n' +
@@ -381,7 +400,7 @@ class Emailer {
381 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 400 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
382 } 401 }
383 402
384 addUserBlockJob (user: UserModel, blocked: boolean, reason?: string) { 403 addUserBlockJob (user: MUser, blocked: boolean, reason?: string) {
385 const reasonString = reason ? ` for the following reason: ${reason}` : '' 404 const reasonString = reason ? ` for the following reason: ${reason}` : ''
386 const blockedWord = blocked ? 'blocked' : 'unblocked' 405 const blockedWord = blocked ? 'blocked' : 'unblocked'
387 const blockedString = `Your account ${user.username} on ${WEBSERVER.HOST} has been ${blockedWord}${reasonString}.` 406 const blockedString = `Your account ${user.username} on ${WEBSERVER.HOST} has been ${blockedWord}${reasonString}.`