diff options
Diffstat (limited to 'server/lib/activitypub/send/send-undo.ts')
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index d2b738bef..948ca0d7a 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -7,7 +7,7 @@ import { | |||
7 | ActivityFollow, | 7 | ActivityFollow, |
8 | ActivityLike, | 8 | ActivityLike, |
9 | ActivityUndo | 9 | ActivityUndo |
10 | } from '../../../../shared/models/activitypub' | 10 | } from '@shared/models' |
11 | import { logger } from '../../../helpers/logger' | 11 | import { logger } from '../../../helpers/logger' |
12 | import { VideoModel } from '../../../models/video/video' | 12 | import { VideoModel } from '../../../models/video/video' |
13 | import { | 13 | import { |
@@ -27,7 +27,7 @@ import { buildCreateActivity } from './send-create' | |||
27 | import { buildDislikeActivity } from './send-dislike' | 27 | import { buildDislikeActivity } from './send-dislike' |
28 | import { buildFollowActivity } from './send-follow' | 28 | import { buildFollowActivity } from './send-follow' |
29 | import { buildLikeActivity } from './send-like' | 29 | import { buildLikeActivity } from './send-like' |
30 | import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' | 30 | import { broadcastToFollowers, sendVideoActivityToOrigin, sendVideoRelatedActivity, unicastTo } from './shared/send-utils' |
31 | 31 | ||
32 | function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { | 32 | function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { |
33 | const me = actorFollow.ActorFollower | 33 | const me = actorFollow.ActorFollower |
@@ -46,6 +46,8 @@ function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { | |||
46 | t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl)) | 46 | t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl)) |
47 | } | 47 | } |
48 | 48 | ||
49 | // --------------------------------------------------------------------------- | ||
50 | |||
49 | async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, t: Transaction) { | 51 | async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, t: Transaction) { |
50 | logger.info('Creating job to undo announce %s.', videoShare.url) | 52 | logger.info('Creating job to undo announce %s.', videoShare.url) |
51 | 53 | ||
@@ -58,13 +60,30 @@ async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare, | |||
58 | return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) | 60 | return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) |
59 | } | 61 | } |
60 | 62 | ||
63 | async function sendUndoCacheFile (byActor: MActor, redundancyModel: MVideoRedundancyVideo, t: Transaction) { | ||
64 | logger.info('Creating job to undo cache file %s.', redundancyModel.url) | ||
65 | |||
66 | const associatedVideo = redundancyModel.getVideo() | ||
67 | if (!associatedVideo) { | ||
68 | logger.warn('Cannot send undo activity for redundancy %s: no video files associated.', redundancyModel.url) | ||
69 | return | ||
70 | } | ||
71 | |||
72 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(associatedVideo.id) | ||
73 | const createActivity = buildCreateActivity(redundancyModel.url, byActor, redundancyModel.toActivityPubObject()) | ||
74 | |||
75 | return sendUndoVideoRelatedActivity({ byActor, video, url: redundancyModel.url, activity: createActivity, transaction: t }) | ||
76 | } | ||
77 | |||
78 | // --------------------------------------------------------------------------- | ||
79 | |||
61 | async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { | 80 | async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { |
62 | logger.info('Creating job to undo a like of video %s.', video.url) | 81 | logger.info('Creating job to undo a like of video %s.', video.url) |
63 | 82 | ||
64 | const likeUrl = getVideoLikeActivityPubUrlByLocalActor(byActor, video) | 83 | const likeUrl = getVideoLikeActivityPubUrlByLocalActor(byActor, video) |
65 | const likeActivity = buildLikeActivity(likeUrl, byActor, video) | 84 | const likeActivity = buildLikeActivity(likeUrl, byActor, video) |
66 | 85 | ||
67 | return sendUndoVideoRelatedActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t }) | 86 | return sendUndoVideoToOriginActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t }) |
68 | } | 87 | } |
69 | 88 | ||
70 | async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { | 89 | async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { |
@@ -73,22 +92,7 @@ async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: T | |||
73 | const dislikeUrl = getVideoDislikeActivityPubUrlByLocalActor(byActor, video) | 92 | const dislikeUrl = getVideoDislikeActivityPubUrlByLocalActor(byActor, video) |
74 | const dislikeActivity = buildDislikeActivity(dislikeUrl, byActor, video) | 93 | const dislikeActivity = buildDislikeActivity(dislikeUrl, byActor, video) |
75 | 94 | ||
76 | return sendUndoVideoRelatedActivity({ byActor, video, url: dislikeUrl, activity: dislikeActivity, transaction: t }) | 95 | return sendUndoVideoToOriginActivity({ byActor, video, url: dislikeUrl, activity: dislikeActivity, transaction: t }) |
77 | } | ||
78 | |||
79 | async function sendUndoCacheFile (byActor: MActor, redundancyModel: MVideoRedundancyVideo, t: Transaction) { | ||
80 | logger.info('Creating job to undo cache file %s.', redundancyModel.url) | ||
81 | |||
82 | const associatedVideo = redundancyModel.getVideo() | ||
83 | if (!associatedVideo) { | ||
84 | logger.warn('Cannot send undo activity for redundancy %s: no video files associated.', redundancyModel.url) | ||
85 | return | ||
86 | } | ||
87 | |||
88 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(associatedVideo.id) | ||
89 | const createActivity = buildCreateActivity(redundancyModel.url, byActor, redundancyModel.toActivityPubObject()) | ||
90 | |||
91 | return sendUndoVideoRelatedActivity({ byActor, video, url: redundancyModel.url, activity: createActivity, transaction: t }) | ||
92 | } | 96 | } |
93 | 97 | ||
94 | // --------------------------------------------------------------------------- | 98 | // --------------------------------------------------------------------------- |
@@ -126,7 +130,7 @@ async function sendUndoVideoRelatedActivity (options: { | |||
126 | byActor: MActor | 130 | byActor: MActor |
127 | video: MVideoAccountLight | 131 | video: MVideoAccountLight |
128 | url: string | 132 | url: string |
129 | activity: ActivityFollow | ActivityLike | ActivityDislike | ActivityCreate | ActivityAnnounce | 133 | activity: ActivityFollow | ActivityCreate | ActivityAnnounce |
130 | transaction: Transaction | 134 | transaction: Transaction |
131 | }) { | 135 | }) { |
132 | const activityBuilder = (audience: ActivityAudience) => { | 136 | const activityBuilder = (audience: ActivityAudience) => { |
@@ -137,3 +141,19 @@ async function sendUndoVideoRelatedActivity (options: { | |||
137 | 141 | ||
138 | return sendVideoRelatedActivity(activityBuilder, options) | 142 | return sendVideoRelatedActivity(activityBuilder, options) |
139 | } | 143 | } |
144 | |||
145 | async function sendUndoVideoToOriginActivity (options: { | ||
146 | byActor: MActor | ||
147 | video: MVideoAccountLight | ||
148 | url: string | ||
149 | activity: ActivityLike | ActivityDislike | ||
150 | transaction: Transaction | ||
151 | }) { | ||
152 | const activityBuilder = (audience: ActivityAudience) => { | ||
153 | const undoUrl = getUndoActivityPubUrl(options.url) | ||
154 | |||
155 | return undoActivityData(undoUrl, options.byActor, options.activity, audience) | ||
156 | } | ||
157 | |||
158 | return sendVideoActivityToOrigin(activityBuilder, options) | ||
159 | } | ||