diff options
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r-- | server/lib/emailer.ts | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 10e7d0479..76349ef8f 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts | |||
@@ -2,17 +2,13 @@ import { createTransport, Transporter } from 'nodemailer' | |||
2 | import { isTestInstance } from '../helpers/core-utils' | 2 | import { isTestInstance } from '../helpers/core-utils' |
3 | import { bunyanLogger, logger } from '../helpers/logger' | 3 | import { bunyanLogger, logger } from '../helpers/logger' |
4 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
5 | import { UserModel } from '../models/account/user' | ||
6 | import { VideoModel } from '../models/video/video' | ||
7 | import { JobQueue } from './job-queue' | 5 | import { JobQueue } from './job-queue' |
8 | import { EmailPayload } from './job-queue/handlers/email' | 6 | import { EmailPayload } from './job-queue/handlers/email' |
9 | import { readFileSync } from 'fs-extra' | 7 | import { readFileSync } from 'fs-extra' |
10 | import { VideoCommentModel } from '../models/video/video-comment' | ||
11 | import { VideoAbuseModel } from '../models/video/video-abuse' | ||
12 | import { VideoBlacklistModel } from '../models/video/video-blacklist' | ||
13 | import { VideoImportModel } from '../models/video/video-import' | ||
14 | import { ActorFollowModel } from '../models/activitypub/actor-follow' | ||
15 | import { WEBSERVER } from '../initializers/constants' | 8 | import { WEBSERVER } from '../initializers/constants' |
9 | import { MCommentOwnerVideo, MVideo, MVideoAbuseVideo, MVideoAccountLight, MVideoBlacklistVideo } from '../typings/models/video' | ||
10 | import { MActorFollowActors, MActorFollowFollowingFullFollowerAccount, MUser } from '../typings/models' | ||
11 | import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import' | ||
16 | 12 | ||
17 | type SendEmailOptions = { | 13 | type SendEmailOptions = { |
18 | to: string[] | 14 | to: string[] |
@@ -90,7 +86,7 @@ class Emailer { | |||
90 | } | 86 | } |
91 | } | 87 | } |
92 | 88 | ||
93 | addNewVideoFromSubscriberNotification (to: string[], video: VideoModel) { | 89 | addNewVideoFromSubscriberNotification (to: string[], video: MVideoAccountLight) { |
94 | const channelName = video.VideoChannel.getDisplayName() | 90 | const channelName = video.VideoChannel.getDisplayName() |
95 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() | 91 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() |
96 | 92 | ||
@@ -111,7 +107,7 @@ class Emailer { | |||
111 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 107 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
112 | } | 108 | } |
113 | 109 | ||
114 | addNewFollowNotification (to: string[], actorFollow: ActorFollowModel, followType: 'account' | 'channel') { | 110 | addNewFollowNotification (to: string[], actorFollow: MActorFollowFollowingFullFollowerAccount, followType: 'account' | 'channel') { |
115 | const followerName = actorFollow.ActorFollower.Account.getDisplayName() | 111 | const followerName = actorFollow.ActorFollower.Account.getDisplayName() |
116 | const followingName = (actorFollow.ActorFollowing.VideoChannel || actorFollow.ActorFollowing.Account).getDisplayName() | 112 | const followingName = (actorFollow.ActorFollowing.VideoChannel || actorFollow.ActorFollowing.Account).getDisplayName() |
117 | 113 | ||
@@ -130,7 +126,7 @@ class Emailer { | |||
130 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 126 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
131 | } | 127 | } |
132 | 128 | ||
133 | addNewInstanceFollowerNotification (to: string[], actorFollow: ActorFollowModel) { | 129 | addNewInstanceFollowerNotification (to: string[], actorFollow: MActorFollowActors) { |
134 | const awaitingApproval = actorFollow.state === 'pending' ? ' awaiting manual approval.' : '' | 130 | const awaitingApproval = actorFollow.state === 'pending' ? ' awaiting manual approval.' : '' |
135 | 131 | ||
136 | const text = `Hi dear admin,\n\n` + | 132 | const text = `Hi dear admin,\n\n` + |
@@ -148,7 +144,7 @@ class Emailer { | |||
148 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 144 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
149 | } | 145 | } |
150 | 146 | ||
151 | myVideoPublishedNotification (to: string[], video: VideoModel) { | 147 | myVideoPublishedNotification (to: string[], video: MVideo) { |
152 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() | 148 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() |
153 | 149 | ||
154 | const text = `Hi dear user,\n\n` + | 150 | const text = `Hi dear user,\n\n` + |
@@ -168,7 +164,7 @@ class Emailer { | |||
168 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 164 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
169 | } | 165 | } |
170 | 166 | ||
171 | myVideoImportSuccessNotification (to: string[], videoImport: VideoImportModel) { | 167 | myVideoImportSuccessNotification (to: string[], videoImport: MVideoImportVideo) { |
172 | const videoUrl = WEBSERVER.URL + videoImport.Video.getWatchStaticPath() | 168 | const videoUrl = WEBSERVER.URL + videoImport.Video.getWatchStaticPath() |
173 | 169 | ||
174 | const text = `Hi dear user,\n\n` + | 170 | const text = `Hi dear user,\n\n` + |
@@ -188,7 +184,7 @@ class Emailer { | |||
188 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 184 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
189 | } | 185 | } |
190 | 186 | ||
191 | myVideoImportErrorNotification (to: string[], videoImport: VideoImportModel) { | 187 | myVideoImportErrorNotification (to: string[], videoImport: MVideoImport) { |
192 | const importUrl = WEBSERVER.URL + '/my-account/video-imports' | 188 | const importUrl = WEBSERVER.URL + '/my-account/video-imports' |
193 | 189 | ||
194 | const text = `Hi dear user,\n\n` + | 190 | const text = `Hi dear user,\n\n` + |
@@ -208,7 +204,7 @@ class Emailer { | |||
208 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 204 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
209 | } | 205 | } |
210 | 206 | ||
211 | addNewCommentOnMyVideoNotification (to: string[], comment: VideoCommentModel) { | 207 | addNewCommentOnMyVideoNotification (to: string[], comment: MCommentOwnerVideo) { |
212 | const accountName = comment.Account.getDisplayName() | 208 | const accountName = comment.Account.getDisplayName() |
213 | const video = comment.Video | 209 | const video = comment.Video |
214 | const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() | 210 | const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() |
@@ -230,7 +226,7 @@ class Emailer { | |||
230 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 226 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
231 | } | 227 | } |
232 | 228 | ||
233 | addNewCommentMentionNotification (to: string[], comment: VideoCommentModel) { | 229 | addNewCommentMentionNotification (to: string[], comment: MCommentOwnerVideo) { |
234 | const accountName = comment.Account.getDisplayName() | 230 | const accountName = comment.Account.getDisplayName() |
235 | const video = comment.Video | 231 | const video = comment.Video |
236 | const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() | 232 | const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() |
@@ -252,7 +248,7 @@ class Emailer { | |||
252 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 248 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
253 | } | 249 | } |
254 | 250 | ||
255 | addVideoAbuseModeratorsNotification (to: string[], videoAbuse: VideoAbuseModel) { | 251 | addVideoAbuseModeratorsNotification (to: string[], videoAbuse: MVideoAbuseVideo) { |
256 | const videoUrl = WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() | 252 | const videoUrl = WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() |
257 | 253 | ||
258 | const text = `Hi,\n\n` + | 254 | const text = `Hi,\n\n` + |
@@ -269,7 +265,7 @@ class Emailer { | |||
269 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 265 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
270 | } | 266 | } |
271 | 267 | ||
272 | addVideoAutoBlacklistModeratorsNotification (to: string[], video: VideoModel) { | 268 | addVideoAutoBlacklistModeratorsNotification (to: string[], video: MVideo) { |
273 | const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' | 269 | const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' |
274 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() | 270 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() |
275 | 271 | ||
@@ -292,7 +288,7 @@ class Emailer { | |||
292 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 288 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
293 | } | 289 | } |
294 | 290 | ||
295 | addNewUserRegistrationNotification (to: string[], user: UserModel) { | 291 | addNewUserRegistrationNotification (to: string[], user: MUser) { |
296 | const text = `Hi,\n\n` + | 292 | const text = `Hi,\n\n` + |
297 | `User ${user.username} just registered on ${WEBSERVER.HOST} PeerTube instance.\n\n` + | 293 | `User ${user.username} just registered on ${WEBSERVER.HOST} PeerTube instance.\n\n` + |
298 | `Cheers,\n` + | 294 | `Cheers,\n` + |
@@ -307,7 +303,7 @@ class Emailer { | |||
307 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 303 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
308 | } | 304 | } |
309 | 305 | ||
310 | addVideoBlacklistNotification (to: string[], videoBlacklist: VideoBlacklistModel) { | 306 | addVideoBlacklistNotification (to: string[], videoBlacklist: MVideoBlacklistVideo) { |
311 | const videoName = videoBlacklist.Video.name | 307 | const videoName = videoBlacklist.Video.name |
312 | const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() | 308 | const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() |
313 | 309 | ||
@@ -329,7 +325,7 @@ class Emailer { | |||
329 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 325 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
330 | } | 326 | } |
331 | 327 | ||
332 | addVideoUnblacklistNotification (to: string[], video: VideoModel) { | 328 | addVideoUnblacklistNotification (to: string[], video: MVideo) { |
333 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() | 329 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() |
334 | 330 | ||
335 | const text = 'Hi,\n\n' + | 331 | const text = 'Hi,\n\n' + |
@@ -381,7 +377,7 @@ class Emailer { | |||
381 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 377 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
382 | } | 378 | } |
383 | 379 | ||
384 | addUserBlockJob (user: UserModel, blocked: boolean, reason?: string) { | 380 | addUserBlockJob (user: MUser, blocked: boolean, reason?: string) { |
385 | const reasonString = reason ? ` for the following reason: ${reason}` : '' | 381 | const reasonString = reason ? ` for the following reason: ${reason}` : '' |
386 | const blockedWord = blocked ? 'blocked' : 'unblocked' | 382 | const blockedWord = blocked ? 'blocked' : 'unblocked' |
387 | const blockedString = `Your account ${user.username} on ${WEBSERVER.HOST} has been ${blockedWord}${reasonString}.` | 383 | const blockedString = `Your account ${user.username} on ${WEBSERVER.HOST} has been ${blockedWord}${reasonString}.` |