|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- import { type UserNotificationSetting, type UserNotificationSettingValueType } from '@peertube/peertube-models'
- import { TokensCache } from '@server/lib/auth/tokens-cache.js'
- import { MNotificationSettingFormattable } from '@server/types/models/index.js'
- import {
- AfterDestroy,
- AfterUpdate,
- AllowNull,
- BelongsTo,
- Column,
- CreatedAt,
- Default,
- ForeignKey,
- Is, Table,
- UpdatedAt
- } from 'sequelize-typescript'
- import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications.js'
- import { SequelizeModel, throwIfNotValid } from '../shared/index.js'
- import { UserModel } from './user.js'
-
- @Table({
- tableName: 'userNotificationSetting',
- indexes: [
- {
- fields: [ 'userId' ],
- unique: true
- }
- ]
- })
- export class UserNotificationSettingModel extends SequelizeModel<UserNotificationSettingModel> {
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingNewVideoFromSubscription',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'newVideoFromSubscription')
- )
- @Column
- newVideoFromSubscription: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingNewCommentOnMyVideo',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'newCommentOnMyVideo')
- )
- @Column
- newCommentOnMyVideo: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingAbuseAsModerator',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseAsModerator')
- )
- @Column
- abuseAsModerator: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingVideoAutoBlacklistAsModerator',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAutoBlacklistAsModerator')
- )
- @Column
- videoAutoBlacklistAsModerator: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingBlacklistOnMyVideo',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo')
- )
- @Column
- blacklistOnMyVideo: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingMyVideoPublished',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoPublished')
- )
- @Column
- myVideoPublished: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingMyVideoImportFinished',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoImportFinished')
- )
- @Column
- myVideoImportFinished: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingNewUserRegistration',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'newUserRegistration')
- )
- @Column
- newUserRegistration: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingNewInstanceFollower',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'newInstanceFollower')
- )
- @Column
- newInstanceFollower: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingNewInstanceFollower',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'autoInstanceFollowing')
- )
- @Column
- autoInstanceFollowing: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingNewFollow',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'newFollow')
- )
- @Column
- newFollow: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingCommentMention',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'commentMention')
- )
- @Column
- commentMention: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingAbuseStateChange',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseStateChange')
- )
- @Column
- abuseStateChange: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingAbuseNewMessage',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseNewMessage')
- )
- @Column
- abuseNewMessage: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingNewPeerTubeVersion',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPeerTubeVersion')
- )
- @Column
- newPeerTubeVersion: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingNewPeerPluginVersion',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPluginVersion')
- )
- @Column
- newPluginVersion: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingMyVideoStudioEditionFinished',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoStudioEditionFinished')
- )
- @Column
- myVideoStudioEditionFinished: UserNotificationSettingValueType
-
- @AllowNull(false)
- @Default(null)
- @Is(
- 'UserNotificationSettingTranscriptionGeneratedForOwner',
- value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoTranscriptionGenerated')
- )
- @Column
- myVideoTranscriptionGenerated: UserNotificationSettingValueType
-
- @ForeignKey(() => UserModel)
- @Column
- userId: number
-
- @BelongsTo(() => UserModel, {
- foreignKey: {
- allowNull: false
- },
- onDelete: 'cascade'
- })
- User: Awaited<UserModel>
-
- @CreatedAt
- createdAt: Date
-
- @UpdatedAt
- updatedAt: Date
-
- @AfterUpdate
- @AfterDestroy
- static removeTokenCache (instance: UserNotificationSettingModel) {
- return TokensCache.Instance.clearCacheByUserId(instance.userId)
- }
-
- static updateUserSettings (settings: UserNotificationSetting, userId: number) {
- const query = {
- where: {
- userId
- }
- }
-
- return UserNotificationSettingModel.update(settings, query)
- }
-
- toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
- return {
- newCommentOnMyVideo: this.newCommentOnMyVideo,
- newVideoFromSubscription: this.newVideoFromSubscription,
- abuseAsModerator: this.abuseAsModerator,
- videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
- blacklistOnMyVideo: this.blacklistOnMyVideo,
- myVideoPublished: this.myVideoPublished,
- myVideoImportFinished: this.myVideoImportFinished,
- newUserRegistration: this.newUserRegistration,
- commentMention: this.commentMention,
- newFollow: this.newFollow,
- newInstanceFollower: this.newInstanceFollower,
- autoInstanceFollowing: this.autoInstanceFollowing,
- abuseNewMessage: this.abuseNewMessage,
- abuseStateChange: this.abuseStateChange,
- newPeerTubeVersion: this.newPeerTubeVersion,
- myVideoStudioEditionFinished: this.myVideoStudioEditionFinished,
- myVideoTranscriptionGenerated: this.myVideoTranscriptionGenerated,
- newPluginVersion: this.newPluginVersion
- }
- }
- }
|