2
1

send-announce.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { Transaction } from 'sequelize'
  2. import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub'
  3. import { ActorModel } from '../../../models/activitypub/actor'
  4. import { VideoModel } from '../../../models/video/video'
  5. import { VideoShareModel } from '../../../models/video/video-share'
  6. import { broadcastToFollowers } from './utils'
  7. import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf } from '../audience'
  8. import { logger } from '../../../helpers/logger'
  9. async function buildAnnounceWithVideoAudience (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
  10. const announcedObject = video.url
  11. const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
  12. const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo)
  13. const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience)
  14. return { activity, actorsInvolvedInVideo }
  15. }
  16. async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
  17. const { activity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t)
  18. logger.info('Creating job to send announce %s.', videoShare.url)
  19. const followersException = [ byActor ]
  20. return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, t, followersException)
  21. }
  22. function buildAnnounceActivity (url: string, byActor: ActorModel, object: string, audience?: ActivityAudience): ActivityAnnounce {
  23. if (!audience) audience = getAudience(byActor)
  24. return audiencify({
  25. type: 'Announce' as 'Announce',
  26. id: url,
  27. actor: byActor.url,
  28. object
  29. }, audience)
  30. }
  31. // ---------------------------------------------------------------------------
  32. export {
  33. sendVideoAnnounce,
  34. buildAnnounceActivity,
  35. buildAnnounceWithVideoAudience
  36. }