aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/notifier/shared/abuse/new-abuse-message-for-moderators.ts
blob: 9d0629690e32d714df808f09e2866efc7e39b448 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { logger } from '@server/helpers/logger'
import { getAbuseTargetUrl } from '@server/lib/activitypub/url'
import { UserModel } from '@server/models/user/user'
import { MUserDefault } from '@server/types/models'
import { UserRight } from '@shared/models'
import { AbstractNewAbuseMessage } from './abstract-new-abuse-message'

export class NewAbuseMessageForModerators extends AbstractNewAbuseMessage {
  private moderators: MUserDefault[]

  async prepare () {
    this.moderators = await UserModel.listWithRight(UserRight.MANAGE_ABUSES)

    // Don't notify my own message
    this.moderators = this.moderators.filter(m => m.Account.id !== this.message.accountId)
    if (this.moderators.length === 0) return

    await this.loadMessageAccount()
  }

  log () {
    logger.info('Notifying moderators of new abuse message on %s.', getAbuseTargetUrl(this.abuse))
  }

  getTargetUsers () {
    return this.moderators
  }

  createEmail (to: string) {
    return this.createEmailFor(to, 'moderator')
  }
}