diff options
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r-- | server/lib/emailer.ts | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index c6ad03328..9c49aa2f6 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts | |||
@@ -5,13 +5,13 @@ import { join } from 'path' | |||
5 | import { VideoChannelModel } from '@server/models/video/video-channel' | 5 | import { VideoChannelModel } from '@server/models/video/video-channel' |
6 | import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist' | 6 | import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist' |
7 | import { MVideoImport, MVideoImportVideo } from '@server/types/models/video/video-import' | 7 | import { MVideoImport, MVideoImportVideo } from '@server/types/models/video/video-import' |
8 | import { UserAbuse, EmailPayload } from '@shared/models' | 8 | import { AbuseState, EmailPayload, UserAbuse } from '@shared/models' |
9 | import { SendEmailOptions } from '../../shared/models/server/emailer.model' | 9 | import { SendEmailOptions } from '../../shared/models/server/emailer.model' |
10 | import { isTestInstance, root } from '../helpers/core-utils' | 10 | import { isTestInstance, root } from '../helpers/core-utils' |
11 | import { bunyanLogger, logger } from '../helpers/logger' | 11 | import { bunyanLogger, logger } from '../helpers/logger' |
12 | import { CONFIG, isEmailEnabled } from '../initializers/config' | 12 | import { CONFIG, isEmailEnabled } from '../initializers/config' |
13 | import { WEBSERVER } from '../initializers/constants' | 13 | import { WEBSERVER } from '../initializers/constants' |
14 | import { MAbuseFull, MActorFollowActors, MActorFollowFull, MUser } from '../types/models' | 14 | import { MAbuseFull, MAbuseMessage, MActorFollowActors, MActorFollowFull, MUser } from '../types/models' |
15 | import { MCommentOwnerVideo, MVideo, MVideoAccountLight } from '../types/models/video' | 15 | import { MCommentOwnerVideo, MVideo, MVideoAccountLight } from '../types/models/video' |
16 | import { JobQueue } from './job-queue' | 16 | import { JobQueue } from './job-queue' |
17 | 17 | ||
@@ -357,6 +357,55 @@ class Emailer { | |||
357 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 357 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
358 | } | 358 | } |
359 | 359 | ||
360 | addAbuseStateChangeNotification (to: string[], abuse: MAbuseFull) { | ||
361 | const text = abuse.state === AbuseState.ACCEPTED | ||
362 | ? 'Report #' + abuse.id + ' has been accepted' | ||
363 | : 'Report #' + abuse.id + ' has been rejected' | ||
364 | |||
365 | const action = { | ||
366 | text, | ||
367 | url: WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id | ||
368 | } | ||
369 | |||
370 | const emailPayload: EmailPayload = { | ||
371 | template: 'abuse-state-change', | ||
372 | to, | ||
373 | subject: text, | ||
374 | locals: { | ||
375 | action, | ||
376 | abuseId: abuse.id, | ||
377 | isAccepted: abuse.state === AbuseState.ACCEPTED | ||
378 | } | ||
379 | } | ||
380 | |||
381 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | ||
382 | } | ||
383 | |||
384 | addAbuseNewMessageNotification (to: string[], options: { target: 'moderator' | 'reporter', abuse: MAbuseFull, message: MAbuseMessage }) { | ||
385 | const { abuse, target, message } = options | ||
386 | |||
387 | const text = 'New message on abuse #' + abuse.id | ||
388 | const action = { | ||
389 | text, | ||
390 | url: target === 'moderator' | ||
391 | ? WEBSERVER.URL + '/admin/moderation/abuses/list?search=%23' + abuse.id | ||
392 | : WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id | ||
393 | } | ||
394 | |||
395 | const emailPayload: EmailPayload = { | ||
396 | template: 'abuse-new-message', | ||
397 | to, | ||
398 | subject: text, | ||
399 | locals: { | ||
400 | abuseUrl: action.url, | ||
401 | messageText: message.message, | ||
402 | action | ||
403 | } | ||
404 | } | ||
405 | |||
406 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | ||
407 | } | ||
408 | |||
360 | async addVideoAutoBlacklistModeratorsNotification (to: string[], videoBlacklist: MVideoBlacklistLightVideo) { | 409 | async addVideoAutoBlacklistModeratorsNotification (to: string[], videoBlacklist: MVideoBlacklistLightVideo) { |
361 | const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' | 410 | const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' |
362 | const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() | 411 | const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() |