Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Refactor AP audiences

Chocobozzz5975899f7d01
diff --git a/packages/tests/src/api/activitypub/audience.ts b/packages/tests/src/api/activitypub/audience.ts
new file mode 100644
index 0000000000..efc0fd8140
--- /dev/null
+++ b/packages/tests/src/api/activitypub/audience.ts
@@ -0,0 +1,77 @@
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+
+import {
+ PeerTubeServer,
+ cleanupTests,
+ createMultipleServers,
+ followAll,
+ makeActivityPubGetRequest,
+ setAccessTokensToServers,
+ waitJobs
+} from '@peertube/peertube-server-commands'
+import { expect } from 'chai'
+
+describe('Test ActivityPub audience', function () {
+ let servers: PeerTubeServer[] = []
+ const publicUrl = 'https://www.w3.org/ns/activitystreams#Public'
+ let videoUUID: string
+
+ let userToken: string
+
+ before(async function () {
+ this.timeout(120000)
+
+ servers = await createMultipleServers(2)
+
+ // Get the access tokens
+ await setAccessTokensToServers(servers)
+
+ await followAll(servers)
+
+ userToken = await servers[0].users.generateUserAndToken('user')
+ })
+
+ it('Should have the correct audience for a video', async function () {
+ const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
+ videoUUID = uuid
+
+ const { body } = await makeActivityPubGetRequest(servers[0].url, '/w/' + uuid)
+
+ expect(body.to).to.have.members([ publicUrl, servers[0].url + '/video-channels/root_channel' ])
+ expect(body.cc).to.have.members([ servers[0].url + '/accounts/root/followers' ])
+ })
+
+ it('Should have a correct audience for a thread', async function () {
+ const { id } = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread', token: userToken })
+
+ const { body } = await makeActivityPubGetRequest(servers[0].url, '/videos/watch/' + videoUUID + '/comments/' + id)
+
+ expect(body.to).to.have.members([ publicUrl ])
+ expect(body.cc).to.have.members([
+ servers[0].url + '/video-channels/root_channel',
+ servers[0].url + '/accounts/user/followers',
+ servers[0].url + '/accounts/root'
+ ])
+ })
+
+ it('Should have the correct audience for a reply', async function () {
+ await waitJobs(servers)
+
+ const threadId = await servers[1].comments.findCommentId({ text: 'thread', videoId: videoUUID })
+
+ const { id } = await servers[1].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
+ const { body } = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + videoUUID + '/comments/' + id)
+
+ expect(body.to).to.have.members([ publicUrl ])
+ expect(body.cc).to.have.members([
+ servers[0].url + '/video-channels/root_channel',
+ servers[0].url + '/accounts/user',
+ servers[0].url + '/accounts/root',
+ servers[1].url + '/accounts/root/followers'
+ ])
+ })
+
+ after(async function () {
+ await cleanupTests(servers)
+ })
+})
diff --git a/packages/tests/src/api/activitypub/forward.ts b/packages/tests/src/api/activitypub/forward.ts
new file mode 100644
index 0000000000..0afca40ee2
--- /dev/null
+++ b/packages/tests/src/api/activitypub/forward.ts
@@ -0,0 +1,74 @@
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+
+import { PeerTubeServer, cleanupTests, createMultipleServers, setAccessTokensToServers, waitJobs } from '@peertube/peertube-server-commands'
+import { expect } from 'chai'
+
+describe('Test forwarding activities', function () {
+ let servers: PeerTubeServer[] = []
+ const threadText = 'This is a comment'
+ let videoUUID = ''
+
+ before(async function () {
+ this.timeout(120000)
+
+ servers = await createMultipleServers(3)
+
+ // Get the access tokens
+ await setAccessTokensToServers(servers)
+
+ await servers[0].follows.follow({ hosts: [ servers[1].host ] })
+ await servers[2].follows.follow({ hosts: [ servers[1].host ] })
+
+ await servers[1].config.disableTranscoding()
+
+ const { uuid } = await servers[1].videos.quickUpload({ name: 'video' })
+ videoUUID = uuid
+
+ await waitJobs(servers)
+ })
+
+ it('Should correctly forward rates', async function () {
+ await servers[0].videos.rate({ id: videoUUID, rating: 'dislike' })
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const video = await server.videos.get({ id: videoUUID })
+
+ expect(video.dislikes).to.equal(1)
+ }
+ })
+
+ it('Should correctly forward comments to followers', async function () {
+ await servers[0].comments.createThread({ videoId: videoUUID, text: threadText })
+
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const { data } = await server.comments.listThreads({ videoId: videoUUID })
+
+ expect(data[0].text).to.equal(threadText)
+ }
+ })
+
+ it('Should correctly forward comments to mentions', async function () {
+ await servers[0].follows.unfollow({ target: servers[1] })
+ await waitJobs(servers)
+
+ {
+ const threadId = await servers[0].comments.findCommentId({ text: threadText, videoId: videoUUID })
+ await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
+ await waitJobs(servers)
+ }
+
+ for (const server of servers) {
+ const threadId = await server.comments.findCommentId({ text: threadText, videoId: videoUUID })
+ const { children } = await server.comments.getThread({ videoId: videoUUID, threadId })
+
+ expect(children[0].comment.text).to.equal('reply')
+ }
+ })
+
+ after(async function () {
+ await cleanupTests(servers)
+ })
+})
diff --git a/packages/tests/src/api/activitypub/index.ts b/packages/tests/src/api/activitypub/index.ts
index ef4f1aafb2..26f48c0f98 100644
--- a/packages/tests/src/api/activitypub/index.ts
+++ b/packages/tests/src/api/activitypub/index.ts
@@ -1,5 +1,7 @@
+import './audience.js'
import './cleaner.js'
import './client.js'
import './fetch.js'
+import './forward.js'
import './refresher.js'
import './security.js'
diff --git a/server/core/controllers/activitypub/client.ts b/server/core/controllers/activitypub/client.ts
index 98a902fcd9..59a2ab1667 100644
--- a/server/core/controllers/activitypub/client.ts
+++ b/server/core/controllers/activitypub/client.ts
@@ -6,12 +6,13 @@ import { InternalEventEmitter } from '@server/lib/internal-event-emitter.js'
import { getServerActor } from '@server/models/application/application.js'
import { PlayerSettingModel } from '@server/models/video/player-setting.js'
import { VideoChapterModel } from '@server/models/video/video-chapter.js'
+import { VideoModel } from '@server/models/video/video.js'
import { MAccountId, MActorId, MChannelId, MVideoId } from '@server/types/models/index.js'
import cors from 'cors'
import express from 'express'
import { activityPubContextify } from '../../helpers/activity-pub-utils.js'
import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../../initializers/constants.js'
-import { audiencify, getPlaylistAudience, getPublicAudience, getVideoAudience } from '../../lib/activitypub/audience.js'
+import { audiencify, getCommentAudience, getPlaylistAudience, getPublicAudience, getVideoAudience } from '../../lib/activitypub/audience.js'
import { buildAnnounceWithVideoAudience, buildApprovalActivity, buildLikeActivity } from '../../lib/activitypub/send/index.js'
import { buildCreateActivity } from '../../lib/activitypub/send/send-create.js'
import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike.js'
@@ -338,7 +339,7 @@ async function videoController (req: express.Request, res: express.Response) {
// We need captions to render AP object
const videoAP = await video.lightAPToFullAP(undefined)
- const audience = getVideoAudience(videoAP.VideoChannel.Account.Actor, videoAP.privacy)
+ const audience = getVideoAudience({ account: videoAP.VideoChannel.Account, channel: videoAP.VideoChannel, privacy: videoAP.privacy })
const videoObject = audiencify(await videoAP.toActivityPubObject(), audience)
if (req.path.endsWith('/activity')) {
@@ -354,7 +355,7 @@ async function videoAnnounceController (req: express.Request, res: express.Respo
if (redirectIfNotOwned(share.url, res)) return
- const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.videoAll, undefined)
+ const activity = buildAnnounceWithVideoAudience(share.Actor, share, res.locals.videoAll)
return activityPubResponse(activityPubContextify(activity, 'Announce', getContextFilter()), res)
}
@@ -469,7 +470,8 @@ async function videoCommentController (req: express.Request, res: express.Respon
let videoCommentObject = videoComment.toActivityPubObject(threadParentComments)
if (videoComment.Account) {
- const audience = getPublicAudience(videoComment.Account.Actor)
+ const video = await VideoModel.loadByUrlAndPopulateAccount(videoComment.Video.url)
+ const audience = getCommentAudience({ comment: videoComment, video, threadParentComments })
videoCommentObject = audiencify(videoCommentObject, audience)
if (req.path.endsWith('/activity')) {
diff --git a/server/core/controllers/activitypub/outbox.ts b/server/core/controllers/activitypub/outbox.ts
index 224888ba1c..cee848415a 100644
--- a/server/core/controllers/activitypub/outbox.ts
+++ b/server/core/controllers/activitypub/outbox.ts
@@ -62,7 +62,11 @@ async function buildActivities (actor: MActorLight, start: number, count: number
for (const video of data.data) {
const byActor = video.VideoChannel.Account.Actor
- const createActivityAudience = getVideoAudience(byActor, video.privacy)
+ const createActivityAudience = getVideoAudience({
+ account: video.VideoChannel.Account,
+ channel: video.VideoChannel,
+ privacy: video.privacy
+ })
// This is a shared video
if (video.VideoShares !== undefined && video.VideoShares.length !== 0) {
diff --git a/server/core/helpers/activity-pub-utils.ts b/server/core/helpers/activity-pub-utils.ts
index f93cfeff86..5fe16fd92f 100644
--- a/server/core/helpers/activity-pub-utils.ts
+++ b/server/core/helpers/activity-pub-utils.ts
@@ -57,8 +57,8 @@ export async function getApplicationActorOfHost (host: string) {
return found?.href || undefined
}
-export function getAPPublicValue (): 'https://www.w3.org/ns/activitystreams#Public' {
- return 'https://www.w3.org/ns/activitystreams#Public'
+export function getAPPublicValue () {
+ return 'https://www.w3.org/ns/activitystreams#Public' as const
}
export function hasAPPublic (collection: string[] | string) {
diff --git a/server/core/lib/activitypub/audience.ts b/server/core/lib/activitypub/audience.ts
index 0aba9f36d8..567760469e 100644
--- a/server/core/lib/activitypub/audience.ts
+++ b/server/core/lib/activitypub/audience.ts
@@ -1,31 +1,82 @@
import { ActivityAudience, VideoPlaylistPrivacy, VideoPlaylistPrivacyType, VideoPrivacy, VideoPrivacyType } from '@peertube/peertube-models'
import { getAPPublicValue } from '@server/helpers/activity-pub-utils.js'
-import { MActorFollowersUrl } from '../../types/models/index.js'
+import {
+ MAccountAudience,
+ MActorFollowersUrl,
+ MActorUrl,
+ MChannelAudience,
+ MCommentOwner,
+ MVideoAccountLight
+} from '../../types/models/index.js'
export function getPublicAudience (actorSender: MActorFollowersUrl) {
- return buildAudience([ actorSender.followersUrl ], 'public')
+ return _buildPublicAudience({ cc: [ actorSender.followersUrl ] })
}
-export function getVideoAudience (actorSender: MActorFollowersUrl, privacy: VideoPrivacyType, options: {
+export function getDirectAudience (targetActor: MActorUrl): ActivityAudience {
+ return { to: [ targetActor.url ], cc: [] }
+}
+
+export function getVideoAudience (options: {
+ account: MAccountAudience
+ channel: MChannelAudience
+ privacy: VideoPrivacyType
skipPrivacyCheck?: boolean // default false
-} = {}) {
- const { skipPrivacyCheck = false } = options
+}) {
+ const { account, channel, privacy, skipPrivacyCheck = false } = options
- const followerUrls = [ actorSender.followersUrl ]
+ const followerUrls = [ account.Actor.followersUrl ]
- if (privacy === VideoPrivacy.PUBLIC) return buildAudience(followerUrls, 'public')
- else if (privacy === VideoPrivacy.UNLISTED) return buildAudience(followerUrls, 'unlisted')
+ if (privacy === VideoPrivacy.PUBLIC) {
+ return _buildPublicAudience({
+ to: [ channel.Actor.url ], // fep-1b12
+ cc: followerUrls
+ })
+ }
- if (skipPrivacyCheck) return buildAudience(followerUrls, 'private')
+ if (privacy === VideoPrivacy.UNLISTED) {
+ return _buildUnlistedAudience()
+ }
+
+ if (skipPrivacyCheck) {
+ return _buildPrivateAudience()
+ }
throw new Error(`Cannot get audience of non public/unlisted video privacy type (${privacy})`)
}
+export function getCommentAudience (options: {
+ comment: MCommentOwner
+ video: MVideoAccountLight
+ threadParentComments: MCommentOwner[]
+}): ActivityAudience {
+ const { comment, video, threadParentComments } = options
+
+ const audience: ActivityAudience = {
+ to: [ getAPPublicValue() ],
+
+ cc: [
+ comment.Account.Actor.followersUrl, // Followers of the commenter
+ video.VideoChannel.Account.Actor.url, // Owner of the video
+ video.VideoChannel.Actor.url // fep-1b12
+ ]
+ }
+
+ // Send to actors we reply to
+ for (const parentComment of threadParentComments) {
+ if (parentComment.isDeleted()) continue
+
+ audience.cc.push(parentComment.Account.Actor.url)
+ }
+
+ return audience
+}
+
export function getPlaylistAudience (actorSender: MActorFollowersUrl, privacy: VideoPlaylistPrivacyType) {
const followerUrls = [ actorSender.followersUrl ]
- if (privacy === VideoPlaylistPrivacy.PUBLIC) return buildAudience(followerUrls, 'public')
- else if (privacy === VideoPlaylistPrivacy.UNLISTED) return buildAudience(followerUrls, 'unlisted')
+ if (privacy === VideoPlaylistPrivacy.PUBLIC) return _buildPublicAudience({ cc: followerUrls })
+ else if (privacy === VideoPlaylistPrivacy.UNLISTED) return _buildUnlistedAudience()
throw new Error(`Cannot get audience of non public/unlisted playlist privacy type (${privacy})`)
}
@@ -38,20 +89,19 @@ export function audiencify<T> (object: T, audience: ActivityAudience) {
// Private
// ---------------------------------------------------------------------------
-function buildAudience (followerUrls: string[], type: 'public' | 'unlisted' | 'private') {
- let to: string[] = []
- let cc: string[] = []
-
- if (type === 'public') {
- to = [ getAPPublicValue() ]
- cc = followerUrls
- } else if (type === 'unlisted') {
- to = []
- cc = [ getAPPublicValue() ]
- } else {
- to = []
- cc = []
- }
+function _buildPublicAudience (options: {
+ to?: string[]
+ cc?: string[]
+}) {
+ const { to = [], cc = [] } = options
+
+ return { to: [ getAPPublicValue(), ...to ], cc }
+}
+
+function _buildUnlistedAudience () {
+ return { to: [], cc: [ getAPPublicValue() ] }
+}
- return { to, cc }
+function _buildPrivateAudience () {
+ return { to: [], cc: [] }
}
diff --git a/server/core/lib/activitypub/process/process-announce.ts b/server/core/lib/activitypub/process/process-announce.ts
index a99201be5a..c842d99050 100644
--- a/server/core/lib/activitypub/process/process-announce.ts
+++ b/server/core/lib/activitypub/process/process-announce.ts
@@ -55,7 +55,7 @@ async function processVideoShare (actorAnnouncer: MActorSignature, activity: Act
// Don't resend the activity to the sender
const exceptions = [ actorAnnouncer ]
- await forwardVideoRelatedActivity(activity, t, exceptions, video)
+ await forwardVideoRelatedActivity({ activity, transaction: t, followersException: exceptions, video })
}
return undefined
diff --git a/server/core/lib/activitypub/process/process-create.ts b/server/core/lib/activitypub/process/process-create.ts
index 870c32e465..3f6e6b053f 100644
--- a/server/core/lib/activitypub/process/process-create.ts
+++ b/server/core/lib/activitypub/process/process-create.ts
@@ -103,7 +103,7 @@ async function processCreateCacheFile (
if (video.isLocal()) {
// Don't resend the activity to the sender
const exceptions = [ byActor ]
- await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
+ await forwardVideoRelatedActivity({ activity, transaction: undefined, followersException: exceptions, video })
}
}
@@ -174,7 +174,7 @@ async function processCreateVideoComment (
// Don't resend the activity to the sender
const exceptions = [ byActor ]
- await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
+ await forwardVideoRelatedActivity({ activity, transaction: undefined, followersException: exceptions, video })
}
}
diff --git a/server/core/lib/activitypub/process/process-delete.ts b/server/core/lib/activitypub/process/process-delete.ts
index c686a0f35e..918baf1eed 100644
--- a/server/core/lib/activitypub/process/process-delete.ts
+++ b/server/core/lib/activitypub/process/process-delete.ts
@@ -147,7 +147,7 @@ function processDeleteVideoComment (byActor: MActorSignature, videoComment: MCom
if (videoComment.Video.isLocal()) {
// Don't resend the activity to the sender
const exceptions = [ byActor ]
- await forwardVideoRelatedActivity(activity, t, exceptions, videoComment.Video)
+ await forwardVideoRelatedActivity({ activity, transaction: t, followersException: exceptions, video: videoComment.Video })
}
logger.info('Remote video comment %s removed.', videoComment.url)
diff --git a/server/core/lib/activitypub/process/process-undo.ts b/server/core/lib/activitypub/process/process-undo.ts
index b6e79c6889..b5de680947 100644
--- a/server/core/lib/activitypub/process/process-undo.ts
+++ b/server/core/lib/activitypub/process/process-undo.ts
@@ -136,7 +136,7 @@ async function processUndoCacheFile (
// Don't resend the activity to the sender
const exceptions = [ byActor ]
- await forwardVideoRelatedActivity(activity, t, exceptions, video)
+ await forwardVideoRelatedActivity({ activity, transaction: t, followersException: exceptions, video })
}
})
}
@@ -157,7 +157,7 @@ function processUndoAnnounce (byActor: MActorSignature, announceActivity: Activi
// Don't resend the activity to the sender
const exceptions = [ byActor ]
- await forwardVideoRelatedActivity(announceActivity, t, exceptions, share.Video)
+ await forwardVideoRelatedActivity({ activity: announceActivity, transaction: t, followersException: exceptions, video: share.Video })
}
})
}
diff --git a/server/core/lib/activitypub/process/process-update.ts b/server/core/lib/activitypub/process/process-update.ts
index 4471feef9d..d112904209 100644
--- a/server/core/lib/activitypub/process/process-update.ts
+++ b/server/core/lib/activitypub/process/process-update.ts
@@ -116,7 +116,7 @@ async function processUpdateCacheFile (
// Don't resend the activity to the sender
const exceptions = [ byActor ]
- await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
+ await forwardVideoRelatedActivity({ activity, transaction: undefined, followersException: exceptions, video })
}
}
diff --git a/server/core/lib/activitypub/process/process-view.ts b/server/core/lib/activitypub/process/process-view.ts
index 96103e34eb..6ea508cfe5 100644
--- a/server/core/lib/activitypub/process/process-view.ts
+++ b/server/core/lib/activitypub/process/process-view.ts
@@ -41,11 +41,10 @@ async function processCreateView (activity: ActivityView, byActor: MActorSignatu
if (video.isLocal()) {
// Forward the view but don't resend the activity to the sender
const exceptions = [ byActor ]
- await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
+ await forwardVideoRelatedActivity({ activity, transaction: undefined, followersException: exceptions, video })
}
}
-// Viewer protocol V2
function getViewerResultCounter (activity: ActivityView) {
const result = activity.result
diff --git a/server/core/lib/activitypub/send/send-announce.ts b/server/core/lib/activitypub/send/send-announce.ts
index 923a91d384..2396e7f6f5 100644
--- a/server/core/lib/activitypub/send/send-announce.ts
+++ b/server/core/lib/activitypub/send/send-announce.ts
@@ -1,44 +1,41 @@
-import { Transaction } from 'sequelize'
import { ActivityAnnounce, ActivityAudience } from '@peertube/peertube-models'
+import { Transaction } from 'sequelize'
import { logger } from '../../../helpers/logger.js'
import { MActorLight, MVideo } from '../../../types/models/index.js'
import { MVideoShare } from '../../../types/models/video/index.js'
import { audiencify, getPublicAudience } from '../audience.js'
-import { getActorsInvolvedInVideo, getAudienceFromFollowersOf } from './shared/index.js'
-import { broadcastToFollowers } from './shared/send-utils.js'
-
-async function buildAnnounceWithVideoAudience (
- byActor: MActorLight,
- videoShare: MVideoShare,
- video: MVideo,
- t: Transaction
-) {
- const announcedObject = video.url
+import { broadcastToFollowers, getActorsInvolvedInVideo } from './shared/send-utils.js'
- const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
- const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo)
-
- const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience)
-
- return { activity, actorsInvolvedInVideo }
-}
-
-async function sendVideoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, transaction: Transaction) {
- const { activity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, transaction)
+export async function sendVideoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, transaction: Transaction) {
+ const activity = buildAnnounceWithVideoAudience(byActor, videoShare, video)
logger.info('Creating job to send announce %s.', videoShare.url)
return broadcastToFollowers({
data: activity,
byActor,
- toFollowersOf: actorsInvolvedInVideo,
+ toFollowersOf: await getActorsInvolvedInVideo(video, transaction),
transaction,
actorsException: [ byActor ],
contextType: 'Announce'
})
}
-function buildAnnounceActivity (url: string, byActor: MActorLight, object: string, audience?: ActivityAudience): ActivityAnnounce {
+export function buildAnnounceWithVideoAudience (
+ byActor: MActorLight,
+ videoShare: MVideoShare,
+ video: MVideo
+) {
+ const announcedObject = video.url
+
+ const audience = getPublicAudience(byActor)
+
+ const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience)
+
+ return activity
+}
+
+export function buildAnnounceActivity (url: string, byActor: MActorLight, object: string, audience?: ActivityAudience): ActivityAnnounce {
if (!audience) audience = getPublicAudience(byActor)
return audiencify({
@@ -48,11 +45,3 @@ function buildAnnounceActivity (url: string, byActor: MActorLight, object: strin
object
}, audience)
}
-
-// ---------------------------------------------------------------------------
-
-export {
- sendVideoAnnounce,
- buildAnnounceActivity,
- buildAnnounceWithVideoAudience
-}
diff --git a/server/core/lib/activitypub/send/send-create.ts b/server/core/lib/activitypub/send/send-create.ts
index 52655e8f63..f77798d30e 100644
--- a/server/core/lib/activitypub/send/send-create.ts
+++ b/server/core/lib/activitypub/send/send-create.ts
@@ -21,18 +21,16 @@ import {
MVideoPlaylistFull,
MVideoRedundancyStreamingPlaylistVideo
} from '../../../types/models/index.js'
-import { audiencify, getPlaylistAudience, getPublicAudience, getVideoAudience } from '../audience.js'
+import { audiencify, getCommentAudience, getPlaylistAudience, getPublicAudience, getVideoAudience } from '../audience.js'
import { canVideoBeFederated } from '../videos/federate.js'
import {
broadcastToActors,
broadcastToFollowers,
getActorsInvolvedInVideo,
- getAudienceFromFollowersOf,
- getVideoCommentAudience,
- sendVideoActivityToOrigin,
sendVideoRelatedActivity,
+ sendVideoRelatedActivityToOrigin,
unicastTo
-} from './shared/index.js'
+} from './shared/send-utils.js'
const lTags = loggerTagsFactory('ap', 'create')
@@ -44,7 +42,7 @@ export async function sendCreateVideo (video: MVideoAP, transaction: Transaction
const byActor = video.VideoChannel.Account.Actor
const videoObject = await video.toActivityPubObject()
- const audience = getVideoAudience(byActor, video.privacy)
+ const audience = getVideoAudience({ account: video.VideoChannel.Account, channel: video.VideoChannel, privacy: video.privacy })
const createActivity = buildCreateActivity(video.url, byActor, videoObject, audience)
return broadcastToFollowers({
@@ -81,7 +79,7 @@ export async function sendCreateWatchAction (stats: MLocalVideoViewerWithWatchSe
return buildCreateActivity(stats.url, byActor, stats.toActivityPubObject(), audience)
}
- return sendVideoActivityToOrigin(activityBuilder, { byActor, video: stats.Video, transaction, contextType: 'WatchAction' })
+ return sendVideoRelatedActivityToOrigin(activityBuilder, { byActor, video: stats.Video, transaction, contextType: 'WatchAction' })
}
export async function sendCreateVideoPlaylist (playlist: MVideoPlaylistFull, transaction: Transaction) {
@@ -110,9 +108,7 @@ export async function sendCreateVideoPlaylist (playlist: MVideoPlaylistFull, tra
}
export async function sendCreateVideoCommentIfNeeded (comment: MCommentOwnerVideoReply, transaction: Transaction) {
- const isOrigin = comment.Video.isLocal()
-
- if (isOrigin) {
+ if (comment.Video.isLocal()) {
const videoWithBlacklist = await VideoModel.loadWithBlacklist(comment.Video.id)
if (!canVideoBeFederated(videoWithBlacklist)) {
@@ -134,19 +130,11 @@ export async function sendCreateVideoCommentIfNeeded (comment: MCommentOwnerVide
const threadParentComments = await VideoCommentModel.listThreadParentComments({ comment, transaction })
const commentObject = comment.toActivityPubObject(threadParentComments) as VideoCommentObject
- const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, transaction)
- // Add the actor that commented too
- actorsInvolvedInComment.push(byActor)
-
const parentsCommentActors = threadParentComments.filter(c => !c.isDeleted() && !c.heldForReview)
.map(c => c.Account.Actor)
- let audience: ActivityAudience
- if (isOrigin) {
- audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, isOrigin)
- } else {
- audience = getAudienceFromFollowersOf(actorsInvolvedInComment.concat(parentsCommentActors))
- }
+ const video = await VideoModel.loadByUrlAndPopulateAccount(comment.Video.url, transaction)
+ const audience = getCommentAudience({ comment, video, threadParentComments })
const createActivity = buildCreateActivity(comment.url, byActor, commentObject, audience)
@@ -171,7 +159,11 @@ export async function sendCreateVideoCommentIfNeeded (comment: MCommentOwnerVide
})
// Send to actors involved in the comment
- if (isOrigin) {
+ if (comment.Video.isLocal()) {
+ const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, transaction)
+ // Add the actor that commented too
+ actorsInvolvedInComment.push(byActor)
+
return broadcastToFollowers({
data: createActivity,
byActor,
diff --git a/server/core/lib/activitypub/send/send-delete.ts b/server/core/lib/activitypub/send/send-delete.ts
index f7202dd0bc..5ee3cabf98 100644
--- a/server/core/lib/activitypub/send/send-delete.ts
+++ b/server/core/lib/activitypub/send/send-delete.ts
@@ -1,6 +1,7 @@
import { ActivityAudience, ActivityDelete } from '@peertube/peertube-models'
import { AccountModel } from '@server/models/account/account.js'
import { getServerActor } from '@server/models/application/application.js'
+import { VideoModel } from '@server/models/video/video.js'
import { Transaction } from 'sequelize'
import { logger } from '../../../helpers/logger.js'
import { ActorModel } from '../../../models/actor/actor.js'
@@ -8,10 +9,15 @@ import { VideoCommentModel } from '../../../models/video/video-comment.js'
import { VideoShareModel } from '../../../models/video/video-share.js'
import { MActorUrl } from '../../../types/models/index.js'
import { MCommentOwnerVideo, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../types/models/video/index.js'
-import { audiencify } from '../audience.js'
+import { audiencify, getCommentAudience } from '../audience.js'
import { getDeleteActivityPubUrl } from '../url.js'
-import { getActorsInvolvedInVideo, getVideoCommentAudience } from './shared/index.js'
-import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './shared/send-utils.js'
+import {
+ broadcastToActors,
+ broadcastToFollowers,
+ getActorsInvolvedInVideo,
+ sendVideoRelatedActivity,
+ unicastTo
+} from './shared/send-utils.js'
async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) {
logger.info('Creating job to broadcast delete of video %s.', video.url)
@@ -50,27 +56,25 @@ async function sendDeleteActor (byActor: ActorModel, transaction: Transaction) {
})
}
-async function sendDeleteVideoComment (videoComment: MCommentOwnerVideo, transaction: Transaction) {
- logger.info('Creating job to send delete of comment %s.', videoComment.url)
+async function sendDeleteVideoComment (comment: MCommentOwnerVideo, transaction: Transaction) {
+ logger.info('Creating job to send delete of comment %s.', comment.url)
- const isVideoOrigin = videoComment.Video.isLocal()
+ const isVideoOrigin = comment.Video.isLocal()
- const url = getDeleteActivityPubUrl(videoComment.url)
+ const url = getDeleteActivityPubUrl(comment.url)
- const videoAccount = await AccountModel.load(videoComment.Video.VideoChannel.Account.id, transaction)
+ const videoAccount = await AccountModel.load(comment.Video.VideoChannel.Account.id, transaction)
- const byActor = videoComment.isLocal()
- ? videoComment.Account.Actor
+ const byActor = comment.isLocal()
+ ? comment.Account.Actor
: videoAccount.Actor
- const threadParentComments = await VideoCommentModel.listThreadParentComments({ comment: videoComment, transaction })
+ const threadParentComments = await VideoCommentModel.listThreadParentComments({ comment, transaction })
const threadParentCommentsFiltered = threadParentComments.filter(c => !c.isDeleted() && !c.heldForReview)
- const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, transaction)
- actorsInvolvedInComment.push(byActor) // Add the actor that commented the video
-
- const audience = getVideoCommentAudience(videoComment, threadParentCommentsFiltered, actorsInvolvedInComment, isVideoOrigin)
- const activity = buildDeleteActivity(url, videoComment.url, byActor, audience)
+ const video = await VideoModel.loadByUrlAndPopulateAccount(comment.Video.url, transaction)
+ const audience = getCommentAudience({ video, comment, threadParentComments: threadParentCommentsFiltered })
+ const activity = buildDeleteActivity(url, comment.url, byActor, audience)
// This was a reply, send it to the parent actors
const actorsException = [ byActor ]
@@ -94,6 +98,9 @@ async function sendDeleteVideoComment (videoComment: MCommentOwnerVideo, transac
// Send to actors involved in the comment
if (isVideoOrigin) {
+ const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, transaction)
+ actorsInvolvedInComment.push(byActor) // Add the actor that commented the video
+
return broadcastToFollowers({
data: activity,
byActor,
diff --git a/server/core/lib/activitypub/send/send-dislike.ts b/server/core/lib/activitypub/send/send-dislike.ts
index ea414885d0..6b08e37a49 100644
--- a/server/core/lib/activitypub/send/send-dislike.ts
+++ b/server/core/lib/activitypub/send/send-dislike.ts
@@ -4,7 +4,7 @@ import { logger } from '../../../helpers/logger.js'
import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models/index.js'
import { audiencify, getPublicAudience } from '../audience.js'
import { getVideoDislikeActivityPubUrlByLocalActor } from '../url.js'
-import { sendVideoActivityToOrigin } from './shared/send-utils.js'
+import { sendVideoRelatedActivityToOrigin } from './shared/send-utils.js'
function sendDislike (byActor: MActor, video: MVideoAccountLight, transaction: Transaction) {
logger.info('Creating job to dislike %s.', video.url)
@@ -15,7 +15,7 @@ function sendDislike (byActor: MActor, video: MVideoAccountLight, transaction: T
return buildDislikeActivity(url, byActor, video, audience)
}
- return sendVideoActivityToOrigin(activityBuilder, { byActor, video, transaction, contextType: 'Rate' })
+ return sendVideoRelatedActivityToOrigin(activityBuilder, { byActor, video, transaction, contextType: 'Rate' })
}
function buildDislikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityDislike {
diff --git a/server/core/lib/activitypub/send/send-like.ts b/server/core/lib/activitypub/send/send-like.ts
index 682a568963..800c7066d4 100644
--- a/server/core/lib/activitypub/send/send-like.ts
+++ b/server/core/lib/activitypub/send/send-like.ts
@@ -4,7 +4,7 @@ import { logger } from '../../../helpers/logger.js'
import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models/index.js'
import { audiencify, getPublicAudience } from '../audience.js'
import { getVideoLikeActivityPubUrlByLocalActor } from '../url.js'
-import { sendVideoActivityToOrigin } from './shared/send-utils.js'
+import { sendVideoRelatedActivityToOrigin } from './shared/send-utils.js'
function sendLike (byActor: MActor, video: MVideoAccountLight, transaction: Transaction) {
logger.info('Creating job to like %s.', video.url)
@@ -15,7 +15,7 @@ function sendLike (byActor: MActor, video: MVideoAccountLight, transaction: Tran
return buildLikeActivity(url, byActor, video, audience)
}
- return sendVideoActivityToOrigin(activityBuilder, { byActor, video, transaction, contextType: 'Rate' })
+ return sendVideoRelatedActivityToOrigin(activityBuilder, { byActor, video, transaction, contextType: 'Rate' })
}
function buildLikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityLike {
diff --git a/server/core/lib/activitypub/send/send-undo.ts b/server/core/lib/activitypub/send/send-undo.ts
index 9c93530dd7..237132dbef 100644
--- a/server/core/lib/activitypub/send/send-undo.ts
+++ b/server/core/lib/activitypub/send/send-undo.ts
@@ -1,5 +1,5 @@
-import { Transaction } from 'sequelize'
import { ActivityAudience, ActivityDislike, ActivityLike, ActivityUndo, ActivityUndoObject, ContextType } from '@peertube/peertube-models'
+import { Transaction } from 'sequelize'
import { logger } from '../../../helpers/logger.js'
import { VideoModel } from '../../../models/video/video.js'
import {
@@ -19,7 +19,13 @@ import { buildCreateActivity } from './send-create.js'
import { buildDislikeActivity } from './send-dislike.js'
import { buildFollowActivity } from './send-follow.js'
import { buildLikeActivity } from './send-like.js'
-import { broadcastToFollowers, sendVideoActivityToOrigin, sendVideoRelatedActivity, unicastTo } from './shared/send-utils.js'
+import {
+ broadcastToFollowers,
+ getActorsInvolvedInVideo,
+ sendVideoRelatedActivity,
+ sendVideoRelatedActivityToOrigin,
+ unicastTo
+} from './shared/send-utils.js'
function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) {
const me = actorFollow.ActorFollower
@@ -52,13 +58,13 @@ async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare,
const undoUrl = getUndoActivityPubUrl(videoShare.url)
- const { activity: announce, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, transaction)
+ const announce = buildAnnounceWithVideoAudience(byActor, videoShare, video)
const undoActivity = undoActivityData(undoUrl, byActor, announce)
return broadcastToFollowers({
data: undoActivity,
byActor,
- toFollowersOf: actorsInvolvedInVideo,
+ toFollowersOf: await getActorsInvolvedInVideo(video, transaction),
transaction,
actorsException: [ byActor ],
contextType: 'Announce'
@@ -110,11 +116,11 @@ async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: T
// ---------------------------------------------------------------------------
export {
- sendUndoFollow,
- sendUndoLike,
- sendUndoDislike,
sendUndoAnnounce,
- sendUndoCacheFile
+ sendUndoCacheFile,
+ sendUndoDislike,
+ sendUndoFollow,
+ sendUndoLike
}
// ---------------------------------------------------------------------------
@@ -168,5 +174,5 @@ async function sendUndoVideoRateToOriginActivity (options: {
return undoActivityData(undoUrl, options.byActor, options.activity, audience)
}
- return sendVideoActivityToOrigin(activityBuilder, { ...options, contextType: 'Rate' })
+ return sendVideoRelatedActivityToOrigin(activityBuilder, { ...options, contextType: 'Rate' })
}
diff --git a/server/core/lib/activitypub/send/send-update.ts b/server/core/lib/activitypub/send/send-update.ts
index fa439bbfb9..b4f1b76bdf 100644
--- a/server/core/lib/activitypub/send/send-update.ts
+++ b/server/core/lib/activitypub/send/send-update.ts
@@ -20,8 +20,7 @@ import {
import { audiencify, getPlaylistAudience, getPublicAudience, getVideoAudience } from '../audience.js'
import { getLocalChannelPlayerSettingsActivityPubUrl, getLocalVideoPlayerSettingsActivityPubUrl, getUpdateActivityPubUrl } from '../url.js'
import { canVideoBeFederated } from '../videos/federate.js'
-import { getActorsInvolvedInVideo } from './shared/index.js'
-import { broadcastToFollowers, sendVideoRelatedActivity } from './shared/send-utils.js'
+import { broadcastToFollowers, getActorsInvolvedInVideo, sendVideoRelatedActivity } from './shared/send-utils.js'
export async function sendUpdateVideo (videoArg: MVideoAPLight, transaction: Transaction, overriddenByActor?: MActor) {
if (!canVideoBeFederated(videoArg)) return undefined
@@ -35,7 +34,7 @@ export async function sendUpdateVideo (videoArg: MVideoAPLight, transaction: Tra
const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
const videoObject = await video.toActivityPubObject()
- const audience = getVideoAudience(byActor, video.privacy)
+ const audience = getVideoAudience({ account: video.VideoChannel.Account, channel: video.VideoChannel, privacy: video.privacy })
const updateActivity = buildUpdateActivity(url, byActor, videoObject, audience)
@@ -130,7 +129,7 @@ export async function sendUpdateVideoPlayerSettings (video: MVideoFullLight, set
const updateUrl = getUpdateActivityPubUrl(settingsUrl, settings.updatedAt.toISOString())
const object = PlayerSettingModel.formatAPPlayerSetting({ settings, video, channel: undefined })
- const audience = getVideoAudience(byActor, video.privacy)
+ const audience = getVideoAudience({ account: video.VideoChannel.Account, channel: video.VideoChannel, privacy: video.privacy })
const updateActivity = buildUpdateActivity(updateUrl, byActor, object, audience)
diff --git a/server/core/lib/activitypub/send/shared/audience-utils.ts b/server/core/lib/activitypub/send/shared/audience-utils.ts
deleted file mode 100644
index 3616694ebc..0000000000
--- a/server/core/lib/activitypub/send/shared/audience-utils.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-import { ActivityAudience } from '@peertube/peertube-models'
-import { getAPPublicValue } from '@server/helpers/activity-pub-utils.js'
-import { ActorModel } from '@server/models/actor/actor.js'
-import { VideoShareModel } from '@server/models/video/video-share.js'
-import { VideoModel } from '@server/models/video/video.js'
-import { MActorFollowersUrl, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '@server/types/models/index.js'
-import { Transaction } from 'sequelize'
-
-export function getOriginVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[] = []): ActivityAudience {
- return {
- to: [ accountActor.url ],
- cc: actorsInvolvedInVideo.map(a => a.followersUrl)
- }
-}
-
-export function getVideoCommentAudience (
- videoComment: MCommentOwnerVideo,
- threadParentComments: MCommentOwner[],
- actorsInvolvedInVideo: MActorFollowersUrl[],
- isOrigin = false
-): ActivityAudience {
- const to = [ getAPPublicValue() ]
- const cc: string[] = []
-
- // Owner of the video we comment
- if (isOrigin === false) {
- cc.push(videoComment.Video.VideoChannel.Account.Actor.url)
- }
-
- // Followers of the poster
- cc.push(videoComment.Account.Actor.followersUrl)
-
- // Send to actors we reply to
- for (const parentComment of threadParentComments) {
- if (parentComment.isDeleted()) continue
-
- cc.push(parentComment.Account.Actor.url)
- }
-
- return {
- to,
- cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
- }
-}
-
-export function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[]): ActivityAudience {
- return {
- to: [ getAPPublicValue() as string ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
- cc: []
- }
-}
-
-export async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
- const actors = await VideoShareModel.listActorIdsAndFollowerUrlsByShare(video.id, t)
-
- const alreadyLoadedActor = (video as VideoModel).VideoChannel?.Account?.Actor
-
- const videoActor = alreadyLoadedActor?.url && alreadyLoadedActor?.followersUrl
- ? alreadyLoadedActor
- : await ActorModel.loadAccountActorFollowerUrlByVideoId(video.id, t)
-
- if (videoActor) actors.push(videoActor)
-
- return actors
-}
diff --git a/server/core/lib/activitypub/send/shared/index.ts b/server/core/lib/activitypub/send/shared/index.ts
deleted file mode 100644
index 25beeafbfc..0000000000
--- a/server/core/lib/activitypub/send/shared/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export * from './audience-utils.js'
-export * from './send-utils.js'
diff --git a/server/core/lib/activitypub/send/shared/send-utils.ts b/server/core/lib/activitypub/send/shared/send-utils.ts
index ba17a528f4..c5f1b9d213 100644
--- a/server/core/lib/activitypub/send/shared/send-utils.ts
+++ b/server/core/lib/activitypub/send/shared/send-utils.ts
@@ -1,7 +1,9 @@
-import { Transaction } from 'sequelize'
import { Activity, ActivityAudience, ActivitypubHttpBroadcastPayload, ContextType } from '@peertube/peertube-models'
import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache.js'
import { getServerActor } from '@server/models/application/application.js'
+import { VideoShareModel } from '@server/models/video/video-share.js'
+import { VideoModel } from '@server/models/video/video.js'
+import { Transaction } from 'sequelize'
import { afterCommitIfTransaction } from '../../../../helpers/database-utils.js'
import { logger } from '../../../../helpers/logger.js'
import { ActorFollowModel } from '../../../../models/actor/actor-follow.js'
@@ -16,8 +18,7 @@ import {
MVideoImmutable
} from '../../../../types/models/index.js'
import { JobQueue } from '../../../job-queue/index.js'
-import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getOriginVideoAudience } from './audience-utils.js'
-import { arrayify } from '@peertube/peertube-core-utils'
+import { getDirectAudience, getVideoAudience } from '../../audience.js'
async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: {
byActor: MActorLight
@@ -26,17 +27,18 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud
parallelizable?: boolean
transaction?: Transaction
}) {
- const { byActor, video, transaction, contextType, parallelizable } = options
+ const { byActor, transaction, contextType, parallelizable } = options
// Send to origin
- if (video.isLocal() === false) {
- return sendVideoActivityToOrigin(activityBuilder, options)
+ if (options.video.isLocal() === false) {
+ return sendVideoRelatedActivityToOrigin(activityBuilder, options)
}
+ const video = await VideoModel.loadByUrlAndPopulateAccount(options.video.url, transaction)
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, transaction)
// Send to followers
- const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo)
+ const audience = getVideoAudience({ account: video.VideoChannel.Account, channel: video.VideoChannel, privacy: video.privacy })
const activity = activityBuilder(audience)
const actorsException = [ byActor ]
@@ -52,22 +54,23 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud
})
}
-async function sendVideoActivityToOrigin (activityBuilder: (audience: ActivityAudience) => Activity, options: {
- byActor: MActorLight
- video: MVideoImmutable | MVideoAccountLight
- contextType: ContextType
-
- actorsInvolvedInVideo?: MActorLight[]
- transaction?: Transaction
-}) {
- const { byActor, video, actorsInvolvedInVideo, transaction, contextType } = options
+async function sendVideoRelatedActivityToOrigin (
+ activityBuilder: (audience: ActivityAudience) => Activity,
+ options: {
+ byActor: MActorLight
+ video: MVideoImmutable | MVideoAccountLight
+ contextType: ContextType
+ transaction?: Transaction
+ }
+) {
+ const { byActor, video, transaction, contextType } = options
if (video.isLocal()) throw new Error('Cannot send activity to owned video origin ' + video.url)
let accountActor: MActorLight = (video as MVideoAccountLight).VideoChannel?.Account?.Actor
if (!accountActor) accountActor = await ActorModel.loadAccountActorByVideoId(video.id, transaction)
- const audience = getOriginVideoAudience(accountActor, actorsInvolvedInVideo)
+ const audience = getDirectAudience(accountActor)
const activity = activityBuilder(audience)
return afterCommitIfTransaction(transaction, () => {
@@ -82,39 +85,24 @@ async function sendVideoActivityToOrigin (activityBuilder: (audience: ActivityAu
// ---------------------------------------------------------------------------
-async function forwardVideoRelatedActivity (
- activity: Activity,
- t: Transaction,
- followersException: MActorWithInboxes[],
+async function forwardVideoRelatedActivity (options: {
+ activity: Activity
+ transaction: Transaction
+ followersException: MActorWithInboxes[]
video: MVideoId
-) {
+}) {
+ const { activity, transaction, followersException, video } = options
+
// Mastodon does not add our announces in audience, so we forward to them manually
- const additionalActors = await getActorsInvolvedInVideo(video, t)
+ const additionalActors = await getActorsInvolvedInVideo(video, transaction)
const additionalFollowerUrls = additionalActors.map(a => a.followersUrl)
- return forwardActivity(activity, t, followersException, additionalFollowerUrls)
-}
-
-async function forwardActivity (
- activity: Activity,
- t: Transaction,
- followersException: MActorWithInboxes[] = [],
- additionalFollowerUrls: string[] = []
-) {
logger.info('Forwarding activity %s.', activity.id)
- const to = arrayify(activity.to)
- const cc = arrayify(activity.cc)
-
const followersUrls = additionalFollowerUrls
- for (const dest of to.concat(cc)) {
- if (dest.endsWith('/followers')) {
- followersUrls.push(dest)
- }
- }
- const toActorFollowers = await ActorModel.listByFollowersUrls(followersUrls, t)
- const uris = await computeFollowerUris(toActorFollowers, followersException, t)
+ const toActorFollowers = await ActorModel.listByFollowersUrls(followersUrls, transaction)
+ const uris = await computeFollowerUris(toActorFollowers, followersException, transaction)
if (uris.length === 0) {
logger.info('0 followers for %s, no forwarding.', toActorFollowers.map(a => a.id).join(', '))
@@ -128,7 +116,8 @@ async function forwardActivity (
body: activity,
contextType: null
}
- return afterCommitIfTransaction(t, () => JobQueue.Instance.createJobAsync({ type: 'activitypub-http-broadcast', payload }))
+
+ return afterCommitIfTransaction(transaction, () => JobQueue.Instance.createJobAsync({ type: 'activitypub-http-broadcast', payload }))
}
// ---------------------------------------------------------------------------
@@ -256,13 +245,29 @@ function unicastTo (options: {
// ---------------------------------------------------------------------------
+export async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
+ const actors = await VideoShareModel.listActorIdsAndFollowerUrlsByShare(video.id, t)
+
+ const alreadyLoadedActor = (video as VideoModel).VideoChannel?.Account?.Actor
+
+ const videoActor = alreadyLoadedActor?.url && alreadyLoadedActor?.followersUrl
+ ? alreadyLoadedActor
+ : await ActorModel.loadAccountActorFollowerUrlByVideoId(video.id, t)
+
+ if (videoActor) actors.push(videoActor)
+
+ return actors
+}
+
+// ---------------------------------------------------------------------------
+
export {
- broadcastToFollowers,
- unicastTo,
broadcastToActors,
- sendVideoActivityToOrigin,
+ broadcastToFollowers,
forwardVideoRelatedActivity,
- sendVideoRelatedActivity
+ sendVideoRelatedActivity,
+ sendVideoRelatedActivityToOrigin,
+ unicastTo
}
// ---------------------------------------------------------------------------
diff --git a/server/core/lib/user-import-export/exporters/videos-exporter.ts b/server/core/lib/user-import-export/exporters/videos-exporter.ts
index a2d934b4d2..0c66ffbc0a 100644
--- a/server/core/lib/user-import-export/exporters/videos-exporter.ts
+++ b/server/core/lib/user-import-export/exporters/videos-exporter.ts
@@ -292,7 +292,13 @@ export class VideosExporter extends AbstractUserExporter<VideoExportJSON> {
): Promise<ActivityCreate<VideoObject>> {
const icon = video.getPreview()
- const audience = getVideoAudience(video.VideoChannel.Account.Actor, video.privacy, { skipPrivacyCheck: true })
+ const audience = getVideoAudience({
+ account: video.VideoChannel.Account,
+ channel: video.VideoChannel,
+ privacy: video.privacy,
+ skipPrivacyCheck: true
+ })
+
const videoObject: VideoObject = {
...audiencify(await video.toActivityPubObject(), audience),
diff --git a/server/core/types/models/video/video-channel.ts b/server/core/types/models/video/video-channel.ts
index 8cc85603f1..7ee9780ff3 100644
--- a/server/core/types/models/video/video-channel.ts
+++ b/server/core/types/models/video/video-channel.ts
@@ -18,6 +18,7 @@ import {
MActorAPChannel,
MActorAPI,
MActorAccountChannelId,
+ MActorAudience,
MActorDefault,
MActorDefaultBanner,
MActorDefaultLight,
@@ -67,6 +68,7 @@ export type MChannelActor =
& Use<'Actor', MActor>
export type MChannelUrl = Use<'Actor', MActorUrl>
+export type MChannelAudience = Use<'Actor', MActorAudience>
// Default scope
export type MChannelDefault =