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