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