X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fsend%2Fsend-create.ts;h=249dd91dc846155f1dcb821621fe3a480a198812;hb=e12a009254de33bcdbd8334992980fa029c3e10d;hp=113d892335a667bc3e1cbcfcf3c5fb3d82cf96dd;hpb=63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 113d89233..249dd91dc 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts @@ -1,115 +1,121 @@ import { Transaction } from 'sequelize' -import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub/activity' -import { getServerAccount } from '../../../helpers/utils' -import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' -import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface' +import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' +import { VideoPrivacy } from '../../../../shared/models/videos' +import { getServerActor } from '../../../helpers' +import { ActorModel } from '../../../models/activitypub/actor' +import { VideoModel } from '../../../models/video/video' +import { VideoAbuseModel } from '../../../models/video/video-abuse' import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' import { + audiencify, broadcastToFollowers, - getAccountsInvolvedInVideo, + getActorsInvolvedInVideo, getAudience, + getObjectFollowersAudience, getOriginVideoAudience, - getVideoFollowersAudience, unicastTo } from './misc' -async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { - const byAccount = videoChannel.Account +async function sendCreateVideo (video: VideoModel, t: Transaction) { + if (video.privacy === VideoPrivacy.PRIVATE) return - const videoChannelObject = videoChannel.toActivityPubObject() - const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject) + const byActor = video.VideoChannel.Account.Actor + const videoObject = video.toActivityPubObject() - return broadcastToFollowers(data, byAccount, [ byAccount ], t) + const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) + const data = await createActivityData(video.url, byActor, videoObject, t, audience) + + return broadcastToFollowers(data, byActor, [ byActor ], t) } -async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbuseInstance, video: VideoInstance, t: Transaction) { +async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { const url = getVideoAbuseActivityPubUrl(videoAbuse) - const audience = { to: [ video.VideoChannel.Account.url ], cc: [] } - const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), audience) + const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] } + const data = await createActivityData(url, byActor, videoAbuse.toActivityPubObject(), t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { - const url = getVideoViewActivityPubUrl(byAccount, video) - const viewActivity = createViewActivityData(byAccount, video) +async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getVideoViewActivityPubUrl(byActor, video) + const viewActivity = createViewActivityData(byActor, video) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) - const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) - const data = await createActivityData(url, byAccount, viewActivity, audience) + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) + const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) + const data = await createActivityData(url, byActor, viewActivity, t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { - const url = getVideoViewActivityPubUrl(byAccount, video) - const viewActivity = createViewActivityData(byAccount, video) +async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getVideoViewActivityPubUrl(byActor, video) + const viewActivity = createViewActivityData(byActor, video) - const accountsToForwardView = await getAccountsInvolvedInVideo(video) - const audience = getVideoFollowersAudience(accountsToForwardView) - const data = await createActivityData(url, byAccount, viewActivity, audience) + const actorsToForwardView = await getActorsInvolvedInVideo(video, t) + const audience = getObjectFollowersAudience(actorsToForwardView) + const data = await createActivityData(url, byActor, viewActivity, t, audience) - // Use the server account to send the view, because it could be an unregistered account - const serverAccount = await getServerAccount() - const followersException = [ byAccount ] - return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) + // Use the server actor to send the view + const serverActor = await getServerActor() + const followersException = [ byActor ] + return broadcastToFollowers(data, serverActor, actorsToForwardView, t, followersException) } -async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { - const url = getVideoDislikeActivityPubUrl(byAccount, video) - const dislikeActivity = createDislikeActivityData(byAccount, video) +async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getVideoDislikeActivityPubUrl(byActor, video) + const dislikeActivity = createDislikeActivityData(byActor, video) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) - const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) - const data = await createActivityData(url, byAccount, dislikeActivity, audience) + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) + const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) + const data = await createActivityData(url, byActor, dislikeActivity, t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { - const url = getVideoDislikeActivityPubUrl(byAccount, video) - const dislikeActivity = createDislikeActivityData(byAccount, video) +async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getVideoDislikeActivityPubUrl(byActor, video) + const dislikeActivity = createDislikeActivityData(byActor, video) - const accountsToForwardView = await getAccountsInvolvedInVideo(video) - const audience = getVideoFollowersAudience(accountsToForwardView) - const data = await createActivityData(url, byAccount, dislikeActivity, audience) + const actorsToForwardView = await getActorsInvolvedInVideo(video, t) + const audience = getObjectFollowersAudience(actorsToForwardView) + const data = await createActivityData(url, byActor, dislikeActivity, t, audience) - const followersException = [ byAccount ] - return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException) + const followersException = [ byActor ] + return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) } -async function createActivityData (url: string, byAccount: AccountInstance, object: any, audience?: ActivityAudience) { +async function createActivityData ( + url: string, + byActor: ActorModel, + object: any, + t: Transaction, + audience?: ActivityAudience +): Promise { if (!audience) { - audience = await getAudience(byAccount) + audience = await getAudience(byActor, t) } - const activity: ActivityCreate = { + return audiencify({ type: 'Create', id: url, - actor: byAccount.url, - to: audience.to, - cc: audience.cc, - object - } - - return activity + actor: byActor.url, + object: audiencify(object, audience) + }, audience) } -function createDislikeActivityData (byAccount: AccountInstance, video: VideoInstance) { - const obj = { +function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { + return { type: 'Dislike', - actor: byAccount.url, + actor: byActor.url, object: video.url } - - return obj } // --------------------------------------------------------------------------- export { - sendCreateVideoChannel, + sendCreateVideo, sendVideoAbuse, createActivityData, sendCreateViewToOrigin, @@ -121,12 +127,10 @@ export { // --------------------------------------------------------------------------- -function createViewActivityData (byAccount: AccountInstance, video: VideoInstance) { - const obj = { +function createViewActivityData (byActor: ActorModel, video: VideoModel) { + return { type: 'View', - actor: byAccount.url, + actor: byActor.url, object: video.url } - - return obj }