14 } from 'sequelize-typescript'
15 import { TokensCache } from '@server/lib/auth/tokens-cache'
16 import { MNotificationSettingFormattable } from '@server/types/models'
17 import { AttributesOnly } from '@shared/typescript-utils'
18 import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
19 import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
20 import { throwIfNotValid } from '../shared'
21 import { UserModel } from './user'
24 tableName: 'userNotificationSetting',
32 export class UserNotificationSettingModel extends Model<Partial<AttributesOnly<UserNotificationSettingModel>>> {
37 'UserNotificationSettingNewVideoFromSubscription',
38 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newVideoFromSubscription')
41 newVideoFromSubscription: UserNotificationSettingValue
46 'UserNotificationSettingNewCommentOnMyVideo',
47 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newCommentOnMyVideo')
50 newCommentOnMyVideo: UserNotificationSettingValue
55 'UserNotificationSettingAbuseAsModerator',
56 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseAsModerator')
59 abuseAsModerator: UserNotificationSettingValue
64 'UserNotificationSettingVideoAutoBlacklistAsModerator',
65 value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAutoBlacklistAsModerator')
68 videoAutoBlacklistAsModerator: UserNotificationSettingValue
73 'UserNotificationSettingBlacklistOnMyVideo',
74 value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo')
77 blacklistOnMyVideo: UserNotificationSettingValue
82 'UserNotificationSettingMyVideoPublished',
83 value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoPublished')
86 myVideoPublished: UserNotificationSettingValue
91 'UserNotificationSettingMyVideoImportFinished',
92 value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoImportFinished')
95 myVideoImportFinished: UserNotificationSettingValue
100 'UserNotificationSettingNewUserRegistration',
101 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newUserRegistration')
104 newUserRegistration: UserNotificationSettingValue
109 'UserNotificationSettingNewInstanceFollower',
110 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newInstanceFollower')
113 newInstanceFollower: UserNotificationSettingValue
118 'UserNotificationSettingNewInstanceFollower',
119 value => throwIfNotValid(value, isUserNotificationSettingValid, 'autoInstanceFollowing')
122 autoInstanceFollowing: UserNotificationSettingValue
127 'UserNotificationSettingNewFollow',
128 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newFollow')
131 newFollow: UserNotificationSettingValue
136 'UserNotificationSettingCommentMention',
137 value => throwIfNotValid(value, isUserNotificationSettingValid, 'commentMention')
140 commentMention: UserNotificationSettingValue
145 'UserNotificationSettingAbuseStateChange',
146 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseStateChange')
149 abuseStateChange: UserNotificationSettingValue
154 'UserNotificationSettingAbuseNewMessage',
155 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseNewMessage')
158 abuseNewMessage: UserNotificationSettingValue
163 'UserNotificationSettingNewPeerTubeVersion',
164 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPeerTubeVersion')
167 newPeerTubeVersion: UserNotificationSettingValue
172 'UserNotificationSettingNewPeerPluginVersion',
173 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPluginVersion')
176 newPluginVersion: UserNotificationSettingValue
181 'UserNotificationSettingMyVideoStudioEditionFinished',
182 value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoStudioEditionFinished')
185 myVideoStudioEditionFinished: UserNotificationSettingValue
187 @ForeignKey(() => UserModel)
191 @BelongsTo(() => UserModel, {
207 static removeTokenCache (instance: UserNotificationSettingModel) {
208 return TokensCache.Instance.clearCacheByUserId(instance.userId)
211 toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
213 newCommentOnMyVideo: this.newCommentOnMyVideo,
214 newVideoFromSubscription: this.newVideoFromSubscription,
215 abuseAsModerator: this.abuseAsModerator,
216 videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
217 blacklistOnMyVideo: this.blacklistOnMyVideo,
218 myVideoPublished: this.myVideoPublished,
219 myVideoImportFinished: this.myVideoImportFinished,
220 newUserRegistration: this.newUserRegistration,
221 commentMention: this.commentMention,
222 newFollow: this.newFollow,
223 newInstanceFollower: this.newInstanceFollower,
224 autoInstanceFollowing: this.autoInstanceFollowing,
225 abuseNewMessage: this.abuseNewMessage,
226 abuseStateChange: this.abuseStateChange,
227 newPeerTubeVersion: this.newPeerTubeVersion,
228 myVideoStudioEditionFinished: this.myVideoStudioEditionFinished,
229 newPluginVersion: this.newPluginVersion