]>
Commit | Line | Data |
---|---|---|
cef534ed C |
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' | |
f43db2f4 | 15 | import { TokensCache } from '@server/lib/auth/tokens-cache' |
594d3e48 | 16 | import { MNotificationSettingFormattable } from '@server/types/models' |
6b5f72be | 17 | import { AttributesOnly } from '@shared/typescript-utils' |
cef534ed | 18 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' |
594d3e48 | 19 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' |
594d3e48 C |
20 | import { throwIfNotValid } from '../utils' |
21 | import { UserModel } from './user' | |
cef534ed C |
22 | |
23 | @Table({ | |
24 | tableName: 'userNotificationSetting', | |
25 | indexes: [ | |
26 | { | |
27 | fields: [ 'userId' ], | |
28 | unique: true | |
29 | } | |
30 | ] | |
31 | }) | |
16c016e8 | 32 | export 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 | ||
cef534ed C |
178 | @ForeignKey(() => UserModel) |
179 | @Column | |
180 | userId: number | |
181 | ||
182 | @BelongsTo(() => UserModel, { | |
183 | foreignKey: { | |
184 | allowNull: false | |
185 | }, | |
186 | onDelete: 'cascade' | |
187 | }) | |
188 | User: UserModel | |
189 | ||
190 | @CreatedAt | |
191 | createdAt: Date | |
192 | ||
193 | @UpdatedAt | |
194 | updatedAt: Date | |
195 | ||
196 | @AfterUpdate | |
197 | @AfterDestroy | |
198 | static removeTokenCache (instance: UserNotificationSettingModel) { | |
f43db2f4 | 199 | return TokensCache.Instance.clearCacheByUserId(instance.userId) |
cef534ed C |
200 | } |
201 | ||
1ca9f7c3 | 202 | toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting { |
cef534ed C |
203 | return { |
204 | newCommentOnMyVideo: this.newCommentOnMyVideo, | |
205 | newVideoFromSubscription: this.newVideoFromSubscription, | |
4f32032f | 206 | abuseAsModerator: this.abuseAsModerator, |
7ccddd7b | 207 | videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator, |
dc133480 C |
208 | blacklistOnMyVideo: this.blacklistOnMyVideo, |
209 | myVideoPublished: this.myVideoPublished, | |
f7cc67b4 C |
210 | myVideoImportFinished: this.myVideoImportFinished, |
211 | newUserRegistration: this.newUserRegistration, | |
212 | commentMention: this.commentMention, | |
883993c8 | 213 | newFollow: this.newFollow, |
8424c402 | 214 | newInstanceFollower: this.newInstanceFollower, |
594d3e48 C |
215 | autoInstanceFollowing: this.autoInstanceFollowing, |
216 | abuseNewMessage: this.abuseNewMessage, | |
32a18cbf C |
217 | abuseStateChange: this.abuseStateChange, |
218 | newPeerTubeVersion: this.newPeerTubeVersion, | |
219 | newPluginVersion: this.newPluginVersion | |
cef534ed C |
220 | } |
221 | } | |
222 | } |