X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fsend%2Fsend-create.ts;h=e5fb212b741f0e4bba0a1b815186b02d18f274d0;hb=40ff57078e15d5b86ee6b71e198b95d3feb78eaf;hp=66bfeee89371336c7bc8910f58eda9641a2240f0;hpb=54141398354e6e7b94aa3065a705a1251390111c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 66bfeee89..e5fb212b7 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts @@ -3,7 +3,9 @@ import { ActivityCreate } from '../../../../shared/models/activitypub/activity' import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface' import { broadcastToFollowers, getAudience, unicastTo } from './misc' -import { getVideoAbuseActivityPubUrl } from '../../../helpers/activitypub' +import { getVideoAbuseActivityPubUrl, getVideoViewActivityPubUrl } from '../url' +import { getServerAccount } from '../../../helpers/utils' +import { database as db } from '../../../initializers' async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { const byAccount = videoChannel.Account @@ -16,19 +18,53 @@ async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Tr async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbuseInstance, video: VideoInstance, t: Transaction) { const url = getVideoAbuseActivityPubUrl(videoAbuse) - const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject()) + + const audience = { to: [ video.VideoChannel.Account.url ], cc: [] } + const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), audience) + + return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) +} + +async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { + const url = getVideoViewActivityPubUrl(byAccount, video) + const viewActivity = createViewActivityData(byAccount, video) + + const audience = { to: [ video.VideoChannel.Account.url ], cc: [ video.VideoChannel.Account.url + '/followers' ] } + const data = await createActivityData(url, byAccount, viewActivity, audience) return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) } -async function createActivityData (url: string, byAccount: AccountInstance, object: any) { - const { to, cc } = await getAudience(byAccount) +async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { + const url = getVideoViewActivityPubUrl(byAccount, video) + const viewActivity = createViewActivityData(byAccount, video) + + const audience = { to: [ video.VideoChannel.Account.url + '/followers' ], cc: [] } + const data = await createActivityData(url, byAccount, viewActivity, audience) + + const serverAccount = await getServerAccount() + const accountsToForwardView = await db.VideoShare.loadAccountsByShare(video.id) + accountsToForwardView.push(video.VideoChannel.Account) + + // Don't forward view to server that sent it to us + const index = accountsToForwardView.findIndex(a => a.id === byAccount.id) + if (index) accountsToForwardView.splice(index, 1) + + const followersException = [ byAccount ] + return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) +} + +async function createActivityData (url: string, byAccount: AccountInstance, object: any, audience?: { to: string[], cc: string[] }) { + if (!audience) { + audience = await getAudience(byAccount) + } + const activity: ActivityCreate = { type: 'Create', id: url, actor: byAccount.url, - to, - cc, + to: audience.to, + cc: audience.cc, object } @@ -40,5 +76,19 @@ async function createActivityData (url: string, byAccount: AccountInstance, obje export { sendCreateVideoChannel, sendVideoAbuse, - createActivityData + createActivityData, + sendCreateViewToOrigin, + sendCreateViewToVideoFollowers +} + +// --------------------------------------------------------------------------- + +function createViewActivityData (byAccount: AccountInstance, video: VideoInstance) { + const obj = { + type: 'View', + actor: byAccount.url, + object: video.url + } + + return obj }