aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/user/user-notification-setting.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/user/user-notification-setting.ts')
-rw-r--r--server/models/user/user-notification-setting.ts222
1 files changed, 222 insertions, 0 deletions
diff --git a/server/models/user/user-notification-setting.ts b/server/models/user/user-notification-setting.ts
new file mode 100644
index 000000000..bee7d7851
--- /dev/null
+++ b/server/models/user/user-notification-setting.ts
@@ -0,0 +1,222 @@
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'
15import { TokensCache } from '@server/lib/auth/tokens-cache'
16import { MNotificationSettingFormattable } from '@server/types/models'
17import { AttributesOnly } from '@shared/core-utils'
18import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
19import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
20import { throwIfNotValid } from '../utils'
21import { UserModel } from './user'
22
23@Table({
24 tableName: 'userNotificationSetting',
25 indexes: [
26 {
27 fields: [ 'userId' ],
28 unique: true
29 }
30 ]
31})
32export 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 @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) {
199 return TokensCache.Instance.clearCacheByUserId(instance.userId)
200 }
201
202 toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
203 return {
204 newCommentOnMyVideo: this.newCommentOnMyVideo,
205 newVideoFromSubscription: this.newVideoFromSubscription,
206 abuseAsModerator: this.abuseAsModerator,
207 videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
208 blacklistOnMyVideo: this.blacklistOnMyVideo,
209 myVideoPublished: this.myVideoPublished,
210 myVideoImportFinished: this.myVideoImportFinished,
211 newUserRegistration: this.newUserRegistration,
212 commentMention: this.commentMention,
213 newFollow: this.newFollow,
214 newInstanceFollower: this.newInstanceFollower,
215 autoInstanceFollowing: this.autoInstanceFollowing,
216 abuseNewMessage: this.abuseNewMessage,
217 abuseStateChange: this.abuseStateChange,
218 newPeerTubeVersion: this.newPeerTubeVersion,
219 newPluginVersion: this.newPluginVersion
220 }
221 }
222}