aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-delete.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/send/send-delete.ts')
-rw-r--r--server/lib/activitypub/send/send-delete.ts40
1 files changed, 29 insertions, 11 deletions
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts
index 9f1ea3bd0..bb5d6913c 100644
--- a/server/lib/activitypub/send/send-delete.ts
+++ b/server/lib/activitypub/send/send-delete.ts
@@ -1,11 +1,11 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityDelete } from '../../../../shared/models/activitypub' 2import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub'
3import { ActorModel } from '../../../models/activitypub/actor' 3import { ActorModel } from '../../../models/activitypub/actor'
4import { VideoModel } from '../../../models/video/video' 4import { VideoModel } from '../../../models/video/video'
5import { VideoCommentModel } from '../../../models/video/video-comment' 5import { VideoCommentModel } from '../../../models/video/video-comment'
6import { VideoShareModel } from '../../../models/video/video-share' 6import { VideoShareModel } from '../../../models/video/video-share'
7import { getDeleteActivityPubUrl } from '../url' 7import { getDeleteActivityPubUrl } from '../url'
8import { broadcastToFollowers } from './misc' 8import { audiencify, broadcastToActors, broadcastToFollowers, getActorsInvolvedInVideo, getVideoCommentAudience, unicastTo } from './misc'
9 9
10async function sendDeleteVideo (video: VideoModel, t: Transaction) { 10async function sendDeleteVideo (video: VideoModel, t: Transaction) {
11 const url = getDeleteActivityPubUrl(video.url) 11 const url = getDeleteActivityPubUrl(video.url)
@@ -30,16 +30,30 @@ async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
30} 30}
31 31
32async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) { 32async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
33 const url = getDeleteActivityPubUrl(videoComment.url) 33 const isVideoOrigin = videoComment.Video.isOwned()
34 34
35 const url = getDeleteActivityPubUrl(videoComment.url)
35 const byActor = videoComment.Account.Actor 36 const byActor = videoComment.Account.Actor
36 const data = deleteActivityData(url, videoComment.url, byActor) 37 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t)
37 38
38 const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t) 39 const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t)
39 actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor) 40 actorsInvolvedInComment.push(byActor)
40 actorsInvolved.push(byActor)
41 41
42 return broadcastToFollowers(data, byActor, actorsInvolved, t) 42 const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin)
43 const data = deleteActivityData(url, videoComment.url, byActor, audience)
44
45 // This was a reply, send it to the parent actors
46 const actorsException = [ byActor ]
47 await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
48
49 // Broadcast to our followers
50 await broadcastToFollowers(data, byActor, [ byActor ], t)
51
52 // Send to actors involved in the comment
53 if (isVideoOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
54
55 // Send to origin
56 return unicastTo(data, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
43} 57}
44 58
45// --------------------------------------------------------------------------- 59// ---------------------------------------------------------------------------
@@ -52,11 +66,15 @@ export {
52 66
53// --------------------------------------------------------------------------- 67// ---------------------------------------------------------------------------
54 68
55function deleteActivityData (url: string, object: string, byActor: ActorModel): ActivityDelete { 69function deleteActivityData (url: string, object: string, byActor: ActorModel, audience?: ActivityAudience): ActivityDelete {
56 return { 70 const activity = {
57 type: 'Delete', 71 type: 'Delete' as 'Delete',
58 id: url, 72 id: url,
59 actor: byActor.url, 73 actor: byActor.url,
60 object 74 object
61 } 75 }
76
77 if (audience) return audiencify(activity, audience)
78
79 return activity
62} 80}