14 } from 'sequelize-typescript'
15 import { throwIfNotValid } from '../utils'
16 import { UserModel } from './user'
17 import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
18 import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
19 import { clearCacheByUserId } from '../../lib/oauth-model'
20 import { MNotificationSettingFormattable } from '@server/typings/models'
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 'UserNotificationSettingVideoAbuseAsModerator',
55 value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAbuseAsModerator')
58 videoAbuseAsModerator: 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 'UserNotificationSettingNewFollow',
118 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newFollow')
121 newFollow: UserNotificationSettingValue
126 'UserNotificationSettingCommentMention',
127 value => throwIfNotValid(value, isUserNotificationSettingValid, 'commentMention')
130 commentMention: UserNotificationSettingValue
132 @ForeignKey(() => UserModel)
136 @BelongsTo(() => UserModel, {
152 static removeTokenCache (instance: UserNotificationSettingModel) {
153 return clearCacheByUserId(instance.userId)
156 toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
158 newCommentOnMyVideo: this.newCommentOnMyVideo,
159 newVideoFromSubscription: this.newVideoFromSubscription,
160 videoAbuseAsModerator: this.videoAbuseAsModerator,
161 videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
162 blacklistOnMyVideo: this.blacklistOnMyVideo,
163 myVideoPublished: this.myVideoPublished,
164 myVideoImportFinished: this.myVideoImportFinished,
165 newUserRegistration: this.newUserRegistration,
166 commentMention: this.commentMention,
167 newFollow: this.newFollow,
168 newInstanceFollower: this.newInstanceFollower