]>
Commit | Line | Data |
---|---|---|
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 { getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience' | |
8 | ||
9 | async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { | |
10 | const announcedObject = video.url | |
11 | ||
12 | const accountsToForwardView = await getActorsInvolvedInVideo(video, t) | |
13 | const audience = getObjectFollowersAudience(accountsToForwardView) | |
14 | return announceActivityData(videoShare.url, byActor, announcedObject, t, audience) | |
15 | } | |
16 | ||
17 | async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { | |
18 | const data = await buildVideoAnnounce(byActor, videoShare, video, t) | |
19 | ||
20 | return broadcastToFollowers(data, byActor, [ byActor ], t) | |
21 | } | |
22 | ||
23 | async function announceActivityData ( | |
24 | url: string, | |
25 | byActor: ActorModel, | |
26 | object: string, | |
27 | t: Transaction, | |
28 | audience?: ActivityAudience | |
29 | ): Promise<ActivityAnnounce> { | |
30 | if (!audience) { | |
31 | audience = await getAudience(byActor, t) | |
32 | } | |
33 | ||
34 | return { | |
35 | type: 'Announce', | |
36 | to: audience.to, | |
37 | cc: audience.cc, | |
38 | id: url, | |
39 | actor: byActor.url, | |
40 | object | |
41 | } | |
42 | } | |
43 | ||
44 | // --------------------------------------------------------------------------- | |
45 | ||
46 | export { | |
47 | sendVideoAnnounce, | |
48 | announceActivityData, | |
49 | buildVideoAnnounce | |
50 | } |