X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Faudience.ts;h=6f54913875858aff5b10f5131282c2137248a34d;hb=ccd62a45024d90c004d0d38737fef055b3fe22b7;hp=c1265dbcd3314435cd68f53e2c3cce8bc63d447d;hpb=e3d5ea4f82ffbb51eae3471f004bf382b07ea04c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/audience.ts b/server/lib/activitypub/audience.ts index c1265dbcd..6f5491387 100644 --- a/server/lib/activitypub/audience.ts +++ b/server/lib/activitypub/audience.ts @@ -1,81 +1,28 @@ -import { Transaction } from 'sequelize' import { ActivityAudience } from '../../../shared/models/activitypub' -import { ACTIVITY_PUB } from '../../initializers' -import { ActorModel } from '../../models/activitypub/actor' -import { VideoModel } from '../../models/video/video' -import { VideoCommentModel } from '../../models/video/video-comment' -import { VideoShareModel } from '../../models/video/video-share' +import { ACTIVITY_PUB } from '../../initializers/constants' +import { MActorFollowersUrl } from '../../types/models' -function getVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]) { - return { - to: [ video.VideoChannel.Account.Actor.url ], - cc: actorsInvolvedInVideo.map(a => a.followersUrl) - } -} - -function getVideoCommentAudience ( - videoComment: VideoCommentModel, - threadParentComments: VideoCommentModel[], - actorsInvolvedInVideo: ActorModel[], - isOrigin = false -) { - const to = [ ACTIVITY_PUB.PUBLIC ] - const cc = [ ] - - // 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) { - cc.push(parentComment.Account.Actor.url) - } - - return { - to, - cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl)) - } -} - -function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { - return { - to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)), - cc: [] - } -} - -async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) { - const actors = await VideoShareModel.loadActorsByShare(video.id, t) - actors.push(video.VideoChannel.Account.Actor) - - return actors -} - -async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) { +function getAudience (actorSender: MActorFollowersUrl, isPublic = true) { return buildAudience([ actorSender.followersUrl ], isPublic) } function buildAudience (followerUrls: string[], isPublic = true) { - let to = [] - let cc = [] + let to: string[] = [] + let cc: string[] = [] if (isPublic) { to = [ ACTIVITY_PUB.PUBLIC ] cc = followerUrls } else { // Unlisted - to = [ ] - cc = [ ] + to = [] + cc = [] } return { to, cc } } -function audiencify (object: T, audience: ActivityAudience) { - return Object.assign(object, audience) +function audiencify (object: T, audience: ActivityAudience) { + return { ...audience, ...object } } // --------------------------------------------------------------------------- @@ -83,9 +30,5 @@ function audiencify (object: T, audience: ActivityAudience) { export { buildAudience, getAudience, - getVideoAudience, - getActorsInvolvedInVideo, - getObjectFollowersAudience, - audiencify, - getVideoCommentAudience + audiencify }