aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-undo.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-18 11:17:35 +0100
committerChocobozzz <me@florianbigard.com>2022-03-18 11:21:50 +0100
commit57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c (patch)
treefcf12670d643ec4a3b5eccdfa834227c0417d988 /server/lib/activitypub/send/send-undo.ts
parent2e3f7a5a6fbae276d3ba1cb1b08289917ec7604b (diff)
downloadPeerTube-57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c.tar.gz
PeerTube-57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c.tar.zst
PeerTube-57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c.zip
Don't store remote rates of remote videos
In the future we'll stop to expose all available rates to improve users privacy
Diffstat (limited to 'server/lib/activitypub/send/send-undo.ts')
-rw-r--r--server/lib/activitypub/send/send-undo.ts60
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'
11import { logger } from '../../../helpers/logger' 11import { logger } from '../../../helpers/logger'
12import { VideoModel } from '../../../models/video/video' 12import { VideoModel } from '../../../models/video/video'
13import { 13import {
@@ -27,7 +27,7 @@ import { buildCreateActivity } from './send-create'
27import { buildDislikeActivity } from './send-dislike' 27import { buildDislikeActivity } from './send-dislike'
28import { buildFollowActivity } from './send-follow' 28import { buildFollowActivity } from './send-follow'
29import { buildLikeActivity } from './send-like' 29import { buildLikeActivity } from './send-like'
30import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' 30import { broadcastToFollowers, sendVideoActivityToOrigin, sendVideoRelatedActivity, unicastTo } from './shared/send-utils'
31 31
32function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { 32function 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
49async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, t: Transaction) { 51async 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
63async 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
61async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { 80async 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
70async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { 89async 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
79async 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
145async 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}