diff options
author | Chocobozzz <me@florianbigard.com> | 2018-03-27 13:33:56 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-03-27 13:33:56 +0200 |
commit | 07197db4c567f22bbc9c12339062896dc76bac2f (patch) | |
tree | 5682f0d88fc1b4032018e5122ed42eb9967fd743 /server/lib/activitypub/send/send-undo.ts | |
parent | da99ccf2681bcbc172a96cf30e7b733948767faa (diff) | |
download | PeerTube-07197db4c567f22bbc9c12339062896dc76bac2f.tar.gz PeerTube-07197db4c567f22bbc9c12339062896dc76bac2f.tar.zst PeerTube-07197db4c567f22bbc9c12339062896dc76bac2f.zip |
Try to refractor activities sending
There is still a need for work on this part though
Diffstat (limited to 'server/lib/activitypub/send/send-undo.ts')
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 49 |
1 files changed, 18 insertions, 31 deletions
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 41a500384..bd49d452e 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -30,68 +30,55 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { | |||
30 | return unicastTo(data, me, following.inboxUrl) | 30 | return unicastTo(data, me, following.inboxUrl) |
31 | } | 31 | } |
32 | 32 | ||
33 | async function sendUndoLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { | 33 | async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) { |
34 | const likeUrl = getVideoLikeActivityPubUrl(byActor, video) | 34 | const likeUrl = getVideoLikeActivityPubUrl(byActor, video) |
35 | const undoUrl = getUndoActivityPubUrl(likeUrl) | 35 | const undoUrl = getUndoActivityPubUrl(likeUrl) |
36 | 36 | ||
37 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | 37 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
38 | const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) | ||
39 | const object = await likeActivityData(likeUrl, byActor, video, t) | 38 | const object = await likeActivityData(likeUrl, byActor, video, t) |
40 | const data = await undoActivityData(undoUrl, byActor, object, t, audience) | ||
41 | 39 | ||
42 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 40 | // Send to origin |
43 | } | 41 | if (video.isOwned() === false) { |
42 | const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) | ||
43 | const data = await undoActivityData(undoUrl, byActor, object, t, audience) | ||
44 | 44 | ||
45 | async function sendUndoLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { | 45 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
46 | const likeUrl = getVideoLikeActivityPubUrl(byActor, video) | 46 | } |
47 | const undoUrl = getUndoActivityPubUrl(likeUrl) | ||
48 | 47 | ||
49 | const toActorsFollowers = await getActorsInvolvedInVideo(video, t) | 48 | const audience = getObjectFollowersAudience(actorsInvolvedInVideo) |
50 | const audience = getObjectFollowersAudience(toActorsFollowers) | ||
51 | const object = await likeActivityData(likeUrl, byActor, video, t) | ||
52 | const data = await undoActivityData(undoUrl, byActor, object, t, audience) | 49 | const data = await undoActivityData(undoUrl, byActor, object, t, audience) |
53 | 50 | ||
54 | const followersException = [ byActor ] | 51 | const followersException = [ byActor ] |
55 | return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException) | 52 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) |
56 | } | 53 | } |
57 | 54 | ||
58 | async function sendUndoDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { | 55 | async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) { |
59 | const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) | 56 | const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) |
60 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | 57 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) |
61 | 58 | ||
62 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | 59 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
63 | const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) | ||
64 | const dislikeActivity = createDislikeActivityData(byActor, video) | 60 | const dislikeActivity = createDislikeActivityData(byActor, video) |
65 | const object = await createActivityData(undoUrl, byActor, dislikeActivity, t) | 61 | const object = await createActivityData(undoUrl, byActor, dislikeActivity, t) |
66 | 62 | ||
67 | const data = await undoActivityData(undoUrl, byActor, object, t, audience) | 63 | if (video.isOwned() === false) { |
68 | 64 | const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) | |
69 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 65 | const data = await undoActivityData(undoUrl, byActor, object, t, audience) |
70 | } | ||
71 | |||
72 | async function sendUndoDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { | ||
73 | const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) | ||
74 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | ||
75 | 66 | ||
76 | const dislikeActivity = createDislikeActivityData(byActor, video) | 67 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
77 | const object = await createActivityData(undoUrl, byActor, dislikeActivity, t) | 68 | } |
78 | 69 | ||
79 | const data = await undoActivityData(undoUrl, byActor, object, t) | 70 | const data = await undoActivityData(undoUrl, byActor, object, t) |
80 | 71 | ||
81 | const toActorsFollowers = await getActorsInvolvedInVideo(video, t) | ||
82 | |||
83 | const followersException = [ byActor ] | 72 | const followersException = [ byActor ] |
84 | return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException) | 73 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) |
85 | } | 74 | } |
86 | 75 | ||
87 | // --------------------------------------------------------------------------- | 76 | // --------------------------------------------------------------------------- |
88 | 77 | ||
89 | export { | 78 | export { |
90 | sendUndoFollow, | 79 | sendUndoFollow, |
91 | sendUndoLikeToOrigin, | 80 | sendUndoLike, |
92 | sendUndoLikeToVideoFollowers, | 81 | sendUndoDislike |
93 | sendUndoDislikeToOrigin, | ||
94 | sendUndoDislikeToVideoFollowers | ||
95 | } | 82 | } |
96 | 83 | ||
97 | // --------------------------------------------------------------------------- | 84 | // --------------------------------------------------------------------------- |