1 import { logger } from '@server/helpers/logger'
2 import { WEBSERVER } from '@server/initializers/constants'
3 import { getAbuseTargetUrl } from '@server/lib/activitypub/url'
4 import { UserModel } from '@server/models/user/user'
5 import { UserNotificationModel } from '@server/models/user/user-notification'
6 import { MAbuseFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
7 import { AbuseState, UserNotificationType } from '@shared/models'
8 import { AbstractNotification } from '../common/abstract-notification'
10 export class AbuseStateChangeForReporter extends AbstractNotification <MAbuseFull> {
12 private user: MUserDefault
15 const reporter = this.abuse.ReporterAccount
16 if (reporter.isOwned() !== true) return
18 this.user = await UserModel.loadByAccountActorId(this.abuse.ReporterAccount.actorId)
22 logger.info('Notifying reporter of abuse % of state change.', getAbuseTargetUrl(this.abuse))
25 getSetting (user: MUserWithNotificationSetting) {
26 return user.NotificationSetting.abuseStateChange
30 if (!this.user) return []
35 async createNotification (user: MUserWithNotificationSetting) {
36 const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
37 type: UserNotificationType.ABUSE_STATE_CHANGE,
39 abuseId: this.abuse.id
41 notification.Abuse = this.abuse
46 createEmail (to: string) {
47 const text = this.abuse.state === AbuseState.ACCEPTED
48 ? 'Report #' + this.abuse.id + ' has been accepted'
49 : 'Report #' + this.abuse.id + ' has been rejected'
51 const abuseUrl = WEBSERVER.URL + '/my-account/abuses?search=%23' + this.abuse.id
54 text: 'View report #' + this.abuse.id,
59 template: 'abuse-state-change',
64 abuseId: this.abuse.id,
66 isAccepted: this.abuse.state === AbuseState.ACCEPTED
71 private get abuse () {