diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-23 16:14:33 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-24 09:40:46 +0100 |
commit | a219c9100b3ce8774d454497d46be87465bf664e (patch) | |
tree | caa869e47919a9e23cc86dcece1100e239683b8c /server/lib/activitypub/send/send-update.ts | |
parent | 7e98a7df7d04e19ba67163a86c7b876d78d76839 (diff) | |
download | PeerTube-a219c9100b3ce8774d454497d46be87465bf664e.tar.gz PeerTube-a219c9100b3ce8774d454497d46be87465bf664e.tar.zst PeerTube-a219c9100b3ce8774d454497d46be87465bf664e.zip |
Refactor AP context builder
Diffstat (limited to 'server/lib/activitypub/send/send-update.ts')
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 7c9e72cbc..3577ece02 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -20,20 +20,20 @@ import { getUpdateActivityPubUrl } from '../url' | |||
20 | import { getActorsInvolvedInVideo } from './shared' | 20 | import { getActorsInvolvedInVideo } from './shared' |
21 | import { broadcastToFollowers, sendVideoRelatedActivity } from './shared/send-utils' | 21 | import { broadcastToFollowers, sendVideoRelatedActivity } from './shared/send-utils' |
22 | 22 | ||
23 | async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction, overrodeByActor?: MActor) { | 23 | async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, transaction: Transaction, overriddenByActor?: MActor) { |
24 | const video = videoArg as MVideoAP | 24 | const video = videoArg as MVideoAP |
25 | 25 | ||
26 | if (!video.hasPrivacyForFederation()) return undefined | 26 | if (!video.hasPrivacyForFederation()) return undefined |
27 | 27 | ||
28 | logger.info('Creating job to update video %s.', video.url) | 28 | logger.info('Creating job to update video %s.', video.url) |
29 | 29 | ||
30 | const byActor = overrodeByActor || video.VideoChannel.Account.Actor | 30 | const byActor = overriddenByActor || video.VideoChannel.Account.Actor |
31 | 31 | ||
32 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) | 32 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) |
33 | 33 | ||
34 | // Needed to build the AP object | 34 | // Needed to build the AP object |
35 | if (!video.VideoCaptions) { | 35 | if (!video.VideoCaptions) { |
36 | video.VideoCaptions = await video.$get('VideoCaptions', { transaction: t }) | 36 | video.VideoCaptions = await video.$get('VideoCaptions', { transaction }) |
37 | } | 37 | } |
38 | 38 | ||
39 | const videoObject = video.toActivityPubObject() | 39 | const videoObject = video.toActivityPubObject() |
@@ -41,13 +41,19 @@ async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction | |||
41 | 41 | ||
42 | const updateActivity = buildUpdateActivity(url, byActor, videoObject, audience) | 42 | const updateActivity = buildUpdateActivity(url, byActor, videoObject, audience) |
43 | 43 | ||
44 | const actorsInvolved = await getActorsInvolvedInVideo(video, t) | 44 | const actorsInvolved = await getActorsInvolvedInVideo(video, transaction) |
45 | if (overrodeByActor) actorsInvolved.push(overrodeByActor) | 45 | if (overriddenByActor) actorsInvolved.push(overriddenByActor) |
46 | 46 | ||
47 | return broadcastToFollowers(updateActivity, byActor, actorsInvolved, t) | 47 | return broadcastToFollowers({ |
48 | data: updateActivity, | ||
49 | byActor, | ||
50 | toFollowersOf: actorsInvolved, | ||
51 | contextType: 'Video', | ||
52 | transaction | ||
53 | }) | ||
48 | } | 54 | } |
49 | 55 | ||
50 | async function sendUpdateActor (accountOrChannel: MChannelDefault | MAccountDefault, t: Transaction) { | 56 | async function sendUpdateActor (accountOrChannel: MChannelDefault | MAccountDefault, transaction: Transaction) { |
51 | const byActor = accountOrChannel.Actor | 57 | const byActor = accountOrChannel.Actor |
52 | 58 | ||
53 | logger.info('Creating job to update actor %s.', byActor.url) | 59 | logger.info('Creating job to update actor %s.', byActor.url) |
@@ -60,15 +66,21 @@ async function sendUpdateActor (accountOrChannel: MChannelDefault | MAccountDefa | |||
60 | let actorsInvolved: MActor[] | 66 | let actorsInvolved: MActor[] |
61 | if (accountOrChannel instanceof AccountModel) { | 67 | if (accountOrChannel instanceof AccountModel) { |
62 | // Actors that shared my videos are involved too | 68 | // Actors that shared my videos are involved too |
63 | actorsInvolved = await VideoShareModel.loadActorsWhoSharedVideosOf(byActor.id, t) | 69 | actorsInvolved = await VideoShareModel.loadActorsWhoSharedVideosOf(byActor.id, transaction) |
64 | } else { | 70 | } else { |
65 | // Actors that shared videos of my channel are involved too | 71 | // Actors that shared videos of my channel are involved too |
66 | actorsInvolved = await VideoShareModel.loadActorsByVideoChannel(accountOrChannel.id, t) | 72 | actorsInvolved = await VideoShareModel.loadActorsByVideoChannel(accountOrChannel.id, transaction) |
67 | } | 73 | } |
68 | 74 | ||
69 | actorsInvolved.push(byActor) | 75 | actorsInvolved.push(byActor) |
70 | 76 | ||
71 | return broadcastToFollowers(updateActivity, byActor, actorsInvolved, t) | 77 | return broadcastToFollowers({ |
78 | data: updateActivity, | ||
79 | byActor, | ||
80 | toFollowersOf: actorsInvolved, | ||
81 | transaction, | ||
82 | contextType: 'Actor' | ||
83 | }) | ||
72 | } | 84 | } |
73 | 85 | ||
74 | async function sendUpdateCacheFile (byActor: MActorLight, redundancyModel: MVideoRedundancyVideo) { | 86 | async function sendUpdateCacheFile (byActor: MActorLight, redundancyModel: MVideoRedundancyVideo) { |
@@ -92,7 +104,7 @@ async function sendUpdateCacheFile (byActor: MActorLight, redundancyModel: MVide | |||
92 | return sendVideoRelatedActivity(activityBuilder, { byActor, video, contextType: 'CacheFile' }) | 104 | return sendVideoRelatedActivity(activityBuilder, { byActor, video, contextType: 'CacheFile' }) |
93 | } | 105 | } |
94 | 106 | ||
95 | async function sendUpdateVideoPlaylist (videoPlaylist: MVideoPlaylistFull, t: Transaction) { | 107 | async function sendUpdateVideoPlaylist (videoPlaylist: MVideoPlaylistFull, transaction: Transaction) { |
96 | if (videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) return undefined | 108 | if (videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) return undefined |
97 | 109 | ||
98 | const byActor = videoPlaylist.OwnerAccount.Actor | 110 | const byActor = videoPlaylist.OwnerAccount.Actor |
@@ -101,7 +113,7 @@ async function sendUpdateVideoPlaylist (videoPlaylist: MVideoPlaylistFull, t: Tr | |||
101 | 113 | ||
102 | const url = getUpdateActivityPubUrl(videoPlaylist.url, videoPlaylist.updatedAt.toISOString()) | 114 | const url = getUpdateActivityPubUrl(videoPlaylist.url, videoPlaylist.updatedAt.toISOString()) |
103 | 115 | ||
104 | const object = await videoPlaylist.toActivityPubObject(null, t) | 116 | const object = await videoPlaylist.toActivityPubObject(null, transaction) |
105 | const audience = getAudience(byActor, videoPlaylist.privacy === VideoPlaylistPrivacy.PUBLIC) | 117 | const audience = getAudience(byActor, videoPlaylist.privacy === VideoPlaylistPrivacy.PUBLIC) |
106 | 118 | ||
107 | const updateActivity = buildUpdateActivity(url, byActor, object, audience) | 119 | const updateActivity = buildUpdateActivity(url, byActor, object, audience) |
@@ -111,7 +123,13 @@ async function sendUpdateVideoPlaylist (videoPlaylist: MVideoPlaylistFull, t: Tr | |||
111 | 123 | ||
112 | if (videoPlaylist.VideoChannel) toFollowersOf.push(videoPlaylist.VideoChannel.Actor) | 124 | if (videoPlaylist.VideoChannel) toFollowersOf.push(videoPlaylist.VideoChannel.Actor) |
113 | 125 | ||
114 | return broadcastToFollowers(updateActivity, byActor, toFollowersOf, t) | 126 | return broadcastToFollowers({ |
127 | data: updateActivity, | ||
128 | byActor, | ||
129 | toFollowersOf, | ||
130 | transaction, | ||
131 | contextType: 'Playlist' | ||
132 | }) | ||
115 | } | 133 | } |
116 | 134 | ||
117 | // --------------------------------------------------------------------------- | 135 | // --------------------------------------------------------------------------- |