14 } from 'sequelize-typescript'
15 import { MNotificationSettingFormattable } from '@server/types/models'
16 import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
17 import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
18 import { clearCacheByUserId } from '../../lib/oauth-model'
19 import { throwIfNotValid } from '../utils'
20 import { UserModel } from './user'
23 tableName: 'userNotificationSetting',
31 export class UserNotificationSettingModel extends Model<UserNotificationSettingModel> {
36 'UserNotificationSettingNewVideoFromSubscription',
37 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newVideoFromSubscription')
40 newVideoFromSubscription: UserNotificationSettingValue
45 'UserNotificationSettingNewCommentOnMyVideo',
46 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newCommentOnMyVideo')
49 newCommentOnMyVideo: UserNotificationSettingValue
54 'UserNotificationSettingAbuseAsModerator',
55 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseAsModerator')
58 abuseAsModerator: UserNotificationSettingValue
63 'UserNotificationSettingVideoAutoBlacklistAsModerator',
64 value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAutoBlacklistAsModerator')
67 videoAutoBlacklistAsModerator: UserNotificationSettingValue
72 'UserNotificationSettingBlacklistOnMyVideo',
73 value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo')
76 blacklistOnMyVideo: UserNotificationSettingValue
81 'UserNotificationSettingMyVideoPublished',
82 value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoPublished')
85 myVideoPublished: UserNotificationSettingValue
90 'UserNotificationSettingMyVideoImportFinished',
91 value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoImportFinished')
94 myVideoImportFinished: UserNotificationSettingValue
99 'UserNotificationSettingNewUserRegistration',
100 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newUserRegistration')
103 newUserRegistration: UserNotificationSettingValue
108 'UserNotificationSettingNewInstanceFollower',
109 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newInstanceFollower')
112 newInstanceFollower: UserNotificationSettingValue
117 'UserNotificationSettingNewInstanceFollower',
118 value => throwIfNotValid(value, isUserNotificationSettingValid, 'autoInstanceFollowing')
121 autoInstanceFollowing: UserNotificationSettingValue
126 'UserNotificationSettingNewFollow',
127 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newFollow')
130 newFollow: UserNotificationSettingValue
135 'UserNotificationSettingCommentMention',
136 value => throwIfNotValid(value, isUserNotificationSettingValid, 'commentMention')
139 commentMention: UserNotificationSettingValue
144 'UserNotificationSettingAbuseStateChange',
145 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseStateChange')
148 abuseStateChange: UserNotificationSettingValue
153 'UserNotificationSettingAbuseNewMessage',
154 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseNewMessage')
157 abuseNewMessage: UserNotificationSettingValue
159 @ForeignKey(() => UserModel)
163 @BelongsTo(() => UserModel, {
179 static removeTokenCache (instance: UserNotificationSettingModel) {
180 return clearCacheByUserId(instance.userId)
183 toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
185 newCommentOnMyVideo: this.newCommentOnMyVideo,
186 newVideoFromSubscription: this.newVideoFromSubscription,
187 abuseAsModerator: this.abuseAsModerator,
188 videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
189 blacklistOnMyVideo: this.blacklistOnMyVideo,
190 myVideoPublished: this.myVideoPublished,
191 myVideoImportFinished: this.myVideoImportFinished,
192 newUserRegistration: this.newUserRegistration,
193 commentMention: this.commentMention,
194 newFollow: this.newFollow,
195 newInstanceFollower: this.newInstanceFollower,
196 autoInstanceFollowing: this.autoInstanceFollowing,
197 abuseNewMessage: this.abuseNewMessage,
198 abuseStateChange: this.abuseStateChange