X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fsend%2Fsend-delete.ts;h=995a534a637da979583b4130732fe314a031bc87;hb=c3badc81fe3d78601fb278a7f28eeed63060d300;hp=c49cda04f905f6da7e39614e7a145bfcfab5b3d4;hpb=25ed141c7c7631ef21d8764c1163fbf8a6591391;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts index c49cda04f..995a534a6 100644 --- a/server/lib/activitypub/send/send-delete.ts +++ b/server/lib/activitypub/send/send-delete.ts @@ -1,53 +1,59 @@ import { Transaction } from 'sequelize' -import { ActivityDelete } from '../../../../shared/models/activitypub/activity' -import { database as db } from '../../../initializers' -import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' +import { ActivityDelete } from '../../../../shared/models/activitypub' +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 { getDeleteActivityPubUrl } from '../url' import { broadcastToFollowers } from './misc' -async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { - const byAccount = videoChannel.Account +async function sendDeleteVideo (video: VideoModel, t: Transaction) { + const url = getDeleteActivityPubUrl(video.url) + const byActor = video.VideoChannel.Account.Actor - const data = deleteActivityData(videoChannel.url, byAccount) + const data = deleteActivityData(url, video.url, byActor) - const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t) - accountsInvolved.push(byAccount) + const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) + actorsInvolved.push(byActor) - return broadcastToFollowers(data, byAccount, accountsInvolved, t) + return broadcastToFollowers(data, byActor, actorsInvolved, t) } -async function sendDeleteVideo (video: VideoInstance, t: Transaction) { - const byAccount = video.VideoChannel.Account +async function sendDeleteActor (byActor: ActorModel, t: Transaction) { + const url = getDeleteActivityPubUrl(byActor.url) + const data = deleteActivityData(url, byActor.url, byActor) - const data = deleteActivityData(video.url, byAccount) + return broadcastToFollowers(data, byActor, [ byActor ], t) +} - const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id, t) - accountsInvolved.push(byAccount) +async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) { + const url = getDeleteActivityPubUrl(videoComment.url) - return broadcastToFollowers(data, byAccount, accountsInvolved, t) -} + const byActor = videoComment.Account.Actor + const data = deleteActivityData(url, videoComment.url, byActor) -async function sendDeleteAccount (account: AccountInstance, t: Transaction) { - const data = await deleteActivityData(account.url, account) + const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t) + actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor) + actorsInvolved.push(byActor) - return broadcastToFollowers(data, account, [ account ], t) + return broadcastToFollowers(data, byActor, actorsInvolved, t) } // --------------------------------------------------------------------------- export { - sendDeleteVideoChannel, sendDeleteVideo, - sendDeleteAccount + sendDeleteActor, + sendDeleteVideoComment } // --------------------------------------------------------------------------- -function deleteActivityData (url: string, byAccount: AccountInstance) { - const activity: ActivityDelete = { +function deleteActivityData (url: string, object: string, byActor: ActorModel): ActivityDelete { + return { type: 'Delete', id: url, - actor: byAccount.url + actor: byActor.url, + object } - - return activity }