PeerTube/server/types/models/user/user.ts

90 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-04-06 17:01:35 +02:00
import { AccountModel } from '@server/models/account/account'
2021-05-11 11:15:29 +02:00
import { UserModel } from '@server/models/user/user'
2021-04-06 17:01:35 +02:00
import { MVideoPlaylist } from '@server/types/models'
import { PickWith, PickWithOpt } from '@shared/typescript-utils'
2019-08-20 19:05:31 +02:00
import {
MAccount,
MAccountDefault,
MAccountDefaultChannelDefault,
MAccountFormattable,
MAccountId,
MAccountIdActorId,
MAccountUrl
} from '../account'
import { MChannelFormattable } from '../video/video-channels'
2021-04-06 17:01:35 +02:00
import { MNotificationSetting, MNotificationSettingFormattable } from './user-notification-setting'
2019-08-15 11:53:26 +02:00
2019-08-20 13:52:49 +02:00
type Use<K extends keyof UserModel, M> = PickWith<UserModel, K, M>
// ############################################################################
2019-08-15 11:53:26 +02:00
export type MUser = Omit<UserModel, 'Account' | 'NotificationSetting' | 'VideoImports' | 'OAuthTokens'>
2019-08-20 13:52:49 +02:00
// ############################################################################
2019-08-20 19:05:31 +02:00
export type MUserQuotaUsed = MUser & { videoQuotaUsed?: number, videoQuotaUsedDaily?: number }
2019-08-15 11:53:26 +02:00
export type MUserId = Pick<UserModel, 'id'>
2019-08-20 13:52:49 +02:00
// ############################################################################
2019-08-15 11:53:26 +02:00
2019-08-20 13:52:49 +02:00
// With account
2020-01-31 16:56:52 +01:00
export type MUserAccountId =
MUser &
2019-08-20 13:52:49 +02:00
Use<'Account', MAccountId>
2020-01-31 16:56:52 +01:00
export type MUserAccountUrl =
MUser &
2019-08-20 13:52:49 +02:00
Use<'Account', MAccountUrl & MAccountIdActorId>
2019-08-15 11:53:26 +02:00
2020-01-31 16:56:52 +01:00
export type MUserAccount =
MUser &
2019-08-20 13:52:49 +02:00
Use<'Account', MAccount>
2019-08-15 11:53:26 +02:00
2020-01-31 16:56:52 +01:00
export type MUserAccountDefault =
MUser &
2019-08-20 13:52:49 +02:00
Use<'Account', MAccountDefault>
2019-08-15 11:53:26 +02:00
2019-08-20 13:52:49 +02:00
// With channel
2019-08-15 11:53:26 +02:00
2020-01-31 16:56:52 +01:00
export type MUserNotifSettingChannelDefault =
MUser &
2019-08-20 13:52:49 +02:00
Use<'NotificationSetting', MNotificationSetting> &
Use<'Account', MAccountDefaultChannelDefault>
2019-08-15 11:53:26 +02:00
2019-08-20 13:52:49 +02:00
// With notification settings
2019-08-15 11:53:26 +02:00
2020-01-31 16:56:52 +01:00
export type MUserWithNotificationSetting =
MUser &
2019-08-20 13:52:49 +02:00
Use<'NotificationSetting', MNotificationSetting>
2020-01-31 16:56:52 +01:00
export type MUserNotifSettingAccount =
MUser &
2019-08-20 13:52:49 +02:00
Use<'NotificationSetting', MNotificationSetting> &
Use<'Account', MAccount>
// Default scope
2020-01-31 16:56:52 +01:00
export type MUserDefault =
MUser &
2019-08-20 13:52:49 +02:00
Use<'NotificationSetting', MNotificationSetting> &
Use<'Account', MAccountDefault>
2019-08-20 19:05:31 +02:00
// ############################################################################
// Format for API or AP object
type MAccountWithChannels = MAccountFormattable & PickWithOpt<AccountModel, 'VideoChannels', MChannelFormattable[]>
2020-01-31 16:56:52 +01:00
type MAccountWithChannelsAndSpecialPlaylists =
MAccountWithChannels &
PickWithOpt<AccountModel, 'VideoPlaylists', MVideoPlaylist[]>
2020-01-31 16:56:52 +01:00
export type MUserFormattable =
MUserQuotaUsed &
Use<'Account', MAccountWithChannels> &
2019-08-20 19:05:31 +02:00
PickWithOpt<UserModel, 'NotificationSetting', MNotificationSettingFormattable>
2020-01-31 16:56:52 +01:00
export type MMyUserFormattable =
MUserFormattable &
Use<'Account', MAccountWithChannelsAndSpecialPlaylists>