aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/emailer.ts30
-rw-r--r--server/lib/emails/abuse-new-message/html.pug4
-rw-r--r--server/lib/emails/abuse-state-change/html.pug4
-rw-r--r--server/lib/notifier.ts9
4 files changed, 32 insertions, 15 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 9c49aa2f6..25b0aaedd 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -11,7 +11,7 @@ import { isTestInstance, root } from '../helpers/core-utils'
11import { bunyanLogger, logger } from '../helpers/logger' 11import { bunyanLogger, logger } from '../helpers/logger'
12import { CONFIG, isEmailEnabled } from '../initializers/config' 12import { CONFIG, isEmailEnabled } from '../initializers/config'
13import { WEBSERVER } from '../initializers/constants' 13import { WEBSERVER } from '../initializers/constants'
14import { MAbuseFull, MAbuseMessage, MActorFollowActors, MActorFollowFull, MUser } from '../types/models' 14import { MAbuseFull, MAbuseMessage, MAccountDefault, MActorFollowActors, MActorFollowFull, MUser } from '../types/models'
15import { MCommentOwnerVideo, MVideo, MVideoAccountLight } from '../types/models/video' 15import { MCommentOwnerVideo, MVideo, MVideoAccountLight } from '../types/models/video'
16import { JobQueue } from './job-queue' 16import { JobQueue } from './job-queue'
17 17
@@ -362,9 +362,11 @@ class Emailer {
362 ? 'Report #' + abuse.id + ' has been accepted' 362 ? 'Report #' + abuse.id + ' has been accepted'
363 : 'Report #' + abuse.id + ' has been rejected' 363 : 'Report #' + abuse.id + ' has been rejected'
364 364
365 const abuseUrl = WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id
366
365 const action = { 367 const action = {
366 text, 368 text,
367 url: WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id 369 url: abuseUrl
368 } 370 }
369 371
370 const emailPayload: EmailPayload = { 372 const emailPayload: EmailPayload = {
@@ -374,6 +376,7 @@ class Emailer {
374 locals: { 376 locals: {
375 action, 377 action,
376 abuseId: abuse.id, 378 abuseId: abuse.id,
379 abuseUrl,
377 isAccepted: abuse.state === AbuseState.ACCEPTED 380 isAccepted: abuse.state === AbuseState.ACCEPTED
378 } 381 }
379 } 382 }
@@ -381,15 +384,24 @@ class Emailer {
381 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 384 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
382 } 385 }
383 386
384 addAbuseNewMessageNotification (to: string[], options: { target: 'moderator' | 'reporter', abuse: MAbuseFull, message: MAbuseMessage }) { 387 addAbuseNewMessageNotification (
385 const { abuse, target, message } = options 388 to: string[],
389 options: {
390 target: 'moderator' | 'reporter'
391 abuse: MAbuseFull
392 message: MAbuseMessage
393 accountMessage: MAccountDefault
394 }) {
395 const { abuse, target, message, accountMessage } = options
396
397 const text = 'New message on report #' + abuse.id
398 const abuseUrl = target === 'moderator'
399 ? WEBSERVER.URL + '/admin/moderation/abuses/list?search=%23' + abuse.id
400 : WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id
386 401
387 const text = 'New message on abuse #' + abuse.id
388 const action = { 402 const action = {
389 text, 403 text,
390 url: target === 'moderator' 404 url: abuseUrl
391 ? WEBSERVER.URL + '/admin/moderation/abuses/list?search=%23' + abuse.id
392 : WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id
393 } 405 }
394 406
395 const emailPayload: EmailPayload = { 407 const emailPayload: EmailPayload = {
@@ -397,7 +409,9 @@ class Emailer {
397 to, 409 to,
398 subject: text, 410 subject: text,
399 locals: { 411 locals: {
412 abuseId: abuse.id,
400 abuseUrl: action.url, 413 abuseUrl: action.url,
414 messageAccountName: accountMessage.getDisplayName(),
401 messageText: message.message, 415 messageText: message.message,
402 action 416 action
403 } 417 }
diff --git a/server/lib/emails/abuse-new-message/html.pug b/server/lib/emails/abuse-new-message/html.pug
index a4180aba1..0841775d2 100644
--- a/server/lib/emails/abuse-new-message/html.pug
+++ b/server/lib/emails/abuse-new-message/html.pug
@@ -2,10 +2,10 @@ extends ../common/greetings
2include ../common/mixins.pug 2include ../common/mixins.pug
3 3
4block title 4block title
5 | New abuse message 5 | New message on abuse report
6 6
7block content 7block content
8 p 8 p
9 | A new message was created on #[a(href=WEBSERVER.URL) abuse ##{abuseId} on #{WEBSERVER.HOST}] 9 | A new message by #{messageAccountName} was posted on #[a(href=abuseUrl) abuse report ##{abuseId}] on #{WEBSERVER.HOST}
10 blockquote #{messageText} 10 blockquote #{messageText}
11 br(style="display: none;") 11 br(style="display: none;")
diff --git a/server/lib/emails/abuse-state-change/html.pug b/server/lib/emails/abuse-state-change/html.pug
index a94c8521d..ca89a2f05 100644
--- a/server/lib/emails/abuse-state-change/html.pug
+++ b/server/lib/emails/abuse-state-change/html.pug
@@ -2,8 +2,8 @@ extends ../common/greetings
2include ../common/mixins.pug 2include ../common/mixins.pug
3 3
4block title 4block title
5 | Abuse state changed 5 | Abuse report state changed
6 6
7block content 7block content
8 p 8 p
9 | #[a(href=abuseUrl) Your abuse ##{abuseId} on #{WEBSERVER.HOST}] has been #{isAccepted ? 'accepted' : 'rejected'} 9 | #[a(href=abuseUrl) Your abuse report ##{abuseId}] on #{WEBSERVER.HOST} has been #{isAccepted ? 'accepted' : 'rejected'}
diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts
index 5c50fcf01..9c2f16c27 100644
--- a/server/lib/notifier.ts
+++ b/server/lib/notifier.ts
@@ -24,6 +24,7 @@ import { MCommentOwnerVideo, MVideoAccountLight, MVideoFullLight } from '../type
24import { isBlockedByServerOrAccount } from './blocklist' 24import { isBlockedByServerOrAccount } from './blocklist'
25import { Emailer } from './emailer' 25import { Emailer } from './emailer'
26import { PeerTubeSocket } from './peertube-socket' 26import { PeerTubeSocket } from './peertube-socket'
27import { AccountModel } from '@server/models/account/account'
27 28
28class Notifier { 29class Notifier {
29 30
@@ -137,7 +138,7 @@ class Notifier {
137 }) 138 })
138 } 139 }
139 140
140 notifyOnAbuseMessage (abuse: MAbuseFull, message: AbuseMessageModel): void { 141 notifyOnAbuseMessage (abuse: MAbuseFull, message: MAbuseMessage): void {
141 this.notifyOfNewAbuseMessage(abuse, message) 142 this.notifyOfNewAbuseMessage(abuse, message)
142 .catch(err => { 143 .catch(err => {
143 logger.error('Cannot notify on new abuse %d message.', abuse.id, { err }) 144 logger.error('Cannot notify on new abuse %d message.', abuse.id, { err })
@@ -436,6 +437,8 @@ class Notifier {
436 const url = this.getAbuseUrl(abuse) 437 const url = this.getAbuseUrl(abuse)
437 logger.info('Notifying reporter and moderators of new abuse message on %s.', url) 438 logger.info('Notifying reporter and moderators of new abuse message on %s.', url)
438 439
440 const accountMessage = await AccountModel.load(message.accountId)
441
439 function settingGetter (user: MUserWithNotificationSetting) { 442 function settingGetter (user: MUserWithNotificationSetting) {
440 return user.NotificationSetting.abuseNewMessage 443 return user.NotificationSetting.abuseNewMessage
441 } 444 }
@@ -452,11 +455,11 @@ class Notifier {
452 } 455 }
453 456
454 function emailSenderReporter (emails: string[]) { 457 function emailSenderReporter (emails: string[]) {
455 return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'reporter', abuse, message }) 458 return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'reporter', abuse, message, accountMessage })
456 } 459 }
457 460
458 function emailSenderModerators (emails: string[]) { 461 function emailSenderModerators (emails: string[]) {
459 return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'moderator', abuse, message }) 462 return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'moderator', abuse, message, accountMessage })
460 } 463 }
461 464
462 async function buildReporterOptions () { 465 async function buildReporterOptions () {