]>
Commit | Line | Data |
---|---|---|
1 | import { | |
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' | |
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 '../utils' | |
21 | import { UserModel } from './user' | |
22 | ||
23 | @Table({ | |
24 | tableName: 'userNotificationSetting', | |
25 | indexes: [ | |
26 | { | |
27 | fields: [ 'userId' ], | |
28 | unique: true | |
29 | } | |
30 | ] | |
31 | }) | |
32 | export class UserNotificationSettingModel extends Model<Partial<AttributesOnly<UserNotificationSettingModel>>> { | |
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( | |
55 | 'UserNotificationSettingAbuseAsModerator', | |
56 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseAsModerator') | |
57 | ) | |
58 | @Column | |
59 | abuseAsModerator: UserNotificationSettingValue | |
60 | ||
61 | @AllowNull(false) | |
62 | @Default(null) | |
63 | @Is( | |
64 | 'UserNotificationSettingVideoAutoBlacklistAsModerator', | |
65 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAutoBlacklistAsModerator') | |
66 | ) | |
67 | @Column | |
68 | videoAutoBlacklistAsModerator: UserNotificationSettingValue | |
69 | ||
70 | @AllowNull(false) | |
71 | @Default(null) | |
72 | @Is( | |
73 | 'UserNotificationSettingBlacklistOnMyVideo', | |
74 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo') | |
75 | ) | |
76 | @Column | |
77 | blacklistOnMyVideo: UserNotificationSettingValue | |
78 | ||
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 | ||
97 | @AllowNull(false) | |
98 | @Default(null) | |
99 | @Is( | |
100 | 'UserNotificationSettingNewUserRegistration', | |
101 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newUserRegistration') | |
102 | ) | |
103 | @Column | |
104 | newUserRegistration: UserNotificationSettingValue | |
105 | ||
106 | @AllowNull(false) | |
107 | @Default(null) | |
108 | @Is( | |
109 | 'UserNotificationSettingNewInstanceFollower', | |
110 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newInstanceFollower') | |
111 | ) | |
112 | @Column | |
113 | newInstanceFollower: UserNotificationSettingValue | |
114 | ||
115 | @AllowNull(false) | |
116 | @Default(null) | |
117 | @Is( | |
118 | 'UserNotificationSettingNewInstanceFollower', | |
119 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'autoInstanceFollowing') | |
120 | ) | |
121 | @Column | |
122 | autoInstanceFollowing: UserNotificationSettingValue | |
123 | ||
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 | ||
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 | ||
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 | ||
178 | @AllowNull(false) | |
179 | @Default(null) | |
180 | @Is( | |
181 | 'UserNotificationSettingMyVideoStudioEditionFinished', | |
182 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoStudioEditionFinished') | |
183 | ) | |
184 | @Column | |
185 | myVideoStudioEditionFinished: UserNotificationSettingValue | |
186 | ||
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) { | |
208 | return TokensCache.Instance.clearCacheByUserId(instance.userId) | |
209 | } | |
210 | ||
211 | toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting { | |
212 | return { | |
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 | |
230 | } | |
231 | } | |
232 | } |