diff options
Diffstat (limited to 'server/lib/activitypub/send')
-rw-r--r-- | server/lib/activitypub/send/send-accept.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-announce.ts | 7 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 21 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-delete.ts | 7 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-dislike.ts | 10 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-flag.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-follow.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-like.ts | 10 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-reject.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 60 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 15 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-view.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/send/shared/audience-utils.ts | 74 | ||||
-rw-r--r-- | server/lib/activitypub/send/shared/index.ts | 2 | ||||
-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 @@ | |||
1 | import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub' | 1 | import { ActivityAccept, ActivityFollow } from '@shared/models' |
2 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers/logger' |
3 | import { MActor, MActorFollowActors } from '../../../types/models' | 3 | import { MActor, MActorFollowActors } from '../../../types/models' |
4 | import { getLocalActorFollowAcceptActivityPubUrl } from '../url' | 4 | import { getLocalActorFollowAcceptActivityPubUrl } from '../url' |
5 | import { buildFollowActivity } from './send-follow' | 5 | import { buildFollowActivity } from './send-follow' |
6 | import { unicastTo } from './utils' | 6 | import { unicastTo } from './shared/send-utils' |
7 | 7 | ||
8 | function sendAccept (actorFollow: MActorFollowActors) { | 8 | function 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub' | 2 | import { ActivityAnnounce, ActivityAudience } from '@shared/models' |
3 | import { broadcastToFollowers } from './utils' | ||
4 | import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf } from '../audience' | ||
5 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
6 | import { MActorLight, MVideo } from '../../../types/models' | 4 | import { MActorLight, MVideo } from '../../../types/models' |
7 | import { MVideoShare } from '../../../types/models/video' | 5 | import { MVideoShare } from '../../../types/models/video' |
6 | import { audiencify, getAudience } from '../audience' | ||
7 | import { getActorsInvolvedInVideo, getAudienceFromFollowersOf } from './shared' | ||
8 | import { broadcastToFollowers } from './shared/send-utils' | ||
8 | 9 | ||
9 | async function buildAnnounceWithVideoAudience ( | 10 | async 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' | 2 | import { getServerActor } from '@server/models/application/application' |
3 | import { VideoPrivacy } from '../../../../shared/models/videos' | 3 | import { ActivityAudience, ActivityCreate, ContextType, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
4 | import { VideoCommentModel } from '../../../models/video/video-comment' | ||
5 | import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' | ||
6 | import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf, getVideoCommentAudience } from '../audience' | ||
7 | import { logger, loggerTagsFactory } from '../../../helpers/logger' | 4 | import { logger, loggerTagsFactory } from '../../../helpers/logger' |
8 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' | 5 | import { VideoCommentModel } from '../../../models/video/video-comment' |
9 | import { | 6 | import { |
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' |
18 | import { getServerActor } from '@server/models/application/application' | 15 | import { audiencify, getAudience } from '../audience' |
19 | import { ContextType } from '@shared/models/activitypub/context' | 16 | import { |
17 | broadcastToActors, | ||
18 | broadcastToFollowers, | ||
19 | getActorsInvolvedInVideo, | ||
20 | getAudienceFromFollowersOf, | ||
21 | getVideoCommentAudience, | ||
22 | sendVideoRelatedActivity, | ||
23 | unicastTo | ||
24 | } from './shared' | ||
20 | 25 | ||
21 | const lTags = loggerTagsFactory('ap', 'create') | 26 | const 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { getServerActor } from '@server/models/application/application' | 2 | import { getServerActor } from '@server/models/application/application' |
3 | import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub' | 3 | import { ActivityAudience, ActivityDelete } from '@shared/models' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { ActorModel } from '../../../models/actor/actor' | 5 | import { ActorModel } from '../../../models/actor/actor' |
6 | import { VideoCommentModel } from '../../../models/video/video-comment' | 6 | import { VideoCommentModel } from '../../../models/video/video-comment' |
7 | import { VideoShareModel } from '../../../models/video/video-share' | 7 | import { VideoShareModel } from '../../../models/video/video-share' |
8 | import { MActorUrl } from '../../../types/models' | 8 | import { MActorUrl } from '../../../types/models' |
9 | import { MCommentOwnerVideo, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../types/models/video' | 9 | import { MCommentOwnerVideo, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../types/models/video' |
10 | import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience' | 10 | import { audiencify } from '../audience' |
11 | import { getDeleteActivityPubUrl } from '../url' | 11 | import { getDeleteActivityPubUrl } from '../url' |
12 | import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' | 12 | import { getActorsInvolvedInVideo, getVideoCommentAudience } from './shared' |
13 | import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './shared/send-utils' | ||
13 | 14 | ||
14 | async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) { | 15 | async 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { getVideoDislikeActivityPubUrlByLocalActor } from '../url' | 2 | import { ActivityAudience, ActivityDislike } from '@shared/models' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { ActivityAudience, ActivityDislike } from '../../../../shared/models/activitypub' | ||
5 | import { sendVideoRelatedActivity } from './utils' | ||
6 | import { audiencify, getAudience } from '../audience' | ||
7 | import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models' | 4 | import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models' |
5 | import { audiencify, getAudience } from '../audience' | ||
6 | import { getVideoDislikeActivityPubUrlByLocalActor } from '../url' | ||
7 | import { sendVideoActivityToOrigin } from './shared/send-utils' | ||
8 | 8 | ||
9 | function sendDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { | 9 | function 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 | ||
21 | function buildDislikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityDislike { | 21 | function 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub' | 2 | import { ActivityAudience, ActivityFlag } from '@shared/models' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { MAbuseAP, MAccountLight, MActor } from '../../../types/models' | 4 | import { MAbuseAP, MAccountLight, MActor } from '../../../types/models' |
5 | import { audiencify, getAudience } from '../audience' | 5 | import { audiencify, getAudience } from '../audience' |
6 | import { getLocalAbuseActivityPubUrl } from '../url' | 6 | import { getLocalAbuseActivityPubUrl } from '../url' |
7 | import { unicastTo } from './utils' | 7 | import { unicastTo } from './shared/send-utils' |
8 | 8 | ||
9 | function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) { | 9 | function 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityFollow } from '../../../../shared/models/activitypub' | 2 | import { ActivityFollow } from '@shared/models' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { MActor, MActorFollowActors } from '../../../types/models' | 4 | import { MActor, MActorFollowActors } from '../../../types/models' |
5 | import { unicastTo } from './utils' | 5 | import { unicastTo } from './shared/send-utils' |
6 | 6 | ||
7 | function sendFollow (actorFollow: MActorFollowActors, t: Transaction) { | 7 | function 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' | 2 | import { ActivityAudience, ActivityLike } from '@shared/models' |
3 | import { getVideoLikeActivityPubUrlByLocalActor } from '../url' | ||
4 | import { sendVideoRelatedActivity } from './utils' | ||
5 | import { audiencify, getAudience } from '../audience' | ||
6 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
7 | import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models' | 4 | import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models' |
5 | import { audiencify, getAudience } from '../audience' | ||
6 | import { getVideoLikeActivityPubUrlByLocalActor } from '../url' | ||
7 | import { sendVideoActivityToOrigin } from './shared/send-utils' | ||
8 | 8 | ||
9 | function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { | 9 | function 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 | ||
21 | function buildLikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityLike { | 21 | function 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 @@ | |||
1 | import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub' | 1 | import { ActivityFollow, ActivityReject } from '@shared/models' |
2 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers/logger' |
3 | import { MActor } from '../../../types/models' | 3 | import { MActor } from '../../../types/models' |
4 | import { getLocalActorFollowRejectActivityPubUrl } from '../url' | 4 | import { getLocalActorFollowRejectActivityPubUrl } from '../url' |
5 | import { buildFollowActivity } from './send-follow' | 5 | import { buildFollowActivity } from './send-follow' |
6 | import { unicastTo } from './utils' | 6 | import { unicastTo } from './shared/send-utils' |
7 | 7 | ||
8 | function sendReject (followUrl: string, follower: MActor, following: MActor) { | 8 | function 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' |
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 | } | ||
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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub' | 2 | import { getServerActor } from '@server/models/application/application' |
3 | import { VideoPrivacy } from '../../../../shared/models/videos' | 3 | import { ActivityAudience, ActivityUpdate, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
4 | import { logger } from '../../../helpers/logger' | ||
4 | import { AccountModel } from '../../../models/account/account' | 5 | import { AccountModel } from '../../../models/account/account' |
5 | import { VideoModel } from '../../../models/video/video' | 6 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoShareModel } from '../../../models/video/video-share' | 7 | import { VideoShareModel } from '../../../models/video/video-share' |
7 | import { getUpdateActivityPubUrl } from '../url' | ||
8 | import { broadcastToFollowers, sendVideoRelatedActivity } from './utils' | ||
9 | import { audiencify, getActorsInvolvedInVideo, getAudience } from '../audience' | ||
10 | import { logger } from '../../../helpers/logger' | ||
11 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' | ||
12 | import { | 8 | import { |
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' |
22 | import { getServerActor } from '@server/models/application/application' | 18 | import { audiencify, getAudience } from '../audience' |
19 | import { getUpdateActivityPubUrl } from '../url' | ||
20 | import { getActorsInvolvedInVideo } from './shared' | ||
21 | import { broadcastToFollowers, sendVideoRelatedActivity } from './shared/send-utils' | ||
23 | 22 | ||
24 | async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction, overrodeByActor?: MActor) { | 23 | async 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { VideoViews } from '@server/lib/video-views' | 2 | import { VideoViews } from '@server/lib/video-views' |
3 | import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models' | 3 | import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models' |
4 | import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub' | 4 | import { ActivityAudience, ActivityView } from '@shared/models' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { ActorModel } from '../../../models/actor/actor' | 6 | import { ActorModel } from '../../../models/actor/actor' |
7 | import { audiencify, getAudience } from '../audience' | 7 | import { audiencify, getAudience } from '../audience' |
8 | import { getLocalVideoViewActivityPubUrl } from '../url' | 8 | import { getLocalVideoViewActivityPubUrl } from '../url' |
9 | import { sendVideoRelatedActivity } from './utils' | 9 | import { sendVideoRelatedActivity } from './shared/send-utils' |
10 | 10 | ||
11 | async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) { | 11 | async 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 @@ | |||
1 | import { Transaction } from 'sequelize/dist' | ||
2 | import { ACTIVITY_PUB } from '@server/initializers/constants' | ||
3 | import { ActorModel } from '@server/models/actor/actor' | ||
4 | import { VideoModel } from '@server/models/video/video' | ||
5 | import { VideoShareModel } from '@server/models/video/video-share' | ||
6 | import { MActorFollowersUrl, MActorLight, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '@server/types/models' | ||
7 | import { ActivityAudience } from '@shared/models' | ||
8 | |||
9 | function getOriginVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[] = []): ActivityAudience { | ||
10 | return { | ||
11 | to: [ accountActor.url ], | ||
12 | cc: actorsInvolvedInVideo.map(a => a.followersUrl) | ||
13 | } | ||
14 | } | ||
15 | |||
16 | function 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 | |||
46 | function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[]): ActivityAudience { | ||
47 | return { | ||
48 | to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)), | ||
49 | cc: [] | ||
50 | } | ||
51 | } | ||
52 | |||
53 | async 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 | |||
69 | export { | ||
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 @@ | |||
1 | export * from './audience-utils' | ||
2 | export * 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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache' | 2 | import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache' |
3 | import { getServerActor } from '@server/models/application/application' | 3 | import { getServerActor } from '@server/models/application/application' |
4 | import { Activity, ActivityAudience } from '@shared/models' | ||
4 | import { ContextType } from '@shared/models/activitypub/context' | 5 | import { ContextType } from '@shared/models/activitypub/context' |
5 | import { Activity, ActivityAudience } from '../../../../shared/models/activitypub' | 6 | import { afterCommitIfTransaction } from '../../../../helpers/database-utils' |
6 | import { afterCommitIfTransaction } from '../../../helpers/database-utils' | 7 | import { logger } from '../../../../helpers/logger' |
7 | import { logger } from '../../../helpers/logger' | 8 | import { ActorModel } from '../../../../models/actor/actor' |
8 | import { ActorModel } from '../../../models/actor/actor' | 9 | import { ActorFollowModel } from '../../../../models/actor/actor-follow' |
9 | import { ActorFollowModel } from '../../../models/actor/actor-follow' | 10 | import { MActor, MActorId, MActorLight, MActorWithInboxes, MVideoAccountLight, MVideoId, MVideoImmutable } from '../../../../types/models' |
10 | import { MActor, MActorId, MActorLight, MActorWithInboxes, MVideoAccountLight, MVideoId, MVideoImmutable } from '../../../types/models' | 11 | import { JobQueue } from '../../../job-queue' |
11 | import { JobQueue } from '../../job-queue' | 12 | import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getOriginVideoAudience } from './audience-utils' |
12 | import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience' | ||
13 | 13 | ||
14 | async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { | 14 | async 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 | ||
38 | async 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 | |||
47 | async function forwardVideoRelatedActivity ( | 62 | async 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 | |||
95 | async function broadcastToFollowers ( | 112 | async 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 | } |