1 import { WEBSERVER } from '@server/initializers/constants'
2 import { AccountModel } from '@server/models/account/account'
3 import { UserNotificationModel } from '@server/models/user/user-notification'
4 import { MAbuseFull, MAbuseMessage, MAccountDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
5 import { UserNotificationType } from '@shared/models'
6 import { AbstractNotification } from '../common/abstract-notification'
8 type NewAbuseMessagePayload = {
10 message: MAbuseMessage
13 export abstract class AbstractNewAbuseMessage extends AbstractNotification <NewAbuseMessagePayload> {
14 protected messageAccount: MAccountDefault
16 async loadMessageAccount () {
17 this.messageAccount = await AccountModel.load(this.message.accountId)
20 getSetting (user: MUserWithNotificationSetting) {
21 return user.NotificationSetting.abuseNewMessage
24 async createNotification (user: MUserWithNotificationSetting) {
25 const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
26 type: UserNotificationType.ABUSE_NEW_MESSAGE,
28 abuseId: this.abuse.id
30 notification.Abuse = this.abuse
35 protected createEmailFor (to: string, target: 'moderator' | 'reporter') {
36 const text = 'New message on report #' + this.abuse.id
37 const abuseUrl = target === 'moderator'
38 ? WEBSERVER.URL + '/admin/moderation/abuses/list?search=%23' + this.abuse.id
39 : WEBSERVER.URL + '/my-account/abuses?search=%23' + this.abuse.id
42 text: 'View report #' + this.abuse.id,
47 template: 'abuse-new-message',
51 abuseId: this.abuse.id,
53 messageAccountName: this.messageAccount.getDisplayName(),
54 messageText: this.message.message,
60 protected get abuse () {
61 return this.payload.abuse
64 protected get message () {
65 return this.payload.message