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'
|
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-09-14 09:51:35 -05:00
|
|
|
import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
|
2018-05-25 04:32:36 -05:00
|
|
|
import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience'
|
2018-07-30 10:02:40 -05:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2019-08-15 04:53:26 -05:00
|
|
|
import { MCommentOwnerVideoReply, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../typings/models/video'
|
|
|
|
import { MActorUrl } from '../../../typings/models'
|
2020-04-23 02:32:53 -05:00
|
|
|
import { getServerActor } from '@server/models/application/application'
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) {
|
2018-07-30 10:02:40 -05:00
|
|
|
logger.info('Creating job to broadcast delete of video %s.', 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-09-14 09:51:35 -05:00
|
|
|
const activityBuilder = (audience: ActivityAudience) => {
|
|
|
|
const url = getDeleteActivityPubUrl(video.url)
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2018-09-14 09:51:35 -05:00
|
|
|
return buildDeleteActivity(url, video.url, byActor, audience)
|
|
|
|
}
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2018-09-14 09:51:35 -05:00
|
|
|
return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction })
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
|
2018-07-30 10:02:40 -05:00
|
|
|
logger.info('Creating job to broadcast delete of actor %s.', byActor.url)
|
|
|
|
|
2018-01-04 09:56:36 -06:00
|
|
|
const url = getDeleteActivityPubUrl(byActor.url)
|
2018-09-11 09:27:07 -05:00
|
|
|
const activity = buildDeleteActivity(url, byActor.url, byActor)
|
2017-11-20 02:43:39 -06:00
|
|
|
|
2019-03-05 03:58:44 -06:00
|
|
|
const actorsInvolved = await VideoShareModel.loadActorsWhoSharedVideosOf(byActor.id, t)
|
|
|
|
|
|
|
|
// In case the actor did not have any videos
|
|
|
|
const serverActor = await getServerActor()
|
|
|
|
actorsInvolved.push(serverActor)
|
|
|
|
|
2018-01-18 03:53:54 -06:00
|
|
|
actorsInvolved.push(byActor)
|
|
|
|
|
2018-09-11 09:27:07 -05:00
|
|
|
return broadcastToFollowers(activity, byActor, actorsInvolved, t)
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
async function sendDeleteVideoComment (videoComment: MCommentOwnerVideoReply, t: Transaction) {
|
2018-07-30 10:02:40 -05:00
|
|
|
logger.info('Creating job to send delete of comment %s.', videoComment.url)
|
|
|
|
|
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)
|
2019-08-07 08:35:29 -05:00
|
|
|
const byActor = videoComment.isOwned()
|
|
|
|
? videoComment.Account.Actor
|
|
|
|
: videoComment.Video.VideoChannel.Account.Actor
|
|
|
|
|
2018-03-27 03:26:52 -05:00
|
|
|
const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t)
|
2019-12-04 04:48:12 -06:00
|
|
|
const threadParentCommentsFiltered = threadParentComments.filter(c => !c.isDeleted())
|
2018-01-04 04:19:16 -06:00
|
|
|
|
2018-03-27 03:26:52 -05:00
|
|
|
const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t)
|
2018-09-11 09:27:07 -05:00
|
|
|
actorsInvolvedInComment.push(byActor) // Add the actor that commented the video
|
2018-01-04 04:19:16 -06:00
|
|
|
|
2019-12-04 04:48:12 -06:00
|
|
|
const audience = getVideoCommentAudience(videoComment, threadParentCommentsFiltered, actorsInvolvedInComment, isVideoOrigin)
|
2018-09-11 09:27:07 -05:00
|
|
|
const activity = buildDeleteActivity(url, videoComment.url, byActor, audience)
|
2018-03-27 03:26:52 -05:00
|
|
|
|
|
|
|
// This was a reply, send it to the parent actors
|
|
|
|
const actorsException = [ byActor ]
|
2019-12-04 04:48:12 -06:00
|
|
|
await broadcastToActors(activity, byActor, threadParentCommentsFiltered.map(c => c.Account.Actor), t, actorsException)
|
2018-03-27 03:26:52 -05:00
|
|
|
|
|
|
|
// Broadcast to our followers
|
2018-09-11 09:27:07 -05:00
|
|
|
await broadcastToFollowers(activity, byActor, [ byActor ], t)
|
2018-03-27 03:26:52 -05:00
|
|
|
|
|
|
|
// Send to actors involved in the comment
|
2018-09-11 09:27:07 -05:00
|
|
|
if (isVideoOrigin) return broadcastToFollowers(activity, byActor, actorsInvolvedInComment, t, actorsException)
|
2018-03-27 03:26:52 -05:00
|
|
|
|
|
|
|
// Send to origin
|
2019-10-23 04:33:53 -05:00
|
|
|
t.afterCommit(() => unicastTo(activity, byActor, videoComment.Video.VideoChannel.Account.Actor.getSharedInbox()))
|
2018-01-04 04:19:16 -06:00
|
|
|
}
|
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
async function sendDeleteVideoPlaylist (videoPlaylist: MVideoPlaylistFullSummary, t: Transaction) {
|
2019-02-26 03:55:40 -06:00
|
|
|
logger.info('Creating job to send delete of playlist %s.', videoPlaylist.url)
|
|
|
|
|
|
|
|
const byActor = videoPlaylist.OwnerAccount.Actor
|
|
|
|
|
|
|
|
const url = getDeleteActivityPubUrl(videoPlaylist.url)
|
|
|
|
const activity = buildDeleteActivity(url, videoPlaylist.url, byActor)
|
|
|
|
|
|
|
|
const serverActor = await getServerActor()
|
|
|
|
const toFollowersOf = [ byActor, serverActor ]
|
|
|
|
|
|
|
|
if (videoPlaylist.VideoChannel) toFollowersOf.push(videoPlaylist.VideoChannel.Actor)
|
|
|
|
|
|
|
|
return broadcastToFollowers(activity, byActor, toFollowersOf, t)
|
|
|
|
}
|
|
|
|
|
2017-11-20 02:43:39 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendDeleteVideo,
|
2018-01-04 04:19:16 -06:00
|
|
|
sendDeleteActor,
|
2019-02-26 03:55:40 -06:00
|
|
|
sendDeleteVideoComment,
|
|
|
|
sendDeleteVideoPlaylist
|
2017-11-20 02:43:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
function buildDeleteActivity (url: string, object: string, byActor: MActorUrl, audience?: ActivityAudience): ActivityDelete {
|
2018-03-27 03:26:52 -05:00
|
|
|
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
|
|
|
}
|