PeerTube/server/lib/activitypub/send/send-delete.ts

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-11-20 02:43:39 -06:00
import { Transaction } from 'sequelize'
2017-12-12 10:53:50 -06:00
import { ActivityDelete } from '../../../../shared/models/activitypub'
2017-12-14 10:38:41 -06:00
import { ActorModel } from '../../../models/activitypub/actor'
2017-12-12 10:53:50 -06:00
import { VideoModel } from '../../../models/video/video'
import { VideoShareModel } from '../../../models/video/video-share'
2017-11-20 02:43:39 -06:00
import { broadcastToFollowers } from './misc'
2017-12-12 10:53:50 -06:00
async function sendDeleteVideo (video: VideoModel, t: Transaction) {
2017-12-14 10:38:41 -06:00
const byActor = video.VideoChannel.Account.Actor
2017-11-20 02:43:39 -06:00
2017-12-14 10:38:41 -06:00
const data = deleteActivityData(video.url, byActor)
2017-11-20 02:43:39 -06:00
2017-12-14 10:38:41 -06:00
const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
actorsInvolved.push(byActor)
2017-11-20 02:43:39 -06:00
2017-12-14 10:38:41 -06:00
return broadcastToFollowers(data, byActor, actorsInvolved, t)
2017-11-20 02:43:39 -06:00
}
2017-12-14 10:38:41 -06:00
async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
const data = deleteActivityData(byActor.url, byActor)
2017-11-20 02:43:39 -06:00
2017-12-14 10:38:41 -06:00
return broadcastToFollowers(data, byActor, [ byActor ], t)
2017-11-20 02:43:39 -06:00
}
// ---------------------------------------------------------------------------
export {
sendDeleteVideo,
2017-12-14 10:38:41 -06:00
sendDeleteActor
2017-11-20 02:43:39 -06:00
}
// ---------------------------------------------------------------------------
2017-12-14 10:38:41 -06:00
function deleteActivityData (url: string, byActor: ActorModel): ActivityDelete {
2017-12-12 10:53:50 -06:00
return {
2017-11-20 02:43:39 -06:00
type: 'Delete',
id: url,
2017-12-14 10:38:41 -06:00
actor: byActor.url
2017-11-20 02:43:39 -06:00
}
}