user-notification.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. type Use<K extends keyof UserNotificationModel, M> = PickWith<UserNotificationModel, K, M>
  15. // ############################################################################
  16. export namespace UserNotificationIncludes {
  17. export type VideoInclude = Pick<VideoModel, 'id' | 'uuid' | 'name'>
  18. export type VideoIncludeChannel = VideoInclude &
  19. PickWith<VideoModel, 'VideoChannel', VideoChannelIncludeActor>
  20. export type ActorInclude = Pick<ActorModel, 'preferredUsername' | 'getHost'> &
  21. PickWith<ActorModel, 'Avatar', Pick<AvatarModel, 'filename' | 'getStaticPath'>> &
  22. PickWith<ActorModel, 'Server', Pick<ServerModel, 'host'>>
  23. export type VideoChannelInclude = Pick<VideoChannelModel, 'id' | 'name' | 'getDisplayName'>
  24. export type VideoChannelIncludeActor = VideoChannelInclude &
  25. PickWith<VideoChannelModel, 'Actor', ActorInclude>
  26. export type AccountInclude = Pick<AccountModel, 'id' | 'name' | 'getDisplayName'>
  27. export type AccountIncludeActor = AccountInclude &
  28. PickWith<AccountModel, 'Actor', ActorInclude>
  29. export type VideoCommentInclude = Pick<VideoCommentModel, 'id' | 'originCommentId' | 'getThreadId'> &
  30. PickWith<VideoCommentModel, 'Account', AccountIncludeActor> &
  31. PickWith<VideoCommentModel, 'Video', VideoInclude>
  32. export type VideoAbuseInclude = Pick<VideoAbuseModel, 'id'> &
  33. PickWith<VideoAbuseModel, 'Video', VideoInclude>
  34. export type VideoBlacklistInclude = Pick<VideoBlacklistModel, 'id'> &
  35. PickWith<VideoAbuseModel, 'Video', VideoInclude>
  36. export type VideoImportInclude = Pick<VideoImportModel, 'id' | 'magnetUri' | 'targetUrl' | 'torrentName'> &
  37. PickWith<VideoImportModel, 'Video', VideoInclude>
  38. export type ActorFollower = Pick<ActorModel, 'preferredUsername' | 'getHost'> &
  39. PickWith<ActorModel, 'Account', AccountInclude> &
  40. PickWith<ActorModel, 'Server', Pick<ServerModel, 'host'>> &
  41. PickWithOpt<ActorModel, 'Avatar', Pick<AvatarModel, 'filename' | 'getStaticPath'>>
  42. export type ActorFollowing = Pick<ActorModel, 'preferredUsername' | 'type' | 'getHost'> &
  43. PickWith<ActorModel, 'VideoChannel', VideoChannelInclude> &
  44. PickWith<ActorModel, 'Account', AccountInclude> &
  45. PickWith<ActorModel, 'Server', Pick<ServerModel, 'host'>>
  46. export type ActorFollowInclude = Pick<ActorFollowModel, 'id' | 'state'> &
  47. PickWith<ActorFollowModel, 'ActorFollower', ActorFollower> &
  48. PickWith<ActorFollowModel, 'ActorFollowing', ActorFollowing>
  49. }
  50. // ############################################################################
  51. export type MUserNotification = Omit<UserNotificationModel, 'User' | 'Video' | 'Comment' | 'VideoAbuse' | 'VideoBlacklist' |
  52. 'VideoImport' | 'Account' | 'ActorFollow'>
  53. // ############################################################################
  54. export type UserNotificationModelForApi = MUserNotification &
  55. Use<'Video', UserNotificationIncludes.VideoIncludeChannel> &
  56. Use<'Comment', UserNotificationIncludes.VideoCommentInclude> &
  57. Use<'VideoAbuse', UserNotificationIncludes.VideoAbuseInclude> &
  58. Use<'VideoBlacklist', UserNotificationIncludes.VideoBlacklistInclude> &
  59. Use<'VideoImport', UserNotificationIncludes.VideoImportInclude> &
  60. Use<'ActorFollow', UserNotificationIncludes.ActorFollowInclude> &
  61. Use<'Account', UserNotificationIncludes.AccountIncludeActor>