2017-11-20 02:43:39 -06:00
|
|
|
import { Transaction } from 'sequelize'
|
2018-03-27 03:26:52 -05:00
|
|
|
import { ActivityAudience, 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'
|
2018-01-04 04:19:16 -06:00
|
|
|
import { VideoCommentModel } from '../../../models/video/video-comment'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { VideoShareModel } from '../../../models/video/video-share'
|
2018-01-04 09:56:36 -06:00
|
|
|
import { getDeleteActivityPubUrl } from '../url'
|
2018-05-25 04:32:36 -05:00
|
|
|
import { broadcastToActors, broadcastToFollowers, unicastTo } from './utils'
|
|
|
|
import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience'
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
async function sendDeleteVideo (video: VideoModel, t: Transaction) {
|
2018-01-04 09:56:36 -06:00
|
|
|
const url = getDeleteActivityPubUrl(video.url)
|
2017-12-14 10:38:41 -06:00
|
|
|
const byActor = video.VideoChannel.Account.Actor
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2018-01-04 09:56:36 -06:00
|
|
|
const data = deleteActivityData(url, 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) {
|
2018-01-04 09:56:36 -06:00
|
|
|
const url = getDeleteActivityPubUrl(byActor.url)
|
|
|
|
const data = deleteActivityData(url, byActor.url, byActor)
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2018-01-18 03:53:54 -06:00
|
|
|
const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
|
|
|
|
actorsInvolved.push(byActor)
|
|
|
|
|
|
|
|
return broadcastToFollowers(data, byActor, actorsInvolved, t)
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:19:16 -06:00
|
|
|
async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
|
2018-03-27 03:26:52 -05:00
|
|
|
const isVideoOrigin = videoComment.Video.isOwned()
|
2018-01-04 04:19:16 -06:00
|
|
|
|
2018-03-27 03:26:52 -05:00
|
|
|
const url = getDeleteActivityPubUrl(videoComment.url)
|
2018-01-04 09:56:36 -06:00
|
|
|
const byActor = videoComment.Account.Actor
|
2018-03-27 03:26:52 -05:00
|
|
|
const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t)
|
2018-01-04 04:19:16 -06:00
|
|
|
|
2018-03-27 03:26:52 -05:00
|
|
|
const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t)
|
|
|
|
actorsInvolvedInComment.push(byActor)
|
2018-01-04 04:19:16 -06:00
|
|
|
|
2018-03-27 03:26:52 -05:00
|
|
|
const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin)
|
|
|
|
const data = deleteActivityData(url, videoComment.url, byActor, audience)
|
|
|
|
|
|
|
|
// This was a reply, send it to the parent actors
|
|
|
|
const actorsException = [ byActor ]
|
|
|
|
await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
|
|
|
|
|
|
|
|
// Broadcast to our followers
|
|
|
|
await broadcastToFollowers(data, byActor, [ byActor ], t)
|
|
|
|
|
|
|
|
// Send to actors involved in the comment
|
|
|
|
if (isVideoOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
|
|
|
|
|
|
|
|
// Send to origin
|
|
|
|
return unicastTo(data, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
|
2018-01-04 04:19:16 -06:00
|
|
|
}
|
|
|
|
|
2017-11-20 02:43:39 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendDeleteVideo,
|
2018-01-04 04:19:16 -06:00
|
|
|
sendDeleteActor,
|
|
|
|
sendDeleteVideoComment
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2018-03-27 03:26:52 -05:00
|
|
|
function deleteActivityData (url: string, object: string, byActor: ActorModel, audience?: ActivityAudience): ActivityDelete {
|
|
|
|
const activity = {
|
|
|
|
type: 'Delete' as 'Delete',
|
2017-11-20 02:43:39 -06:00
|
|
|
id: url,
|
2018-01-04 09:56:36 -06:00
|
|
|
actor: byActor.url,
|
|
|
|
object
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|
2018-03-27 03:26:52 -05:00
|
|
|
|
|
|
|
if (audience) return audiencify(activity, audience)
|
|
|
|
|
|
|
|
return activity
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|