1
0
Fork 0
peertube/server/lib/activitypub/send/send-delete.ts
2017-12-19 10:53:16 +01:00

40 lines
1.2 KiB
TypeScript

import { Transaction } from 'sequelize'
import { ActivityDelete } from '../../../../shared/models/activitypub'
import { ActorModel } from '../../../models/activitypub/actor'
import { VideoModel } from '../../../models/video/video'
import { VideoShareModel } from '../../../models/video/video-share'
import { broadcastToFollowers } from './misc'
async function sendDeleteVideo (video: VideoModel, t: Transaction) {
const byActor = video.VideoChannel.Account.Actor
const data = deleteActivityData(video.url, byActor)
const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
actorsInvolved.push(byActor)
return broadcastToFollowers(data, byActor, actorsInvolved, t)
}
async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
const data = deleteActivityData(byActor.url, byActor)
return broadcastToFollowers(data, byActor, [ byActor ], t)
}
// ---------------------------------------------------------------------------
export {
sendDeleteVideo,
sendDeleteActor
}
// ---------------------------------------------------------------------------
function deleteActivityData (url: string, byActor: ActorModel): ActivityDelete {
return {
type: 'Delete',
id: url,
actor: byActor.url
}
}