diff options
Diffstat (limited to 'server/lib/activitypub/send/send-undo.ts')
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 63 |
1 files changed, 40 insertions, 23 deletions
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 30d0fd98b..a50673c79 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -13,12 +13,13 @@ import { VideoModel } from '../../../models/video/video' | |||
13 | import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' | 13 | import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' |
14 | import { broadcastToFollowers, unicastTo } from './utils' | 14 | import { broadcastToFollowers, unicastTo } from './utils' |
15 | import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience' | 15 | import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience' |
16 | import { createActivityData, createDislikeActivityData } from './send-create' | 16 | import { buildCreateActivity, buildDislikeActivity } from './send-create' |
17 | import { followActivityData } from './send-follow' | 17 | import { buildFollowActivity } from './send-follow' |
18 | import { likeActivityData } from './send-like' | 18 | import { buildLikeActivity } from './send-like' |
19 | import { VideoShareModel } from '../../../models/video/video-share' | 19 | import { VideoShareModel } from '../../../models/video/video-share' |
20 | import { buildVideoAnnounce } from './send-announce' | 20 | import { buildAnnounceWithVideoAudience } from './send-announce' |
21 | import { logger } from '../../../helpers/logger' | 21 | import { logger } from '../../../helpers/logger' |
22 | import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' | ||
22 | 23 | ||
23 | async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { | 24 | async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { |
24 | const me = actorFollow.ActorFollower | 25 | const me = actorFollow.ActorFollower |
@@ -32,10 +33,10 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { | |||
32 | const followUrl = getActorFollowActivityPubUrl(actorFollow) | 33 | const followUrl = getActorFollowActivityPubUrl(actorFollow) |
33 | const undoUrl = getUndoActivityPubUrl(followUrl) | 34 | const undoUrl = getUndoActivityPubUrl(followUrl) |
34 | 35 | ||
35 | const object = followActivityData(followUrl, me, following) | 36 | const followActivity = buildFollowActivity(followUrl, me, following) |
36 | const data = undoActivityData(undoUrl, me, object) | 37 | const undoActivity = undoActivityData(undoUrl, me, followActivity) |
37 | 38 | ||
38 | return unicastTo(data, me, following.inboxUrl) | 39 | return unicastTo(undoActivity, me, following.inboxUrl) |
39 | } | 40 | } |
40 | 41 | ||
41 | async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) { | 42 | async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) { |
@@ -45,21 +46,21 @@ async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transact | |||
45 | const undoUrl = getUndoActivityPubUrl(likeUrl) | 46 | const undoUrl = getUndoActivityPubUrl(likeUrl) |
46 | 47 | ||
47 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | 48 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
48 | const object = likeActivityData(likeUrl, byActor, video) | 49 | const likeActivity = buildLikeActivity(likeUrl, byActor, video) |
49 | 50 | ||
50 | // Send to origin | 51 | // Send to origin |
51 | if (video.isOwned() === false) { | 52 | if (video.isOwned() === false) { |
52 | const audience = getVideoAudience(video, actorsInvolvedInVideo) | 53 | const audience = getVideoAudience(video, actorsInvolvedInVideo) |
53 | const data = undoActivityData(undoUrl, byActor, object, audience) | 54 | const undoActivity = undoActivityData(undoUrl, byActor, likeActivity, audience) |
54 | 55 | ||
55 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 56 | return unicastTo(undoActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
56 | } | 57 | } |
57 | 58 | ||
58 | const audience = getObjectFollowersAudience(actorsInvolvedInVideo) | 59 | const audience = getObjectFollowersAudience(actorsInvolvedInVideo) |
59 | const data = undoActivityData(undoUrl, byActor, object, audience) | 60 | const undoActivity = undoActivityData(undoUrl, byActor, likeActivity, audience) |
60 | 61 | ||
61 | const followersException = [ byActor ] | 62 | const followersException = [ byActor ] |
62 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) | 63 | return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) |
63 | } | 64 | } |
64 | 65 | ||
65 | async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) { | 66 | async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) { |
@@ -69,20 +70,20 @@ async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Trans | |||
69 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | 70 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) |
70 | 71 | ||
71 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | 72 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
72 | const dislikeActivity = createDislikeActivityData(byActor, video) | 73 | const dislikeActivity = buildDislikeActivity(byActor, video) |
73 | const object = createActivityData(dislikeUrl, byActor, dislikeActivity) | 74 | const createDislikeActivity = buildCreateActivity(dislikeUrl, byActor, dislikeActivity) |
74 | 75 | ||
75 | if (video.isOwned() === false) { | 76 | if (video.isOwned() === false) { |
76 | const audience = getVideoAudience(video, actorsInvolvedInVideo) | 77 | const audience = getVideoAudience(video, actorsInvolvedInVideo) |
77 | const data = undoActivityData(undoUrl, byActor, object, audience) | 78 | const undoActivity = undoActivityData(undoUrl, byActor, createDislikeActivity, audience) |
78 | 79 | ||
79 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 80 | return unicastTo(undoActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
80 | } | 81 | } |
81 | 82 | ||
82 | const data = undoActivityData(undoUrl, byActor, object) | 83 | const undoActivity = undoActivityData(undoUrl, byActor, createDislikeActivity) |
83 | 84 | ||
84 | const followersException = [ byActor ] | 85 | const followersException = [ byActor ] |
85 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) | 86 | return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) |
86 | } | 87 | } |
87 | 88 | ||
88 | async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { | 89 | async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { |
@@ -90,12 +91,27 @@ async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareMode | |||
90 | 91 | ||
91 | const undoUrl = getUndoActivityPubUrl(videoShare.url) | 92 | const undoUrl = getUndoActivityPubUrl(videoShare.url) |
92 | 93 | ||
93 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | 94 | const { activity: announceActivity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t) |
94 | const object = await buildVideoAnnounce(byActor, videoShare, video, t) | 95 | const undoActivity = undoActivityData(undoUrl, byActor, announceActivity) |
95 | const data = undoActivityData(undoUrl, byActor, object) | ||
96 | 96 | ||
97 | const followersException = [ byActor ] | 97 | const followersException = [ byActor ] |
98 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) | 98 | return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) |
99 | } | ||
100 | |||
101 | async function sendUndoCacheFile (byActor: ActorModel, redundancyModel: VideoRedundancyModel, t: Transaction) { | ||
102 | logger.info('Creating job to undo cache file %s.', redundancyModel.url) | ||
103 | |||
104 | const undoUrl = getUndoActivityPubUrl(redundancyModel.url) | ||
105 | |||
106 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(redundancyModel.VideoFile.Video.id) | ||
107 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | ||
108 | |||
109 | const audience = getVideoAudience(video, actorsInvolvedInVideo) | ||
110 | const createActivity = buildCreateActivity(redundancyModel.url, byActor, redundancyModel.toActivityPubObject()) | ||
111 | |||
112 | const undoActivity = undoActivityData(undoUrl, byActor, createActivity, audience) | ||
113 | |||
114 | return unicastTo(undoActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | ||
99 | } | 115 | } |
100 | 116 | ||
101 | // --------------------------------------------------------------------------- | 117 | // --------------------------------------------------------------------------- |
@@ -104,7 +120,8 @@ export { | |||
104 | sendUndoFollow, | 120 | sendUndoFollow, |
105 | sendUndoLike, | 121 | sendUndoLike, |
106 | sendUndoDislike, | 122 | sendUndoDislike, |
107 | sendUndoAnnounce | 123 | sendUndoAnnounce, |
124 | sendUndoCacheFile | ||
108 | } | 125 | } |
109 | 126 | ||
110 | // --------------------------------------------------------------------------- | 127 | // --------------------------------------------------------------------------- |