X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Faudience.ts;h=6f54913875858aff5b10f5131282c2137248a34d;hb=cea2fd90ddb3bf57c2fed77128938d12d4c2be6b;hp=9933ae2b5cd8b9176495475a74620fbf90c2d6fc;hpb=338eb9d33af690db716805fd2277bf68f473b58f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/audience.ts b/server/lib/activitypub/audience.ts index 9933ae2b5..6f5491387 100644 --- a/server/lib/activitypub/audience.ts +++ b/server/lib/activitypub/audience.ts @@ -1,66 +1,6 @@ -import { Transaction } from 'sequelize' import { ActivityAudience } from '../../../shared/models/activitypub' import { ACTIVITY_PUB } from '../../initializers/constants' -import { ActorModel } from '../../models/activitypub/actor' -import { VideoModel } from '../../models/video/video' -import { VideoShareModel } from '../../models/video/video-share' -import { MActorFollowersUrl, MActorLight, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '../../typings/models' - -function getRemoteVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience { - return { - to: [ accountActor.url ], - cc: actorsInvolvedInVideo.map(a => a.followersUrl) - } -} - -function getVideoCommentAudience ( - videoComment: MCommentOwnerVideo, - threadParentComments: MCommentOwner[], - actorsInvolvedInVideo: MActorFollowersUrl[], - isOrigin = false -): ActivityAudience { - const to = [ ACTIVITY_PUB.PUBLIC ] - 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) { - cc.push(parentComment.Account.Actor.url) - } - - return { - to, - cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl)) - } -} - -function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[]): ActivityAudience { - return { - to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)), - cc: [] - } -} - -async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) { - const actors: MActorLight[] = await VideoShareModel.loadActorsByShare(video.id, t) - - const videoAll = video as VideoModel - - const videoActor = videoAll.VideoChannel && videoAll.VideoChannel.Account - ? videoAll.VideoChannel.Account.Actor - : await ActorModel.loadFromAccountByVideoId(video.id, t) - - actors.push(videoActor) - - return actors -} +import { MActorFollowersUrl } from '../../types/models' function getAudience (actorSender: MActorFollowersUrl, isPublic = true) { return buildAudience([ actorSender.followersUrl ], isPublic) @@ -82,7 +22,7 @@ function buildAudience (followerUrls: string[], isPublic = true) { } function audiencify (object: T, audience: ActivityAudience) { - return Object.assign(object, audience) + return { ...audience, ...object } } // --------------------------------------------------------------------------- @@ -90,9 +30,5 @@ function audiencify (object: T, audience: ActivityAudience) { export { buildAudience, getAudience, - getRemoteVideoAudience, - getActorsInvolvedInVideo, - getAudienceFromFollowersOf, - audiencify, - getVideoCommentAudience + audiencify }