]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/account/user-notification-setting.ts
add quarantine videos feature (#1637)
[github/Chocobozzz/PeerTube.git] / server / models / account / user-notification-setting.ts
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
59 @AllowNull(false)
60 @Default(null)
61 @Is(
62 'UserNotificationSettingVideoAutoBlacklistAsModerator',
63 value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAutoBlacklistAsModerator')
64 )
65 @Column
66 videoAutoBlacklistAsModerator: UserNotificationSettingValue
67
68 @AllowNull(false)
69 @Default(null)
70 @Is(
71 'UserNotificationSettingBlacklistOnMyVideo',
72 value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo')
73 )
74 @Column
75 blacklistOnMyVideo: UserNotificationSettingValue
76
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
95 @AllowNull(false)
96 @Default(null)
97 @Is(
98 'UserNotificationSettingNewUserRegistration',
99 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newUserRegistration')
100 )
101 @Column
102 newUserRegistration: UserNotificationSettingValue
103
104 @AllowNull(false)
105 @Default(null)
106 @Is(
107 'UserNotificationSettingNewFollow',
108 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newFollow')
109 )
110 @Column
111 newFollow: UserNotificationSettingValue
112
113 @AllowNull(false)
114 @Default(null)
115 @Is(
116 'UserNotificationSettingCommentMention',
117 value => throwIfNotValid(value, isUserNotificationSettingValid, 'commentMention')
118 )
119 @Column
120 commentMention: UserNotificationSettingValue
121
122 @ForeignKey(() => UserModel)
123 @Column
124 userId: number
125
126 @BelongsTo(() => UserModel, {
127 foreignKey: {
128 allowNull: false
129 },
130 onDelete: 'cascade'
131 })
132 User: UserModel
133
134 @CreatedAt
135 createdAt: Date
136
137 @UpdatedAt
138 updatedAt: Date
139
140 @AfterUpdate
141 @AfterDestroy
142 static removeTokenCache (instance: UserNotificationSettingModel) {
143 return clearCacheByUserId(instance.userId)
144 }
145
146 toFormattedJSON (): UserNotificationSetting {
147 return {
148 newCommentOnMyVideo: this.newCommentOnMyVideo,
149 newVideoFromSubscription: this.newVideoFromSubscription,
150 videoAbuseAsModerator: this.videoAbuseAsModerator,
151 videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
152 blacklistOnMyVideo: this.blacklistOnMyVideo,
153 myVideoPublished: this.myVideoPublished,
154 myVideoImportFinished: this.myVideoImportFinished,
155 newUserRegistration: this.newUserRegistration,
156 commentMention: this.commentMention,
157 newFollow: this.newFollow
158 }
159 }
160 }