2018-12-26 10:36:24 +01:00
|
|
|
import {
|
|
|
|
AfterDestroy,
|
|
|
|
AfterUpdate,
|
|
|
|
AllowNull,
|
|
|
|
BelongsTo,
|
|
|
|
Column,
|
|
|
|
CreatedAt,
|
|
|
|
Default,
|
|
|
|
ForeignKey,
|
|
|
|
Is,
|
|
|
|
Model,
|
|
|
|
Table,
|
|
|
|
UpdatedAt
|
|
|
|
} from 'sequelize-typescript'
|
2021-03-12 15:20:46 +01:00
|
|
|
import { TokensCache } from '@server/lib/auth/tokens-cache'
|
2020-07-27 16:26:25 +02:00
|
|
|
import { MNotificationSettingFormattable } from '@server/types/models'
|
2021-12-16 18:04:16 +01:00
|
|
|
import { AttributesOnly } from '@shared/typescript-utils'
|
2018-12-26 10:36:24 +01:00
|
|
|
import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
|
2020-07-27 16:26:25 +02:00
|
|
|
import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
|
2023-01-10 11:09:30 +01:00
|
|
|
import { throwIfNotValid } from '../shared'
|
2020-07-27 16:26:25 +02:00
|
|
|
import { UserModel } from './user'
|
2018-12-26 10:36:24 +01:00
|
|
|
|
|
|
|
@Table({
|
|
|
|
tableName: 'userNotificationSetting',
|
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
fields: [ 'userId' ],
|
|
|
|
unique: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2021-05-12 14:09:04 +02:00
|
|
|
export class UserNotificationSettingModel extends Model<Partial<AttributesOnly<UserNotificationSettingModel>>> {
|
2018-12-26 10:36:24 +01:00
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingNewVideoFromSubscription',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'newVideoFromSubscription')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
newVideoFromSubscription: UserNotificationSettingValue
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingNewCommentOnMyVideo',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'newCommentOnMyVideo')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
newCommentOnMyVideo: UserNotificationSettingValue
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
2020-07-07 14:34:16 +02:00
|
|
|
'UserNotificationSettingAbuseAsModerator',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseAsModerator')
|
2018-12-26 10:36:24 +01:00
|
|
|
)
|
|
|
|
@Column
|
2020-07-07 14:34:16 +02:00
|
|
|
abuseAsModerator: UserNotificationSettingValue
|
2018-12-26 10:36:24 +01:00
|
|
|
|
2019-04-02 11:26:47 +02:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingVideoAutoBlacklistAsModerator',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAutoBlacklistAsModerator')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
videoAutoBlacklistAsModerator: UserNotificationSettingValue
|
|
|
|
|
2018-12-26 10:36:24 +01:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingBlacklistOnMyVideo',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
blacklistOnMyVideo: UserNotificationSettingValue
|
|
|
|
|
2019-01-02 16:37:43 +01:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingMyVideoPublished',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoPublished')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
myVideoPublished: UserNotificationSettingValue
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingMyVideoImportFinished',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoImportFinished')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
myVideoImportFinished: UserNotificationSettingValue
|
|
|
|
|
2019-01-04 08:56:20 +01:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingNewUserRegistration',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'newUserRegistration')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
newUserRegistration: UserNotificationSettingValue
|
|
|
|
|
2019-04-08 17:26:01 +02:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingNewInstanceFollower',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'newInstanceFollower')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
newInstanceFollower: UserNotificationSettingValue
|
|
|
|
|
2019-08-30 16:50:12 +02:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingNewInstanceFollower',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'autoInstanceFollowing')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
autoInstanceFollowing: UserNotificationSettingValue
|
|
|
|
|
2019-01-04 08:56:20 +01:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingNewFollow',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'newFollow')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
newFollow: UserNotificationSettingValue
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingCommentMention',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'commentMention')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
commentMention: UserNotificationSettingValue
|
|
|
|
|
2020-07-27 16:26:25 +02:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingAbuseStateChange',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseStateChange')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
abuseStateChange: UserNotificationSettingValue
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingAbuseNewMessage',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseNewMessage')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
abuseNewMessage: UserNotificationSettingValue
|
|
|
|
|
2021-03-11 16:54:52 +01:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingNewPeerTubeVersion',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPeerTubeVersion')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
newPeerTubeVersion: UserNotificationSettingValue
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
|
|
|
'UserNotificationSettingNewPeerPluginVersion',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPluginVersion')
|
|
|
|
)
|
|
|
|
@Column
|
|
|
|
newPluginVersion: UserNotificationSettingValue
|
|
|
|
|
2022-03-22 14:35:04 +01:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is(
|
2022-03-22 16:58:49 +01:00
|
|
|
'UserNotificationSettingMyVideoStudioEditionFinished',
|
|
|
|
value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoStudioEditionFinished')
|
2022-03-22 14:35:04 +01:00
|
|
|
)
|
|
|
|
@Column
|
2022-03-22 16:58:49 +01:00
|
|
|
myVideoStudioEditionFinished: UserNotificationSettingValue
|
2022-03-22 14:35:04 +01:00
|
|
|
|
2018-12-26 10:36:24 +01:00
|
|
|
@ForeignKey(() => UserModel)
|
|
|
|
@Column
|
|
|
|
userId: number
|
|
|
|
|
|
|
|
@BelongsTo(() => UserModel, {
|
|
|
|
foreignKey: {
|
|
|
|
allowNull: false
|
|
|
|
},
|
|
|
|
onDelete: 'cascade'
|
|
|
|
})
|
|
|
|
User: UserModel
|
|
|
|
|
|
|
|
@CreatedAt
|
|
|
|
createdAt: Date
|
|
|
|
|
|
|
|
@UpdatedAt
|
|
|
|
updatedAt: Date
|
|
|
|
|
|
|
|
@AfterUpdate
|
|
|
|
@AfterDestroy
|
|
|
|
static removeTokenCache (instance: UserNotificationSettingModel) {
|
2021-03-12 15:20:46 +01:00
|
|
|
return TokensCache.Instance.clearCacheByUserId(instance.userId)
|
2018-12-26 10:36:24 +01:00
|
|
|
}
|
|
|
|
|
2019-08-20 19:05:31 +02:00
|
|
|
toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
|
2018-12-26 10:36:24 +01:00
|
|
|
return {
|
|
|
|
newCommentOnMyVideo: this.newCommentOnMyVideo,
|
|
|
|
newVideoFromSubscription: this.newVideoFromSubscription,
|
2020-07-07 14:34:16 +02:00
|
|
|
abuseAsModerator: this.abuseAsModerator,
|
2019-04-02 11:26:47 +02:00
|
|
|
videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
|
2019-01-02 16:37:43 +01:00
|
|
|
blacklistOnMyVideo: this.blacklistOnMyVideo,
|
|
|
|
myVideoPublished: this.myVideoPublished,
|
2019-01-04 08:56:20 +01:00
|
|
|
myVideoImportFinished: this.myVideoImportFinished,
|
|
|
|
newUserRegistration: this.newUserRegistration,
|
|
|
|
commentMention: this.commentMention,
|
2019-04-08 17:26:01 +02:00
|
|
|
newFollow: this.newFollow,
|
2019-08-30 16:50:12 +02:00
|
|
|
newInstanceFollower: this.newInstanceFollower,
|
2020-07-27 16:26:25 +02:00
|
|
|
autoInstanceFollowing: this.autoInstanceFollowing,
|
|
|
|
abuseNewMessage: this.abuseNewMessage,
|
2021-03-11 16:54:52 +01:00
|
|
|
abuseStateChange: this.abuseStateChange,
|
|
|
|
newPeerTubeVersion: this.newPeerTubeVersion,
|
2022-03-22 16:58:49 +01:00
|
|
|
myVideoStudioEditionFinished: this.myVideoStudioEditionFinished,
|
2021-03-11 16:54:52 +01:00
|
|
|
newPluginVersion: this.newPluginVersion
|
2018-12-26 10:36:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|