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
86 @ForeignKey(() => UserModel)
90 @BelongsTo(() => UserModel, {
106 static removeTokenCache (instance: UserNotificationSettingModel) {
107 return clearCacheByUserId(instance.userId)
110 toFormattedJSON (): UserNotificationSetting {
112 newCommentOnMyVideo: this.newCommentOnMyVideo,
113 newVideoFromSubscription: this.newVideoFromSubscription,
114 videoAbuseAsModerator: this.videoAbuseAsModerator,
115 blacklistOnMyVideo: this.blacklistOnMyVideo,
116 myVideoPublished: this.myVideoPublished,
117 myVideoImportFinished: this.myVideoImportFinished