]>
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 | ||
50d6de9c | 23 | return broadcastToFollowers(data, byActor, [ byActor ], t) |
54141398 C |
24 | } |
25 | ||
2186386c C |
26 | function announceActivityData (url: string, byActor: ActorModel, object: string, audience?: ActivityAudience): ActivityAnnounce { |
27 | if (!audience) audience = getAudience(byActor) | |
4e50b6a1 | 28 | |
3fd3ab2d | 29 | return { |
54141398 | 30 | type: 'Announce', |
4e50b6a1 C |
31 | to: audience.to, |
32 | cc: audience.cc, | |
54141398 | 33 | id: url, |
50d6de9c | 34 | actor: byActor.url, |
54141398 C |
35 | object |
36 | } | |
54141398 | 37 | } |
e71bcc0f C |
38 | |
39 | // --------------------------------------------------------------------------- | |
40 | ||
41 | export { | |
07197db4 | 42 | sendVideoAnnounce, |
4e50b6a1 | 43 | announceActivityData, |
07197db4 | 44 | buildVideoAnnounce |
e71bcc0f | 45 | } |