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