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