]>
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' | |
15 | import { throwIfNotValid } from '../utils' | |
16 | import { UserModel } from './user' | |
17 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' | |
18 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' | |
19 | import { clearCacheByUserId } from '../../lib/oauth-model' | |
20 | ||
21 | @Table({ | |
22 | tableName: 'userNotificationSetting', | |
23 | indexes: [ | |
24 | { | |
25 | fields: [ 'userId' ], | |
26 | unique: true | |
27 | } | |
28 | ] | |
29 | }) | |
30 | export class UserNotificationSettingModel extends Model<UserNotificationSettingModel> { | |
31 | ||
32 | @AllowNull(false) | |
33 | @Default(null) | |
34 | @Is( | |
35 | 'UserNotificationSettingNewVideoFromSubscription', | |
36 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newVideoFromSubscription') | |
37 | ) | |
38 | @Column | |
39 | newVideoFromSubscription: UserNotificationSettingValue | |
40 | ||
41 | @AllowNull(false) | |
42 | @Default(null) | |
43 | @Is( | |
44 | 'UserNotificationSettingNewCommentOnMyVideo', | |
45 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newCommentOnMyVideo') | |
46 | ) | |
47 | @Column | |
48 | newCommentOnMyVideo: UserNotificationSettingValue | |
49 | ||
50 | @AllowNull(false) | |
51 | @Default(null) | |
52 | @Is( | |
53 | 'UserNotificationSettingVideoAbuseAsModerator', | |
54 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAbuseAsModerator') | |
55 | ) | |
56 | @Column | |
57 | videoAbuseAsModerator: UserNotificationSettingValue | |
58 | ||
7ccddd7b JM |
59 | @AllowNull(false) |
60 | @Default(null) | |
61 | @Is( | |
62 | 'UserNotificationSettingVideoAutoBlacklistAsModerator', | |
63 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAutoBlacklistAsModerator') | |
64 | ) | |
65 | @Column | |
66 | videoAutoBlacklistAsModerator: UserNotificationSettingValue | |
67 | ||
cef534ed C |
68 | @AllowNull(false) |
69 | @Default(null) | |
70 | @Is( | |
71 | 'UserNotificationSettingBlacklistOnMyVideo', | |
72 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo') | |
73 | ) | |
74 | @Column | |
75 | blacklistOnMyVideo: UserNotificationSettingValue | |
76 | ||
dc133480 C |
77 | @AllowNull(false) |
78 | @Default(null) | |
79 | @Is( | |
80 | 'UserNotificationSettingMyVideoPublished', | |
81 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoPublished') | |
82 | ) | |
83 | @Column | |
84 | myVideoPublished: UserNotificationSettingValue | |
85 | ||
86 | @AllowNull(false) | |
87 | @Default(null) | |
88 | @Is( | |
89 | 'UserNotificationSettingMyVideoImportFinished', | |
90 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoImportFinished') | |
91 | ) | |
92 | @Column | |
93 | myVideoImportFinished: UserNotificationSettingValue | |
94 | ||
f7cc67b4 C |
95 | @AllowNull(false) |
96 | @Default(null) | |
97 | @Is( | |
98 | 'UserNotificationSettingNewUserRegistration', | |
99 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newUserRegistration') | |
100 | ) | |
101 | @Column | |
102 | newUserRegistration: UserNotificationSettingValue | |
103 | ||
883993c8 C |
104 | @AllowNull(false) |
105 | @Default(null) | |
106 | @Is( | |
107 | 'UserNotificationSettingNewInstanceFollower', | |
108 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newInstanceFollower') | |
109 | ) | |
110 | @Column | |
111 | newInstanceFollower: UserNotificationSettingValue | |
112 | ||
f7cc67b4 C |
113 | @AllowNull(false) |
114 | @Default(null) | |
115 | @Is( | |
116 | 'UserNotificationSettingNewFollow', | |
117 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newFollow') | |
118 | ) | |
119 | @Column | |
120 | newFollow: UserNotificationSettingValue | |
121 | ||
122 | @AllowNull(false) | |
123 | @Default(null) | |
124 | @Is( | |
125 | 'UserNotificationSettingCommentMention', | |
126 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'commentMention') | |
127 | ) | |
128 | @Column | |
129 | commentMention: UserNotificationSettingValue | |
130 | ||
cef534ed C |
131 | @ForeignKey(() => UserModel) |
132 | @Column | |
133 | userId: number | |
134 | ||
135 | @BelongsTo(() => UserModel, { | |
136 | foreignKey: { | |
137 | allowNull: false | |
138 | }, | |
139 | onDelete: 'cascade' | |
140 | }) | |
141 | User: UserModel | |
142 | ||
143 | @CreatedAt | |
144 | createdAt: Date | |
145 | ||
146 | @UpdatedAt | |
147 | updatedAt: Date | |
148 | ||
149 | @AfterUpdate | |
150 | @AfterDestroy | |
151 | static removeTokenCache (instance: UserNotificationSettingModel) { | |
152 | return clearCacheByUserId(instance.userId) | |
153 | } | |
154 | ||
155 | toFormattedJSON (): UserNotificationSetting { | |
156 | return { | |
157 | newCommentOnMyVideo: this.newCommentOnMyVideo, | |
158 | newVideoFromSubscription: this.newVideoFromSubscription, | |
159 | videoAbuseAsModerator: this.videoAbuseAsModerator, | |
7ccddd7b | 160 | videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator, |
dc133480 C |
161 | blacklistOnMyVideo: this.blacklistOnMyVideo, |
162 | myVideoPublished: this.myVideoPublished, | |
f7cc67b4 C |
163 | myVideoImportFinished: this.myVideoImportFinished, |
164 | newUserRegistration: this.newUserRegistration, | |
165 | commentMention: this.commentMention, | |
883993c8 C |
166 | newFollow: this.newFollow, |
167 | newInstanceFollower: this.newInstanceFollower | |
cef534ed C |
168 | } |
169 | } | |
170 | } |