]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/user/user-notification-setting.ts
Rename studio to editor
[github/Chocobozzz/PeerTube.git] / server / models / user / user-notification-setting.ts
CommitLineData
cef534ed
C
1import {
2 AfterDestroy,
3 AfterUpdate,
4 AllowNull,
5 BelongsTo,
6 Column,
7 CreatedAt,
8 Default,
9 ForeignKey,
10 Is,
11 Model,
12 Table,
13 UpdatedAt
14} from 'sequelize-typescript'
f43db2f4 15import { TokensCache } from '@server/lib/auth/tokens-cache'
594d3e48 16import { MNotificationSettingFormattable } from '@server/types/models'
6b5f72be 17import { AttributesOnly } from '@shared/typescript-utils'
cef534ed 18import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
594d3e48 19import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
594d3e48
C
20import { throwIfNotValid } from '../utils'
21import { UserModel } from './user'
cef534ed
C
22
23@Table({
24 tableName: 'userNotificationSetting',
25 indexes: [
26 {
27 fields: [ 'userId' ],
28 unique: true
29 }
30 ]
31})
16c016e8 32export class UserNotificationSettingModel extends Model<Partial<AttributesOnly<UserNotificationSettingModel>>> {
cef534ed
C
33
34 @AllowNull(false)
35 @Default(null)
36 @Is(
37 'UserNotificationSettingNewVideoFromSubscription',
38 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newVideoFromSubscription')
39 )
40 @Column
41 newVideoFromSubscription: UserNotificationSettingValue
42
43 @AllowNull(false)
44 @Default(null)
45 @Is(
46 'UserNotificationSettingNewCommentOnMyVideo',
47 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newCommentOnMyVideo')
48 )
49 @Column
50 newCommentOnMyVideo: UserNotificationSettingValue
51
52 @AllowNull(false)
53 @Default(null)
54 @Is(
4f32032f
C
55 'UserNotificationSettingAbuseAsModerator',
56 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseAsModerator')
cef534ed
C
57 )
58 @Column
4f32032f 59 abuseAsModerator: UserNotificationSettingValue
cef534ed 60
7ccddd7b
JM
61 @AllowNull(false)
62 @Default(null)
63 @Is(
64 'UserNotificationSettingVideoAutoBlacklistAsModerator',
65 value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAutoBlacklistAsModerator')
66 )
67 @Column
68 videoAutoBlacklistAsModerator: UserNotificationSettingValue
69
cef534ed
C
70 @AllowNull(false)
71 @Default(null)
72 @Is(
73 'UserNotificationSettingBlacklistOnMyVideo',
74 value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo')
75 )
76 @Column
77 blacklistOnMyVideo: UserNotificationSettingValue
78
dc133480
C
79 @AllowNull(false)
80 @Default(null)
81 @Is(
82 'UserNotificationSettingMyVideoPublished',
83 value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoPublished')
84 )
85 @Column
86 myVideoPublished: UserNotificationSettingValue
87
88 @AllowNull(false)
89 @Default(null)
90 @Is(
91 'UserNotificationSettingMyVideoImportFinished',
92 value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoImportFinished')
93 )
94 @Column
95 myVideoImportFinished: UserNotificationSettingValue
96
f7cc67b4
C
97 @AllowNull(false)
98 @Default(null)
99 @Is(
100 'UserNotificationSettingNewUserRegistration',
101 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newUserRegistration')
102 )
103 @Column
104 newUserRegistration: UserNotificationSettingValue
105
883993c8
C
106 @AllowNull(false)
107 @Default(null)
108 @Is(
109 'UserNotificationSettingNewInstanceFollower',
110 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newInstanceFollower')
111 )
112 @Column
113 newInstanceFollower: UserNotificationSettingValue
114
8424c402
C
115 @AllowNull(false)
116 @Default(null)
117 @Is(
118 'UserNotificationSettingNewInstanceFollower',
119 value => throwIfNotValid(value, isUserNotificationSettingValid, 'autoInstanceFollowing')
120 )
121 @Column
122 autoInstanceFollowing: UserNotificationSettingValue
123
f7cc67b4
C
124 @AllowNull(false)
125 @Default(null)
126 @Is(
127 'UserNotificationSettingNewFollow',
128 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newFollow')
129 )
130 @Column
131 newFollow: UserNotificationSettingValue
132
133 @AllowNull(false)
134 @Default(null)
135 @Is(
136 'UserNotificationSettingCommentMention',
137 value => throwIfNotValid(value, isUserNotificationSettingValid, 'commentMention')
138 )
139 @Column
140 commentMention: UserNotificationSettingValue
141
594d3e48
C
142 @AllowNull(false)
143 @Default(null)
144 @Is(
145 'UserNotificationSettingAbuseStateChange',
146 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseStateChange')
147 )
148 @Column
149 abuseStateChange: UserNotificationSettingValue
150
151 @AllowNull(false)
152 @Default(null)
153 @Is(
154 'UserNotificationSettingAbuseNewMessage',
155 value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseNewMessage')
156 )
157 @Column
158 abuseNewMessage: UserNotificationSettingValue
159
32a18cbf
C
160 @AllowNull(false)
161 @Default(null)
162 @Is(
163 'UserNotificationSettingNewPeerTubeVersion',
164 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPeerTubeVersion')
165 )
166 @Column
167 newPeerTubeVersion: UserNotificationSettingValue
168
169 @AllowNull(false)
170 @Default(null)
171 @Is(
172 'UserNotificationSettingNewPeerPluginVersion',
173 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPluginVersion')
174 )
175 @Column
176 newPluginVersion: UserNotificationSettingValue
177
1808a1f8
C
178 @AllowNull(false)
179 @Default(null)
180 @Is(
92e66e04
C
181 'UserNotificationSettingMyVideoStudioEditionFinished',
182 value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoStudioEditionFinished')
1808a1f8
C
183 )
184 @Column
92e66e04 185 myVideoStudioEditionFinished: UserNotificationSettingValue
1808a1f8 186
cef534ed
C
187 @ForeignKey(() => UserModel)
188 @Column
189 userId: number
190
191 @BelongsTo(() => UserModel, {
192 foreignKey: {
193 allowNull: false
194 },
195 onDelete: 'cascade'
196 })
197 User: UserModel
198
199 @CreatedAt
200 createdAt: Date
201
202 @UpdatedAt
203 updatedAt: Date
204
205 @AfterUpdate
206 @AfterDestroy
207 static removeTokenCache (instance: UserNotificationSettingModel) {
f43db2f4 208 return TokensCache.Instance.clearCacheByUserId(instance.userId)
cef534ed
C
209 }
210
1ca9f7c3 211 toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
cef534ed
C
212 return {
213 newCommentOnMyVideo: this.newCommentOnMyVideo,
214 newVideoFromSubscription: this.newVideoFromSubscription,
4f32032f 215 abuseAsModerator: this.abuseAsModerator,
7ccddd7b 216 videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
dc133480
C
217 blacklistOnMyVideo: this.blacklistOnMyVideo,
218 myVideoPublished: this.myVideoPublished,
f7cc67b4
C
219 myVideoImportFinished: this.myVideoImportFinished,
220 newUserRegistration: this.newUserRegistration,
221 commentMention: this.commentMention,
883993c8 222 newFollow: this.newFollow,
8424c402 223 newInstanceFollower: this.newInstanceFollower,
594d3e48
C
224 autoInstanceFollowing: this.autoInstanceFollowing,
225 abuseNewMessage: this.abuseNewMessage,
32a18cbf
C
226 abuseStateChange: this.abuseStateChange,
227 newPeerTubeVersion: this.newPeerTubeVersion,
92e66e04 228 myVideoStudioEditionFinished: this.myVideoStudioEditionFinished,
32a18cbf 229 newPluginVersion: this.newPluginVersion
cef534ed
C
230 }
231 }
232}