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-undo.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-undo.ts')
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 948ca0d7a..36d7ef991 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -6,7 +6,8 @@ import { | |||
6 | ActivityDislike, | 6 | ActivityDislike, |
7 | ActivityFollow, | 7 | ActivityFollow, |
8 | ActivityLike, | 8 | ActivityLike, |
9 | ActivityUndo | 9 | ActivityUndo, |
10 | ContextType | ||
10 | } from '@shared/models' | 11 | } from '@shared/models' |
11 | import { logger } from '../../../helpers/logger' | 12 | import { logger } from '../../../helpers/logger' |
12 | import { VideoModel } from '../../../models/video/video' | 13 | import { VideoModel } from '../../../models/video/video' |
@@ -43,24 +44,37 @@ function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { | |||
43 | const followActivity = buildFollowActivity(actorFollow.url, me, following) | 44 | const followActivity = buildFollowActivity(actorFollow.url, me, following) |
44 | const undoActivity = undoActivityData(undoUrl, me, followActivity) | 45 | const undoActivity = undoActivityData(undoUrl, me, followActivity) |
45 | 46 | ||
46 | t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl)) | 47 | return t.afterCommit(() => { |
48 | return unicastTo({ | ||
49 | data: undoActivity, | ||
50 | byActor: me, | ||
51 | toActorUrl: following.inboxUrl, | ||
52 | contextType: 'Follow' | ||
53 | }) | ||
54 | }) | ||
47 | } | 55 | } |
48 | 56 | ||
49 | // --------------------------------------------------------------------------- | 57 | // --------------------------------------------------------------------------- |
50 | 58 | ||
51 | async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, t: Transaction) { | 59 | async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, transaction: Transaction) { |
52 | logger.info('Creating job to undo announce %s.', videoShare.url) | 60 | logger.info('Creating job to undo announce %s.', videoShare.url) |
53 | 61 | ||
54 | const undoUrl = getUndoActivityPubUrl(videoShare.url) | 62 | const undoUrl = getUndoActivityPubUrl(videoShare.url) |
55 | 63 | ||
56 | const { activity: announceActivity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t) | 64 | const { activity: announce, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, transaction) |
57 | const undoActivity = undoActivityData(undoUrl, byActor, announceActivity) | 65 | const undoActivity = undoActivityData(undoUrl, byActor, announce) |
58 | 66 | ||
59 | const followersException = [ byActor ] | 67 | return broadcastToFollowers({ |
60 | return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) | 68 | data: undoActivity, |
69 | byActor, | ||
70 | toFollowersOf: actorsInvolvedInVideo, | ||
71 | transaction, | ||
72 | actorsException: [ byActor ], | ||
73 | contextType: 'Announce' | ||
74 | }) | ||
61 | } | 75 | } |
62 | 76 | ||
63 | async function sendUndoCacheFile (byActor: MActor, redundancyModel: MVideoRedundancyVideo, t: Transaction) { | 77 | async function sendUndoCacheFile (byActor: MActor, redundancyModel: MVideoRedundancyVideo, transaction: Transaction) { |
64 | logger.info('Creating job to undo cache file %s.', redundancyModel.url) | 78 | logger.info('Creating job to undo cache file %s.', redundancyModel.url) |
65 | 79 | ||
66 | const associatedVideo = redundancyModel.getVideo() | 80 | const associatedVideo = redundancyModel.getVideo() |
@@ -72,7 +86,14 @@ async function sendUndoCacheFile (byActor: MActor, redundancyModel: MVideoRedund | |||
72 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(associatedVideo.id) | 86 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(associatedVideo.id) |
73 | const createActivity = buildCreateActivity(redundancyModel.url, byActor, redundancyModel.toActivityPubObject()) | 87 | const createActivity = buildCreateActivity(redundancyModel.url, byActor, redundancyModel.toActivityPubObject()) |
74 | 88 | ||
75 | return sendUndoVideoRelatedActivity({ byActor, video, url: redundancyModel.url, activity: createActivity, transaction: t }) | 89 | return sendUndoVideoRelatedActivity({ |
90 | byActor, | ||
91 | video, | ||
92 | url: redundancyModel.url, | ||
93 | activity: createActivity, | ||
94 | contextType: 'CacheFile', | ||
95 | transaction | ||
96 | }) | ||
76 | } | 97 | } |
77 | 98 | ||
78 | // --------------------------------------------------------------------------- | 99 | // --------------------------------------------------------------------------- |
@@ -83,7 +104,7 @@ async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Tran | |||
83 | const likeUrl = getVideoLikeActivityPubUrlByLocalActor(byActor, video) | 104 | const likeUrl = getVideoLikeActivityPubUrlByLocalActor(byActor, video) |
84 | const likeActivity = buildLikeActivity(likeUrl, byActor, video) | 105 | const likeActivity = buildLikeActivity(likeUrl, byActor, video) |
85 | 106 | ||
86 | return sendUndoVideoToOriginActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t }) | 107 | return sendUndoVideoRateToOriginActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t }) |
87 | } | 108 | } |
88 | 109 | ||
89 | async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { | 110 | async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { |
@@ -92,7 +113,7 @@ async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: T | |||
92 | const dislikeUrl = getVideoDislikeActivityPubUrlByLocalActor(byActor, video) | 113 | const dislikeUrl = getVideoDislikeActivityPubUrlByLocalActor(byActor, video) |
93 | const dislikeActivity = buildDislikeActivity(dislikeUrl, byActor, video) | 114 | const dislikeActivity = buildDislikeActivity(dislikeUrl, byActor, video) |
94 | 115 | ||
95 | return sendUndoVideoToOriginActivity({ byActor, video, url: dislikeUrl, activity: dislikeActivity, transaction: t }) | 116 | return sendUndoVideoRateToOriginActivity({ byActor, video, url: dislikeUrl, activity: dislikeActivity, transaction: t }) |
96 | } | 117 | } |
97 | 118 | ||
98 | // --------------------------------------------------------------------------- | 119 | // --------------------------------------------------------------------------- |
@@ -131,6 +152,7 @@ async function sendUndoVideoRelatedActivity (options: { | |||
131 | video: MVideoAccountLight | 152 | video: MVideoAccountLight |
132 | url: string | 153 | url: string |
133 | activity: ActivityFollow | ActivityCreate | ActivityAnnounce | 154 | activity: ActivityFollow | ActivityCreate | ActivityAnnounce |
155 | contextType: ContextType | ||
134 | transaction: Transaction | 156 | transaction: Transaction |
135 | }) { | 157 | }) { |
136 | const activityBuilder = (audience: ActivityAudience) => { | 158 | const activityBuilder = (audience: ActivityAudience) => { |
@@ -142,7 +164,7 @@ async function sendUndoVideoRelatedActivity (options: { | |||
142 | return sendVideoRelatedActivity(activityBuilder, options) | 164 | return sendVideoRelatedActivity(activityBuilder, options) |
143 | } | 165 | } |
144 | 166 | ||
145 | async function sendUndoVideoToOriginActivity (options: { | 167 | async function sendUndoVideoRateToOriginActivity (options: { |
146 | byActor: MActor | 168 | byActor: MActor |
147 | video: MVideoAccountLight | 169 | video: MVideoAccountLight |
148 | url: string | 170 | url: string |
@@ -155,5 +177,5 @@ async function sendUndoVideoToOriginActivity (options: { | |||
155 | return undoActivityData(undoUrl, options.byActor, options.activity, audience) | 177 | return undoActivityData(undoUrl, options.byActor, options.activity, audience) |
156 | } | 178 | } |
157 | 179 | ||
158 | return sendVideoActivityToOrigin(activityBuilder, options) | 180 | return sendVideoActivityToOrigin(activityBuilder, { ...options, contextType: 'Rate' }) |
159 | } | 181 | } |