diff options
Diffstat (limited to 'server/lib/activitypub/send/send-update.ts')
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 9baf13a87..48bbbcac1 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -1,56 +1,52 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityUpdate } from '../../../../shared/models/activitypub' | 2 | import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub' |
3 | import { AccountModel } from '../../../models/account/account' | 3 | import { VideoPrivacy } from '../../../../shared/models/videos' |
4 | import { ActorModel } from '../../../models/activitypub/actor' | ||
4 | import { VideoModel } from '../../../models/video/video' | 5 | import { VideoModel } from '../../../models/video/video' |
5 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
6 | import { VideoChannelShareModel } from '../../../models/video/video-channel-share' | ||
7 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
8 | import { getUpdateActivityPubUrl } from '../url' | 7 | import { getUpdateActivityPubUrl } from '../url' |
9 | import { broadcastToFollowers, getAudience } from './misc' | 8 | import { broadcastToFollowers, getAudience } from './misc' |
10 | 9 | ||
11 | async function sendUpdateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { | ||
12 | const byAccount = videoChannel.Account | ||
13 | |||
14 | const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString()) | ||
15 | const videoChannelObject = videoChannel.toActivityPubObject() | ||
16 | const data = await updateActivityData(url, byAccount, videoChannelObject, t) | ||
17 | |||
18 | const accountsInvolved = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t) | ||
19 | accountsInvolved.push(byAccount) | ||
20 | |||
21 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) | ||
22 | } | ||
23 | |||
24 | async function sendUpdateVideo (video: VideoModel, t: Transaction) { | 10 | async function sendUpdateVideo (video: VideoModel, t: Transaction) { |
25 | const byAccount = video.VideoChannel.Account | 11 | const byActor = video.VideoChannel.Account.Actor |
26 | 12 | ||
27 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) | 13 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) |
28 | const videoObject = video.toActivityPubObject() | 14 | const videoObject = video.toActivityPubObject() |
29 | const data = await updateActivityData(url, byAccount, videoObject, t) | 15 | const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) |
16 | |||
17 | const data = await updateActivityData(url, byActor, videoObject, t, audience) | ||
30 | 18 | ||
31 | const accountsInvolved = await VideoShareModel.loadAccountsByShare(video.id, t) | 19 | const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) |
32 | accountsInvolved.push(byAccount) | 20 | actorsInvolved.push(byActor) |
33 | 21 | ||
34 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) | 22 | return broadcastToFollowers(data, byActor, actorsInvolved, t) |
35 | } | 23 | } |
36 | 24 | ||
37 | // --------------------------------------------------------------------------- | 25 | // --------------------------------------------------------------------------- |
38 | 26 | ||
39 | export { | 27 | export { |
40 | sendUpdateVideoChannel, | ||
41 | sendUpdateVideo | 28 | sendUpdateVideo |
42 | } | 29 | } |
43 | 30 | ||
44 | // --------------------------------------------------------------------------- | 31 | // --------------------------------------------------------------------------- |
45 | 32 | ||
46 | async function updateActivityData (url: string, byAccount: AccountModel, object: any, t: Transaction): Promise<ActivityUpdate> { | 33 | async function updateActivityData ( |
47 | const { to, cc } = await getAudience(byAccount, t) | 34 | url: string, |
35 | byActor: ActorModel, | ||
36 | object: any, | ||
37 | t: Transaction, | ||
38 | audience?: ActivityAudience | ||
39 | ): Promise<ActivityUpdate> { | ||
40 | if (!audience) { | ||
41 | audience = await getAudience(byActor, t) | ||
42 | } | ||
43 | |||
48 | return { | 44 | return { |
49 | type: 'Update', | 45 | type: 'Update', |
50 | id: url, | 46 | id: url, |
51 | actor: byAccount.url, | 47 | actor: byActor.url, |
52 | to, | 48 | to: audience.to, |
53 | cc, | 49 | cc: audience.cc, |
54 | object | 50 | object |
55 | } | 51 | } |
56 | } | 52 | } |