14 } from 'sequelize-typescript'
15 import { TokensCache } from '@server/lib/auth/tokens-cache'
16 import { MNotificationSettingFormattable } from '@server/types/models'
17 import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
18 import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
19 import { throwIfNotValid } from '../utils'
20 import { UserModel } from './user'
23 tableName: 'userNotificationSetting',
31 export class UserNotificationSettingModel extends Model {
36 'UserNotificationSettingNewVideoFromSubscription',
37 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newVideoFromSubscription')
40 newVideoFromSubscription: UserNotificationSettingValue
45 'UserNotificationSettingNewCommentOnMyVideo',
46 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newCommentOnMyVideo')
49 newCommentOnMyVideo: UserNotificationSettingValue
54 'UserNotificationSettingAbuseAsModerator',
55 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseAsModerator')
58 abuseAsModerator: 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
144 'UserNotificationSettingAbuseStateChange',
145 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseStateChange')
148 abuseStateChange: UserNotificationSettingValue
153 'UserNotificationSettingAbuseNewMessage',
154 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseNewMessage')
157 abuseNewMessage: UserNotificationSettingValue
162 'UserNotificationSettingNewPeerTubeVersion',
163 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPeerTubeVersion')
166 newPeerTubeVersion: UserNotificationSettingValue
171 'UserNotificationSettingNewPeerPluginVersion',
172 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPluginVersion')
175 newPluginVersion: UserNotificationSettingValue
177 @ForeignKey(() => UserModel)
181 @BelongsTo(() => UserModel, {
197 static removeTokenCache (instance: UserNotificationSettingModel) {
198 return TokensCache.Instance.clearCacheByUserId(instance.userId)
201 toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
203 newCommentOnMyVideo: this.newCommentOnMyVideo,
204 newVideoFromSubscription: this.newVideoFromSubscription,
205 abuseAsModerator: this.abuseAsModerator,
206 videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
207 blacklistOnMyVideo: this.blacklistOnMyVideo,
208 myVideoPublished: this.myVideoPublished,
209 myVideoImportFinished: this.myVideoImportFinished,
210 newUserRegistration: this.newUserRegistration,
211 commentMention: this.commentMention,
212 newFollow: this.newFollow,
213 newInstanceFollower: this.newInstanceFollower,
214 autoInstanceFollowing: this.autoInstanceFollowing,
215 abuseNewMessage: this.abuseNewMessage,
216 abuseStateChange: this.abuseStateChange,
217 newPeerTubeVersion: this.newPeerTubeVersion,
218 newPluginVersion: this.newPluginVersion