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'
22 tableName: 'userNotificationSetting',
30 export class UserNotificationSettingModel extends Model<UserNotificationSettingModel> {
35 'UserNotificationSettingNewVideoFromSubscription',
36 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newVideoFromSubscription')
39 newVideoFromSubscription: UserNotificationSettingValue
44 'UserNotificationSettingNewCommentOnMyVideo',
45 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newCommentOnMyVideo')
48 newCommentOnMyVideo: UserNotificationSettingValue
53 'UserNotificationSettingVideoAbuseAsModerator',
54 value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAbuseAsModerator')
57 videoAbuseAsModerator: UserNotificationSettingValue
62 'UserNotificationSettingBlacklistOnMyVideo',
63 value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo')
66 blacklistOnMyVideo: UserNotificationSettingValue
71 'UserNotificationSettingMyVideoPublished',
72 value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoPublished')
75 myVideoPublished: UserNotificationSettingValue
80 'UserNotificationSettingMyVideoImportFinished',
81 value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoImportFinished')
84 myVideoImportFinished: UserNotificationSettingValue
89 'UserNotificationSettingNewUserRegistration',
90 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newUserRegistration')
93 newUserRegistration: UserNotificationSettingValue
98 'UserNotificationSettingNewFollow',
99 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newFollow')
102 newFollow: UserNotificationSettingValue
107 'UserNotificationSettingCommentMention',
108 value => throwIfNotValid(value, isUserNotificationSettingValid, 'commentMention')
111 commentMention: UserNotificationSettingValue
113 @ForeignKey(() => UserModel)
117 @BelongsTo(() => UserModel, {
133 static removeTokenCache (instance: UserNotificationSettingModel) {
134 return clearCacheByUserId(instance.userId)
137 toFormattedJSON (): UserNotificationSetting {
139 newCommentOnMyVideo: this.newCommentOnMyVideo,
140 newVideoFromSubscription: this.newVideoFromSubscription,
141 videoAbuseAsModerator: this.videoAbuseAsModerator,
142 blacklistOnMyVideo: this.blacklistOnMyVideo,
143 myVideoPublished: this.myVideoPublished,
144 myVideoImportFinished: this.myVideoImportFinished,
145 newUserRegistration: this.newUserRegistration,
146 commentMention: this.commentMention,
147 newFollow: this.newFollow