]>
Commit | Line | Data |
---|---|---|
54141398 | 1 | import { Transaction } from 'sequelize' |
50d6de9c C |
2 | import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub' |
3 | import { VideoPrivacy } from '../../../../shared/models/videos' | |
2422c46b | 4 | import { AccountModel } from '../../../models/account/account' |
50d6de9c | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
3fd3ab2d | 6 | import { VideoModel } from '../../../models/video/video' |
2422c46b | 7 | import { VideoChannelModel } from '../../../models/video/video-channel' |
3fd3ab2d | 8 | import { VideoShareModel } from '../../../models/video/video-share' |
892211e8 | 9 | import { getUpdateActivityPubUrl } from '../url' |
e12a0092 | 10 | import { audiencify, broadcastToFollowers, getAudience } from './misc' |
54141398 | 11 | |
3fd3ab2d | 12 | async function sendUpdateVideo (video: VideoModel, t: Transaction) { |
50d6de9c | 13 | const byActor = video.VideoChannel.Account.Actor |
54141398 C |
14 | |
15 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) | |
16 | const videoObject = video.toActivityPubObject() | |
50d6de9c C |
17 | const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) |
18 | ||
19 | const data = await updateActivityData(url, byActor, videoObject, t, audience) | |
54141398 | 20 | |
50d6de9c C |
21 | const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) |
22 | actorsInvolved.push(byActor) | |
54141398 | 23 | |
50d6de9c | 24 | return broadcastToFollowers(data, byActor, actorsInvolved, t) |
54141398 C |
25 | } |
26 | ||
2422c46b C |
27 | async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) { |
28 | const byActor = accountOrChannel.Actor | |
265ba139 C |
29 | |
30 | const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString()) | |
2422c46b | 31 | const accountOrChannelObject = accountOrChannel.toActivityPubObject() |
265ba139 | 32 | const audience = await getAudience(byActor, t) |
2422c46b C |
33 | const data = await updateActivityData(url, byActor, accountOrChannelObject, t, audience) |
34 | ||
35 | let actorsInvolved: ActorModel[] | |
36 | if (accountOrChannel instanceof AccountModel) { | |
37 | // Actors that shared my videos are involved too | |
38 | actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t) | |
39 | } else { | |
40 | // Actors that shared videos of my channel are involved too | |
41 | actorsInvolved = await VideoShareModel.loadActorsByVideoChannel(accountOrChannel.id, t) | |
42 | } | |
265ba139 | 43 | |
265ba139 C |
44 | actorsInvolved.push(byActor) |
45 | ||
46 | return broadcastToFollowers(data, byActor, actorsInvolved, t) | |
47 | } | |
48 | ||
54141398 C |
49 | // --------------------------------------------------------------------------- |
50 | ||
51 | export { | |
2422c46b | 52 | sendUpdateActor, |
54141398 C |
53 | sendUpdateVideo |
54 | } | |
55 | ||
56 | // --------------------------------------------------------------------------- | |
57 | ||
50d6de9c C |
58 | async function updateActivityData ( |
59 | url: string, | |
60 | byActor: ActorModel, | |
61 | object: any, | |
62 | t: Transaction, | |
63 | audience?: ActivityAudience | |
64 | ): Promise<ActivityUpdate> { | |
65 | if (!audience) { | |
66 | audience = await getAudience(byActor, t) | |
67 | } | |
68 | ||
e12a0092 | 69 | return audiencify({ |
73c08093 | 70 | type: 'Update' as 'Update', |
54141398 | 71 | id: url, |
50d6de9c | 72 | actor: byActor.url, |
e12a0092 C |
73 | object: audiencify(object, audience) |
74 | }, audience) | |
54141398 | 75 | } |