Split types and typings
[oweals/peertube.git] / server / types / models / user / user-notification.ts
1 import { UserNotificationModel } from '../../../models/account/user-notification'
2 import { PickWith, PickWithOpt } from '../../utils'
3 import { VideoModel } from '../../../models/video/video'
4 import { ActorModel } from '../../../models/activitypub/actor'
5 import { ServerModel } from '../../../models/server/server'
6 import { AvatarModel } from '../../../models/avatar/avatar'
7 import { VideoChannelModel } from '../../../models/video/video-channel'
8 import { AccountModel } from '../../../models/account/account'
9 import { VideoCommentModel } from '../../../models/video/video-comment'
10 import { VideoAbuseModel } from '../../../models/video/video-abuse'
11 import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
12 import { VideoImportModel } from '../../../models/video/video-import'
13 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
14
15 type Use<K extends keyof UserNotificationModel, M> = PickWith<UserNotificationModel, K, M>
16
17 // ############################################################################
18
19 export module UserNotificationIncludes {
20
21   export type VideoInclude = Pick<VideoModel, 'id' | 'uuid' | 'name'>
22   export type VideoIncludeChannel =
23     VideoInclude &
24     PickWith<VideoModel, 'VideoChannel', VideoChannelIncludeActor>
25
26   export type ActorInclude =
27     Pick<ActorModel, 'preferredUsername' | 'getHost'> &
28     PickWith<ActorModel, 'Avatar', Pick<AvatarModel, 'filename' | 'getStaticPath'>> &
29     PickWith<ActorModel, 'Server', Pick<ServerModel, 'host'>>
30
31   export type VideoChannelInclude = Pick<VideoChannelModel, 'id' | 'name' | 'getDisplayName'>
32   export type VideoChannelIncludeActor =
33     VideoChannelInclude &
34     PickWith<VideoChannelModel, 'Actor', ActorInclude>
35
36   export type AccountInclude = Pick<AccountModel, 'id' | 'name' | 'getDisplayName'>
37   export type AccountIncludeActor =
38     AccountInclude &
39     PickWith<AccountModel, 'Actor', ActorInclude>
40
41   export type VideoCommentInclude =
42     Pick<VideoCommentModel, 'id' | 'originCommentId' | 'getThreadId'> &
43     PickWith<VideoCommentModel, 'Account', AccountIncludeActor> &
44     PickWith<VideoCommentModel, 'Video', VideoInclude>
45
46   export type VideoAbuseInclude =
47     Pick<VideoAbuseModel, 'id'> &
48     PickWith<VideoAbuseModel, 'Video', VideoInclude>
49
50   export type VideoBlacklistInclude =
51     Pick<VideoBlacklistModel, 'id'> &
52     PickWith<VideoAbuseModel, 'Video', VideoInclude>
53
54   export type VideoImportInclude =
55     Pick<VideoImportModel, 'id' | 'magnetUri' | 'targetUrl' | 'torrentName'> &
56     PickWith<VideoImportModel, 'Video', VideoInclude>
57
58   export type ActorFollower =
59     Pick<ActorModel, 'preferredUsername' | 'getHost'> &
60     PickWith<ActorModel, 'Account', AccountInclude> &
61     PickWith<ActorModel, 'Server', Pick<ServerModel, 'host'>> &
62     PickWithOpt<ActorModel, 'Avatar', Pick<AvatarModel, 'filename' | 'getStaticPath'>>
63
64   export type ActorFollowing =
65     Pick<ActorModel, 'preferredUsername' | 'type' | 'getHost'> &
66     PickWith<ActorModel, 'VideoChannel', VideoChannelInclude> &
67     PickWith<ActorModel, 'Account', AccountInclude> &
68     PickWith<ActorModel, 'Server', Pick<ServerModel, 'host'>>
69
70   export type ActorFollowInclude =
71     Pick<ActorFollowModel, 'id' | 'state'> &
72     PickWith<ActorFollowModel, 'ActorFollower', ActorFollower> &
73     PickWith<ActorFollowModel, 'ActorFollowing', ActorFollowing>
74 }
75
76 // ############################################################################
77
78 export type MUserNotification =
79   Omit<UserNotificationModel, 'User' | 'Video' | 'Comment' | 'VideoAbuse' | 'VideoBlacklist' |
80   'VideoImport' | 'Account' | 'ActorFollow'>
81
82 // ############################################################################
83
84 export type UserNotificationModelForApi =
85   MUserNotification &
86   Use<'Video', UserNotificationIncludes.VideoIncludeChannel> &
87   Use<'Comment', UserNotificationIncludes.VideoCommentInclude> &
88   Use<'VideoAbuse', UserNotificationIncludes.VideoAbuseInclude> &
89   Use<'VideoBlacklist', UserNotificationIncludes.VideoBlacklistInclude> &
90   Use<'VideoImport', UserNotificationIncludes.VideoImportInclude> &
91   Use<'ActorFollow', UserNotificationIncludes.ActorFollowInclude> &
92   Use<'Account', UserNotificationIncludes.AccountIncludeActor>