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