]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/send/send-delete.ts
Fix delete activities
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-delete.ts
index 0a45ea10f3054a01e55144172397801309f4f1de..995a534a637da979583b4130732fe314a031bc87 100644 (file)
@@ -1,54 +1,59 @@
 import { Transaction } from 'sequelize'
 import { ActivityDelete } from '../../../../shared/models/activitypub'
-import { AccountModel } from '../../../models/account/account'
+import { ActorModel } from '../../../models/activitypub/actor'
 import { VideoModel } from '../../../models/video/video'
-import { VideoChannelModel } from '../../../models/video/video-channel'
-import { VideoChannelShareModel } from '../../../models/video/video-channel-share'
+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: VideoChannelModel, 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 VideoChannelShareModel.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: VideoModel, 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 VideoShareModel.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: AccountModel, t: Transaction) {
-  const data = 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: AccountModel): ActivityDelete {
+function deleteActivityData (url: string, object: string, byActor: ActorModel): ActivityDelete {
   return {
     type: 'Delete',
     id: url,
-    actor: byAccount.url
+    actor: byActor.url,
+    object
   }
 }