aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/notifier/shared/abuse/new-abuse-message-for-reporter.ts
blob: c5bbb54478b8ff447d3c17297610d59aa82127f4 (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
33
34
35
36
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 { AbstractNewAbuseMessage } from './abstract-new-abuse-message'

export class NewAbuseMessageForReporter extends AbstractNewAbuseMessage {
  private reporter: MUserDefault

  async prepare () {
    // Only notify our users
    if (this.abuse.ReporterAccount.isOwned() !== true) return

    await this.loadMessageAccount()

    const reporter = await UserModel.loadByAccountActorId(this.abuse.ReporterAccount.actorId)
    // Don't notify my own message
    if (reporter.Account.id === this.message.accountId) return

    this.reporter = reporter
  }

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

  getTargetUsers () {
    if (!this.reporter) return []

    return [ this.reporter ]
  }

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