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 '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
141 @ForeignKey(() => UserModel)
145 @BelongsTo(() => UserModel, {
161 static removeTokenCache (instance: UserNotificationSettingModel) {
162 return clearCacheByUserId(instance.userId)
165 toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
167 newCommentOnMyVideo: this.newCommentOnMyVideo,
168 newVideoFromSubscription: this.newVideoFromSubscription,
169 videoAbuseAsModerator: this.videoAbuseAsModerator,
170 videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
171 blacklistOnMyVideo: this.blacklistOnMyVideo,
172 myVideoPublished: this.myVideoPublished,
173 myVideoImportFinished: this.myVideoImportFinished,
174 newUserRegistration: this.newUserRegistration,
175 commentMention: this.commentMention,
176 newFollow: this.newFollow,
177 newInstanceFollower: this.newInstanceFollower,
178 autoInstanceFollowing: this.autoInstanceFollowing