]>
Commit | Line | Data |
---|---|---|
54141398 | 1 | import { Transaction } from 'sequelize' |
7acee6f1 | 2 | import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub' |
50d6de9c | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
3fd3ab2d | 4 | import { VideoModel } from '../../../models/video/video' |
4ba3b8ea | 5 | import { VideoShareModel } from '../../../models/video/video-share' |
e251f170 C |
6 | import { broadcastToFollowers } from './utils' |
7 | import { getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience' | |
8e0fd45e | 8 | import { logger } from '../../../helpers/logger' |
54141398 | 9 | |
07197db4 | 10 | async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { |
7acee6f1 | 11 | const announcedObject = video.url |
54141398 | 12 | |
50d6de9c | 13 | const accountsToForwardView = await getActorsInvolvedInVideo(video, t) |
4e50b6a1 | 14 | const audience = getObjectFollowersAudience(accountsToForwardView) |
2186386c | 15 | return announceActivityData(videoShare.url, byActor, announcedObject, audience) |
4e50b6a1 C |
16 | } |
17 | ||
07197db4 C |
18 | async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { |
19 | const data = await buildVideoAnnounce(byActor, videoShare, video, t) | |
4e50b6a1 | 20 | |
8e0fd45e C |
21 | logger.info('Creating job to send announce %s.', videoShare.url) |
22 | ||
5cf84858 C |
23 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
24 | const followersException = [ byActor ] | |
25 | ||
26 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) | |
54141398 C |
27 | } |
28 | ||
2186386c C |
29 | function announceActivityData (url: string, byActor: ActorModel, object: string, audience?: ActivityAudience): ActivityAnnounce { |
30 | if (!audience) audience = getAudience(byActor) | |
4e50b6a1 | 31 | |
3fd3ab2d | 32 | return { |
54141398 | 33 | type: 'Announce', |
4e50b6a1 C |
34 | to: audience.to, |
35 | cc: audience.cc, | |
54141398 | 36 | id: url, |
50d6de9c | 37 | actor: byActor.url, |
54141398 C |
38 | object |
39 | } | |
54141398 | 40 | } |
e71bcc0f C |
41 | |
42 | // --------------------------------------------------------------------------- | |
43 | ||
44 | export { | |
07197db4 | 45 | sendVideoAnnounce, |
4e50b6a1 | 46 | announceActivityData, |
07197db4 | 47 | buildVideoAnnounce |
e71bcc0f | 48 | } |