aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send
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
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')
-rw-r--r--server/lib/activitypub/send/send-accept.ts4
-rw-r--r--server/lib/activitypub/send/send-announce.ts7
-rw-r--r--server/lib/activitypub/send/send-create.ts21
-rw-r--r--server/lib/activitypub/send/send-delete.ts7
-rw-r--r--server/lib/activitypub/send/send-dislike.ts10
-rw-r--r--server/lib/activitypub/send/send-flag.ts4
-rw-r--r--server/lib/activitypub/send/send-follow.ts4
-rw-r--r--server/lib/activitypub/send/send-like.ts10
-rw-r--r--server/lib/activitypub/send/send-reject.ts4
-rw-r--r--server/lib/activitypub/send/send-undo.ts60
-rw-r--r--server/lib/activitypub/send/send-update.ts15
-rw-r--r--server/lib/activitypub/send/send-view.ts4
-rw-r--r--server/lib/activitypub/send/shared/audience-utils.ts74
-rw-r--r--server/lib/activitypub/send/shared/index.ts2
-rw-r--r--server/lib/activitypub/send/shared/send-utils.ts (renamed from server/lib/activitypub/send/utils.ts)54
15 files changed, 200 insertions, 80 deletions
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts
index bb387e2c0..939f06d9e 100644
--- a/server/lib/activitypub/send/send-accept.ts
+++ b/server/lib/activitypub/send/send-accept.ts
@@ -1,9 +1,9 @@
1import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub' 1import { ActivityAccept, ActivityFollow } from '@shared/models'
2import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
3import { MActor, MActorFollowActors } from '../../../types/models' 3import { MActor, MActorFollowActors } from '../../../types/models'
4import { getLocalActorFollowAcceptActivityPubUrl } from '../url' 4import { getLocalActorFollowAcceptActivityPubUrl } from '../url'
5import { buildFollowActivity } from './send-follow' 5import { buildFollowActivity } from './send-follow'
6import { unicastTo } from './utils' 6import { unicastTo } from './shared/send-utils'
7 7
8function sendAccept (actorFollow: MActorFollowActors) { 8function sendAccept (actorFollow: MActorFollowActors) {
9 const follower = actorFollow.ActorFollower 9 const follower = actorFollow.ActorFollower
diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts
index 471dcfa77..7897beb75 100644
--- a/server/lib/activitypub/send/send-announce.ts
+++ b/server/lib/activitypub/send/send-announce.ts
@@ -1,10 +1,11 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub' 2import { ActivityAnnounce, ActivityAudience } from '@shared/models'
3import { broadcastToFollowers } from './utils'
4import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf } from '../audience'
5import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
6import { MActorLight, MVideo } from '../../../types/models' 4import { MActorLight, MVideo } from '../../../types/models'
7import { MVideoShare } from '../../../types/models/video' 5import { MVideoShare } from '../../../types/models/video'
6import { audiencify, getAudience } from '../audience'
7import { getActorsInvolvedInVideo, getAudienceFromFollowersOf } from './shared'
8import { broadcastToFollowers } from './shared/send-utils'
8 9
9async function buildAnnounceWithVideoAudience ( 10async function buildAnnounceWithVideoAudience (
10 byActor: MActorLight, 11 byActor: MActorLight,
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index baded642a..f6d897220 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -1,11 +1,8 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' 2import { getServerActor } from '@server/models/application/application'
3import { VideoPrivacy } from '../../../../shared/models/videos' 3import { ActivityAudience, ActivityCreate, ContextType, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
4import { VideoCommentModel } from '../../../models/video/video-comment'
5import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
6import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf, getVideoCommentAudience } from '../audience'
7import { logger, loggerTagsFactory } from '../../../helpers/logger' 4import { logger, loggerTagsFactory } from '../../../helpers/logger'
8import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 5import { VideoCommentModel } from '../../../models/video/video-comment'
9import { 6import {
10 MActorLight, 7 MActorLight,
11 MCommentOwnerVideo, 8 MCommentOwnerVideo,
@@ -15,8 +12,16 @@ import {
15 MVideoRedundancyFileVideo, 12 MVideoRedundancyFileVideo,
16 MVideoRedundancyStreamingPlaylistVideo 13 MVideoRedundancyStreamingPlaylistVideo
17} from '../../../types/models' 14} from '../../../types/models'
18import { getServerActor } from '@server/models/application/application' 15import { audiencify, getAudience } from '../audience'
19import { ContextType } from '@shared/models/activitypub/context' 16import {
17 broadcastToActors,
18 broadcastToFollowers,
19 getActorsInvolvedInVideo,
20 getAudienceFromFollowersOf,
21 getVideoCommentAudience,
22 sendVideoRelatedActivity,
23 unicastTo
24} from './shared'
20 25
21const lTags = loggerTagsFactory('ap', 'create') 26const lTags = loggerTagsFactory('ap', 'create')
22 27
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts
index d31f8c10b..39216cdeb 100644
--- a/server/lib/activitypub/send/send-delete.ts
+++ b/server/lib/activitypub/send/send-delete.ts
@@ -1,15 +1,16 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { getServerActor } from '@server/models/application/application' 2import { getServerActor } from '@server/models/application/application'
3import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub' 3import { ActivityAudience, ActivityDelete } from '@shared/models'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { ActorModel } from '../../../models/actor/actor' 5import { ActorModel } from '../../../models/actor/actor'
6import { VideoCommentModel } from '../../../models/video/video-comment' 6import { VideoCommentModel } from '../../../models/video/video-comment'
7import { VideoShareModel } from '../../../models/video/video-share' 7import { VideoShareModel } from '../../../models/video/video-share'
8import { MActorUrl } from '../../../types/models' 8import { MActorUrl } from '../../../types/models'
9import { MCommentOwnerVideo, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../types/models/video' 9import { MCommentOwnerVideo, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../types/models/video'
10import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience' 10import { audiencify } from '../audience'
11import { getDeleteActivityPubUrl } from '../url' 11import { getDeleteActivityPubUrl } from '../url'
12import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' 12import { getActorsInvolvedInVideo, getVideoCommentAudience } from './shared'
13import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './shared/send-utils'
13 14
14async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) { 15async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) {
15 logger.info('Creating job to broadcast delete of video %s.', video.url) 16 logger.info('Creating job to broadcast delete of video %s.', video.url)
diff --git a/server/lib/activitypub/send/send-dislike.ts b/server/lib/activitypub/send/send-dislike.ts
index 274230535..ecb11e9bf 100644
--- a/server/lib/activitypub/send/send-dislike.ts
+++ b/server/lib/activitypub/send/send-dislike.ts
@@ -1,10 +1,10 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { getVideoDislikeActivityPubUrlByLocalActor } from '../url' 2import { ActivityAudience, ActivityDislike } from '@shared/models'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { ActivityAudience, ActivityDislike } from '../../../../shared/models/activitypub'
5import { sendVideoRelatedActivity } from './utils'
6import { audiencify, getAudience } from '../audience'
7import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models' 4import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models'
5import { audiencify, getAudience } from '../audience'
6import { getVideoDislikeActivityPubUrlByLocalActor } from '../url'
7import { sendVideoActivityToOrigin } from './shared/send-utils'
8 8
9function sendDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { 9function sendDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) {
10 logger.info('Creating job to dislike %s.', video.url) 10 logger.info('Creating job to dislike %s.', video.url)
@@ -15,7 +15,7 @@ function sendDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction
15 return buildDislikeActivity(url, byActor, video, audience) 15 return buildDislikeActivity(url, byActor, video, audience)
16 } 16 }
17 17
18 return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t }) 18 return sendVideoActivityToOrigin(activityBuilder, { byActor, video, transaction: t })
19} 19}
20 20
21function buildDislikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityDislike { 21function buildDislikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityDislike {
diff --git a/server/lib/activitypub/send/send-flag.ts b/server/lib/activitypub/send/send-flag.ts
index b0483b5a0..6df4e7eb8 100644
--- a/server/lib/activitypub/send/send-flag.ts
+++ b/server/lib/activitypub/send/send-flag.ts
@@ -1,10 +1,10 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub' 2import { ActivityAudience, ActivityFlag } from '@shared/models'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { MAbuseAP, MAccountLight, MActor } from '../../../types/models' 4import { MAbuseAP, MAccountLight, MActor } from '../../../types/models'
5import { audiencify, getAudience } from '../audience' 5import { audiencify, getAudience } from '../audience'
6import { getLocalAbuseActivityPubUrl } from '../url' 6import { getLocalAbuseActivityPubUrl } from '../url'
7import { unicastTo } from './utils' 7import { unicastTo } from './shared/send-utils'
8 8
9function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) { 9function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) {
10 if (!flaggedAccount.Actor.serverId) return // Local user 10 if (!flaggedAccount.Actor.serverId) return // Local user
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts
index 9219640dd..aeeb50a2a 100644
--- a/server/lib/activitypub/send/send-follow.ts
+++ b/server/lib/activitypub/send/send-follow.ts
@@ -1,8 +1,8 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityFollow } from '../../../../shared/models/activitypub' 2import { ActivityFollow } from '@shared/models'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { MActor, MActorFollowActors } from '../../../types/models' 4import { MActor, MActorFollowActors } from '../../../types/models'
5import { unicastTo } from './utils' 5import { unicastTo } from './shared/send-utils'
6 6
7function sendFollow (actorFollow: MActorFollowActors, t: Transaction) { 7function sendFollow (actorFollow: MActorFollowActors, t: Transaction) {
8 const me = actorFollow.ActorFollower 8 const me = actorFollow.ActorFollower
diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts
index ed6dfcf56..a5fe95e0a 100644
--- a/server/lib/activitypub/send/send-like.ts
+++ b/server/lib/activitypub/send/send-like.ts
@@ -1,10 +1,10 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' 2import { ActivityAudience, ActivityLike } from '@shared/models'
3import { getVideoLikeActivityPubUrlByLocalActor } from '../url'
4import { sendVideoRelatedActivity } from './utils'
5import { audiencify, getAudience } from '../audience'
6import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
7import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models' 4import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models'
5import { audiencify, getAudience } from '../audience'
6import { getVideoLikeActivityPubUrlByLocalActor } from '../url'
7import { sendVideoActivityToOrigin } from './shared/send-utils'
8 8
9function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { 9function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) {
10 logger.info('Creating job to like %s.', video.url) 10 logger.info('Creating job to like %s.', video.url)
@@ -15,7 +15,7 @@ function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) {
15 return buildLikeActivity(url, byActor, video, audience) 15 return buildLikeActivity(url, byActor, video, audience)
16 } 16 }
17 17
18 return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t }) 18 return sendVideoActivityToOrigin(activityBuilder, { byActor, video, transaction: t })
19} 19}
20 20
21function buildLikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityLike { 21function buildLikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityLike {
diff --git a/server/lib/activitypub/send/send-reject.ts b/server/lib/activitypub/send/send-reject.ts
index 8d74a7848..01b8f743b 100644
--- a/server/lib/activitypub/send/send-reject.ts
+++ b/server/lib/activitypub/send/send-reject.ts
@@ -1,9 +1,9 @@
1import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub' 1import { ActivityFollow, ActivityReject } from '@shared/models'
2import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
3import { MActor } from '../../../types/models' 3import { MActor } from '../../../types/models'
4import { getLocalActorFollowRejectActivityPubUrl } from '../url' 4import { getLocalActorFollowRejectActivityPubUrl } from '../url'
5import { buildFollowActivity } from './send-follow' 5import { buildFollowActivity } from './send-follow'
6import { unicastTo } from './utils' 6import { unicastTo } from './shared/send-utils'
7 7
8function sendReject (followUrl: string, follower: MActor, following: MActor) { 8function sendReject (followUrl: string, follower: MActor, following: MActor) {
9 if (!follower.serverId) { // This should never happen 9 if (!follower.serverId) { // This should never happen
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}
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts
index bcf6e1569..7c9e72cbc 100644
--- a/server/lib/activitypub/send/send-update.ts
+++ b/server/lib/activitypub/send/send-update.ts
@@ -1,14 +1,10 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub' 2import { getServerActor } from '@server/models/application/application'
3import { VideoPrivacy } from '../../../../shared/models/videos' 3import { ActivityAudience, ActivityUpdate, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
4import { logger } from '../../../helpers/logger'
4import { AccountModel } from '../../../models/account/account' 5import { AccountModel } from '../../../models/account/account'
5import { VideoModel } from '../../../models/video/video' 6import { VideoModel } from '../../../models/video/video'
6import { VideoShareModel } from '../../../models/video/video-share' 7import { VideoShareModel } from '../../../models/video/video-share'
7import { getUpdateActivityPubUrl } from '../url'
8import { broadcastToFollowers, sendVideoRelatedActivity } from './utils'
9import { audiencify, getActorsInvolvedInVideo, getAudience } from '../audience'
10import { logger } from '../../../helpers/logger'
11import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
12import { 8import {
13 MAccountDefault, 9 MAccountDefault,
14 MActor, 10 MActor,
@@ -19,7 +15,10 @@ import {
19 MVideoPlaylistFull, 15 MVideoPlaylistFull,
20 MVideoRedundancyVideo 16 MVideoRedundancyVideo
21} from '../../../types/models' 17} from '../../../types/models'
22import { getServerActor } from '@server/models/application/application' 18import { audiencify, getAudience } from '../audience'
19import { getUpdateActivityPubUrl } from '../url'
20import { getActorsInvolvedInVideo } from './shared'
21import { broadcastToFollowers, sendVideoRelatedActivity } from './shared/send-utils'
23 22
24async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction, overrodeByActor?: MActor) { 23async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction, overrodeByActor?: MActor) {
25 const video = videoArg as MVideoAP 24 const video = videoArg as MVideoAP
diff --git a/server/lib/activitypub/send/send-view.ts b/server/lib/activitypub/send/send-view.ts
index b12583e26..1f97307b9 100644
--- a/server/lib/activitypub/send/send-view.ts
+++ b/server/lib/activitypub/send/send-view.ts
@@ -1,12 +1,12 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { VideoViews } from '@server/lib/video-views' 2import { VideoViews } from '@server/lib/video-views'
3import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models' 3import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models'
4import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub' 4import { ActivityAudience, ActivityView } from '@shared/models'
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
6import { ActorModel } from '../../../models/actor/actor' 6import { ActorModel } from '../../../models/actor/actor'
7import { audiencify, getAudience } from '../audience' 7import { audiencify, getAudience } from '../audience'
8import { getLocalVideoViewActivityPubUrl } from '../url' 8import { getLocalVideoViewActivityPubUrl } from '../url'
9import { sendVideoRelatedActivity } from './utils' 9import { sendVideoRelatedActivity } from './shared/send-utils'
10 10
11async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) { 11async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) {
12 logger.info('Creating job to send view of %s.', video.url) 12 logger.info('Creating job to send view of %s.', video.url)
diff --git a/server/lib/activitypub/send/shared/audience-utils.ts b/server/lib/activitypub/send/shared/audience-utils.ts
new file mode 100644
index 000000000..a5f64a08d
--- /dev/null
+++ b/server/lib/activitypub/send/shared/audience-utils.ts
@@ -0,0 +1,74 @@
1import { Transaction } from 'sequelize/dist'
2import { ACTIVITY_PUB } from '@server/initializers/constants'
3import { ActorModel } from '@server/models/actor/actor'
4import { VideoModel } from '@server/models/video/video'
5import { VideoShareModel } from '@server/models/video/video-share'
6import { MActorFollowersUrl, MActorLight, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '@server/types/models'
7import { ActivityAudience } from '@shared/models'
8
9function getOriginVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[] = []): ActivityAudience {
10 return {
11 to: [ accountActor.url ],
12 cc: actorsInvolvedInVideo.map(a => a.followersUrl)
13 }
14}
15
16function getVideoCommentAudience (
17 videoComment: MCommentOwnerVideo,
18 threadParentComments: MCommentOwner[],
19 actorsInvolvedInVideo: MActorFollowersUrl[],
20 isOrigin = false
21): ActivityAudience {
22 const to = [ ACTIVITY_PUB.PUBLIC ]
23 const cc: string[] = []
24
25 // Owner of the video we comment
26 if (isOrigin === false) {
27 cc.push(videoComment.Video.VideoChannel.Account.Actor.url)
28 }
29
30 // Followers of the poster
31 cc.push(videoComment.Account.Actor.followersUrl)
32
33 // Send to actors we reply to
34 for (const parentComment of threadParentComments) {
35 if (parentComment.isDeleted()) continue
36
37 cc.push(parentComment.Account.Actor.url)
38 }
39
40 return {
41 to,
42 cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
43 }
44}
45
46function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[]): ActivityAudience {
47 return {
48 to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
49 cc: []
50 }
51}
52
53async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
54 const actors: MActorLight[] = await VideoShareModel.loadActorsByShare(video.id, t)
55
56 const videoAll = video as VideoModel
57
58 const videoActor = videoAll.VideoChannel?.Account
59 ? videoAll.VideoChannel.Account.Actor
60 : await ActorModel.loadFromAccountByVideoId(video.id, t)
61
62 actors.push(videoActor)
63
64 return actors
65}
66
67// ---------------------------------------------------------------------------
68
69export {
70 getOriginVideoAudience,
71 getActorsInvolvedInVideo,
72 getAudienceFromFollowersOf,
73 getVideoCommentAudience
74}
diff --git a/server/lib/activitypub/send/shared/index.ts b/server/lib/activitypub/send/shared/index.ts
new file mode 100644
index 000000000..bda579115
--- /dev/null
+++ b/server/lib/activitypub/send/shared/index.ts
@@ -0,0 +1,2 @@
1export * from './audience-utils'
2export * from './send-utils'
diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/shared/send-utils.ts
index 7729703b8..9e8f12fa8 100644
--- a/server/lib/activitypub/send/utils.ts
+++ b/server/lib/activitypub/send/shared/send-utils.ts
@@ -1,15 +1,15 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache' 2import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache'
3import { getServerActor } from '@server/models/application/application' 3import { getServerActor } from '@server/models/application/application'
4import { Activity, ActivityAudience } from '@shared/models'
4import { ContextType } from '@shared/models/activitypub/context' 5import { ContextType } from '@shared/models/activitypub/context'
5import { Activity, ActivityAudience } from '../../../../shared/models/activitypub' 6import { afterCommitIfTransaction } from '../../../../helpers/database-utils'
6import { afterCommitIfTransaction } from '../../../helpers/database-utils' 7import { logger } from '../../../../helpers/logger'
7import { logger } from '../../../helpers/logger' 8import { ActorModel } from '../../../../models/actor/actor'
8import { ActorModel } from '../../../models/actor/actor' 9import { ActorFollowModel } from '../../../../models/actor/actor-follow'
9import { ActorFollowModel } from '../../../models/actor/actor-follow' 10import { MActor, MActorId, MActorLight, MActorWithInboxes, MVideoAccountLight, MVideoId, MVideoImmutable } from '../../../../types/models'
10import { MActor, MActorId, MActorLight, MActorWithInboxes, MVideoAccountLight, MVideoId, MVideoImmutable } from '../../../types/models' 11import { JobQueue } from '../../../job-queue'
11import { JobQueue } from '../../job-queue' 12import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getOriginVideoAudience } from './audience-utils'
12import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience'
13 13
14async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { 14async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: {
15 byActor: MActorLight 15 byActor: MActorLight
@@ -23,16 +23,7 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud
23 23
24 // Send to origin 24 // Send to origin
25 if (video.isOwned() === false) { 25 if (video.isOwned() === false) {
26 let accountActor: MActorLight = (video as MVideoAccountLight).VideoChannel?.Account?.Actor 26 return sendVideoActivityToOrigin(activityBuilder, options)
27
28 if (!accountActor) accountActor = await ActorModel.loadAccountActorByVideoId(video.id, transaction)
29
30 const audience = getRemoteVideoAudience(accountActor, actorsInvolvedInVideo)
31 const activity = activityBuilder(audience)
32
33 return afterCommitIfTransaction(transaction, () => {
34 return unicastTo(activity, byActor, accountActor.getSharedInbox(), contextType)
35 })
36 } 27 }
37 28
38 // Send to followers 29 // Send to followers
@@ -44,6 +35,30 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud
44 return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, transaction, actorsException, contextType) 35 return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, transaction, actorsException, contextType)
45} 36}
46 37
38async function sendVideoActivityToOrigin (activityBuilder: (audience: ActivityAudience) => Activity, options: {
39 byActor: MActorLight
40 video: MVideoImmutable | MVideoAccountLight
41 actorsInvolvedInVideo?: MActorLight[]
42 transaction?: Transaction
43 contextType?: ContextType
44}) {
45 const { byActor, video, actorsInvolvedInVideo, transaction, contextType } = options
46
47 if (video.isOwned()) throw new Error('Cannot send activity to owned video origin ' + video.url)
48
49 let accountActor: MActorLight = (video as MVideoAccountLight).VideoChannel?.Account?.Actor
50 if (!accountActor) accountActor = await ActorModel.loadAccountActorByVideoId(video.id, transaction)
51
52 const audience = getOriginVideoAudience(accountActor, actorsInvolvedInVideo)
53 const activity = activityBuilder(audience)
54
55 return afterCommitIfTransaction(transaction, () => {
56 return unicastTo(activity, byActor, accountActor.getSharedInbox(), contextType)
57 })
58}
59
60// ---------------------------------------------------------------------------
61
47async function forwardVideoRelatedActivity ( 62async function forwardVideoRelatedActivity (
48 activity: Activity, 63 activity: Activity,
49 t: Transaction, 64 t: Transaction,
@@ -92,6 +107,8 @@ async function forwardActivity (
92 return afterCommitIfTransaction(t, () => JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload })) 107 return afterCommitIfTransaction(t, () => JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }))
93} 108}
94 109
110// ---------------------------------------------------------------------------
111
95async function broadcastToFollowers ( 112async function broadcastToFollowers (
96 data: any, 113 data: any,
97 byActor: MActorId, 114 byActor: MActorId,
@@ -177,6 +194,7 @@ export {
177 unicastTo, 194 unicastTo,
178 forwardActivity, 195 forwardActivity,
179 broadcastToActors, 196 broadcastToActors,
197 sendVideoActivityToOrigin,
180 forwardVideoRelatedActivity, 198 forwardVideoRelatedActivity,
181 sendVideoRelatedActivity 199 sendVideoRelatedActivity
182} 200}