1
0
Fork 0
peertube/server/lib/activitypub/send/send-delete.ts

60 lines
2 KiB
TypeScript
Raw Normal View History

2017-11-20 03:43:39 -05:00
import { Transaction } from 'sequelize'
2017-12-12 11:53:50 -05:00
import { ActivityDelete } from '../../../../shared/models/activitypub'
2017-12-14 11:38:41 -05:00
import { ActorModel } from '../../../models/activitypub/actor'
2017-12-12 11:53:50 -05:00
import { VideoModel } from '../../../models/video/video'
2018-01-04 05:19:16 -05:00
import { VideoCommentModel } from '../../../models/video/video-comment'
2017-12-12 11:53:50 -05:00
import { VideoShareModel } from '../../../models/video/video-share'
2018-01-04 10:56:36 -05:00
import { getDeleteActivityPubUrl } from '../url'
2017-11-20 03:43:39 -05:00
import { broadcastToFollowers } from './misc'
2017-12-12 11:53:50 -05:00
async function sendDeleteVideo (video: VideoModel, t: Transaction) {
2018-01-04 10:56:36 -05:00
const url = getDeleteActivityPubUrl(video.url)
2017-12-14 11:38:41 -05:00
const byActor = video.VideoChannel.Account.Actor
2017-11-20 03:43:39 -05:00
2018-01-04 10:56:36 -05:00
const data = deleteActivityData(url, video.url, byActor)
2017-11-20 03:43:39 -05:00
2017-12-14 11:38:41 -05:00
const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
actorsInvolved.push(byActor)
2017-11-20 03:43:39 -05:00
2017-12-14 11:38:41 -05:00
return broadcastToFollowers(data, byActor, actorsInvolved, t)
2017-11-20 03:43:39 -05:00
}
2017-12-14 11:38:41 -05:00
async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
2018-01-04 10:56:36 -05:00
const url = getDeleteActivityPubUrl(byActor.url)
const data = deleteActivityData(url, byActor.url, byActor)
2017-11-20 03:43:39 -05:00
2017-12-14 11:38:41 -05:00
return broadcastToFollowers(data, byActor, [ byActor ], t)
2017-11-20 03:43:39 -05:00
}
2018-01-04 05:19:16 -05:00
async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
2018-01-04 10:56:36 -05:00
const url = getDeleteActivityPubUrl(videoComment.url)
2018-01-04 05:19:16 -05:00
2018-01-04 10:56:36 -05:00
const byActor = videoComment.Account.Actor
const data = deleteActivityData(url, videoComment.url, byActor)
2018-01-04 05:19:16 -05:00
const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t)
actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor)
actorsInvolved.push(byActor)
return broadcastToFollowers(data, byActor, actorsInvolved, t)
}
2017-11-20 03:43:39 -05:00
// ---------------------------------------------------------------------------
export {
sendDeleteVideo,
2018-01-04 05:19:16 -05:00
sendDeleteActor,
sendDeleteVideoComment
2017-11-20 03:43:39 -05:00
}
// ---------------------------------------------------------------------------
2018-01-04 10:56:36 -05:00
function deleteActivityData (url: string, object: string, byActor: ActorModel): ActivityDelete {
2017-12-12 11:53:50 -05:00
return {
2017-11-20 03:43:39 -05:00
type: 'Delete',
id: url,
2018-01-04 10:56:36 -05:00
actor: byActor.url,
object
2017-11-20 03:43:39 -05:00
}
}