diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-14 16:51:35 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-14 16:51:35 +0200 |
commit | a2377d15ee09301cf4cc5434ad865a21918da15f (patch) | |
tree | 4325153370bb19511ff162114056a5c7fd89744d /server/lib/activitypub/send/send-undo.ts | |
parent | d61b817890d5d5bba61d447518321870498028d8 (diff) | |
download | PeerTube-a2377d15ee09301cf4cc5434ad865a21918da15f.tar.gz PeerTube-a2377d15ee09301cf4cc5434ad865a21918da15f.tar.zst PeerTube-a2377d15ee09301cf4cc5434ad865a21918da15f.zip |
Refractor activities sending
Diffstat (limited to 'server/lib/activitypub/send/send-undo.ts')
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 85 |
1 files changed, 33 insertions, 52 deletions
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index a50673c79..5236d2cb3 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -11,8 +11,8 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
11 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 11 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
12 | import { VideoModel } from '../../../models/video/video' | 12 | 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, sendVideoRelatedActivity, unicastTo } from './utils' |
15 | import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience' | 15 | import { audiencify, getAudience } from '../audience' |
16 | import { buildCreateActivity, buildDislikeActivity } from './send-create' | 16 | import { buildCreateActivity, buildDislikeActivity } from './send-create' |
17 | import { buildFollowActivity } from './send-follow' | 17 | import { buildFollowActivity } from './send-follow' |
18 | import { buildLikeActivity } from './send-like' | 18 | import { buildLikeActivity } from './send-like' |
@@ -39,79 +39,44 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { | |||
39 | return unicastTo(undoActivity, me, following.inboxUrl) | 39 | return unicastTo(undoActivity, me, following.inboxUrl) |
40 | } | 40 | } |
41 | 41 | ||
42 | async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) { | 42 | async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { |
43 | logger.info('Creating job to undo a like of video %s.', video.url) | 43 | logger.info('Creating job to undo announce %s.', videoShare.url) |
44 | 44 | ||
45 | const likeUrl = getVideoLikeActivityPubUrl(byActor, video) | 45 | const undoUrl = getUndoActivityPubUrl(videoShare.url) |
46 | const undoUrl = getUndoActivityPubUrl(likeUrl) | ||
47 | 46 | ||
48 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | 47 | const { activity: announceActivity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t) |
49 | const likeActivity = buildLikeActivity(likeUrl, byActor, video) | 48 | const undoActivity = undoActivityData(undoUrl, byActor, announceActivity) |
50 | 49 | ||
51 | // Send to origin | 50 | const followersException = [ byActor ] |
52 | if (video.isOwned() === false) { | 51 | return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) |
53 | const audience = getVideoAudience(video, actorsInvolvedInVideo) | 52 | } |
54 | const undoActivity = undoActivityData(undoUrl, byActor, likeActivity, audience) | ||
55 | 53 | ||
56 | return unicastTo(undoActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 54 | async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) { |
57 | } | 55 | logger.info('Creating job to undo a like of video %s.', video.url) |
58 | 56 | ||
59 | const audience = getObjectFollowersAudience(actorsInvolvedInVideo) | 57 | const likeUrl = getVideoLikeActivityPubUrl(byActor, video) |
60 | const undoActivity = undoActivityData(undoUrl, byActor, likeActivity, audience) | 58 | const likeActivity = buildLikeActivity(likeUrl, byActor, video) |
61 | 59 | ||
62 | const followersException = [ byActor ] | 60 | return sendUndoVideoRelatedActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t }) |
63 | return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) | ||
64 | } | 61 | } |
65 | 62 | ||
66 | async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) { | 63 | async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) { |
67 | logger.info('Creating job to undo a dislike of video %s.', video.url) | 64 | logger.info('Creating job to undo a dislike of video %s.', video.url) |
68 | 65 | ||
69 | const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) | 66 | const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) |
70 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | ||
71 | |||
72 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | ||
73 | const dislikeActivity = buildDislikeActivity(byActor, video) | 67 | const dislikeActivity = buildDislikeActivity(byActor, video) |
74 | const createDislikeActivity = buildCreateActivity(dislikeUrl, byActor, dislikeActivity) | 68 | const createDislikeActivity = buildCreateActivity(dislikeUrl, byActor, dislikeActivity) |
75 | 69 | ||
76 | if (video.isOwned() === false) { | 70 | return sendUndoVideoRelatedActivity({ byActor, video, url: dislikeUrl, activity: createDislikeActivity, transaction: t }) |
77 | const audience = getVideoAudience(video, actorsInvolvedInVideo) | ||
78 | const undoActivity = undoActivityData(undoUrl, byActor, createDislikeActivity, audience) | ||
79 | |||
80 | return unicastTo(undoActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | ||
81 | } | ||
82 | |||
83 | const undoActivity = undoActivityData(undoUrl, byActor, createDislikeActivity) | ||
84 | |||
85 | const followersException = [ byActor ] | ||
86 | return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) | ||
87 | } | ||
88 | |||
89 | async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { | ||
90 | logger.info('Creating job to undo announce %s.', videoShare.url) | ||
91 | |||
92 | const undoUrl = getUndoActivityPubUrl(videoShare.url) | ||
93 | |||
94 | const { activity: announceActivity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t) | ||
95 | const undoActivity = undoActivityData(undoUrl, byActor, announceActivity) | ||
96 | |||
97 | const followersException = [ byActor ] | ||
98 | return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) | ||
99 | } | 71 | } |
100 | 72 | ||
101 | async function sendUndoCacheFile (byActor: ActorModel, redundancyModel: VideoRedundancyModel, t: Transaction) { | 73 | async function sendUndoCacheFile (byActor: ActorModel, redundancyModel: VideoRedundancyModel, t: Transaction) { |
102 | logger.info('Creating job to undo cache file %s.', redundancyModel.url) | 74 | logger.info('Creating job to undo cache file %s.', redundancyModel.url) |
103 | 75 | ||
104 | const undoUrl = getUndoActivityPubUrl(redundancyModel.url) | ||
105 | |||
106 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(redundancyModel.VideoFile.Video.id) | 76 | 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()) | 77 | const createActivity = buildCreateActivity(redundancyModel.url, byActor, redundancyModel.toActivityPubObject()) |
111 | 78 | ||
112 | const undoActivity = undoActivityData(undoUrl, byActor, createActivity, audience) | 79 | return sendUndoVideoRelatedActivity({ byActor, video, url: redundancyModel.url, activity: createActivity, transaction: t }) |
113 | |||
114 | return unicastTo(undoActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | ||
115 | } | 80 | } |
116 | 81 | ||
117 | // --------------------------------------------------------------------------- | 82 | // --------------------------------------------------------------------------- |
@@ -144,3 +109,19 @@ function undoActivityData ( | |||
144 | audience | 109 | audience |
145 | ) | 110 | ) |
146 | } | 111 | } |
112 | |||
113 | async function sendUndoVideoRelatedActivity (options: { | ||
114 | byActor: ActorModel, | ||
115 | video: VideoModel, | ||
116 | url: string, | ||
117 | activity: ActivityFollow | ActivityLike | ActivityCreate | ActivityAnnounce, | ||
118 | transaction: Transaction | ||
119 | }) { | ||
120 | const activityBuilder = (audience: ActivityAudience) => { | ||
121 | const undoUrl = getUndoActivityPubUrl(options.url) | ||
122 | |||
123 | return undoActivityData(undoUrl, options.byActor, options.activity, audience) | ||
124 | } | ||
125 | |||
126 | return sendVideoRelatedActivity(activityBuilder, options) | ||
127 | } | ||