diff options
author | Chocobozzz <me@florianbigard.com> | 2018-03-27 10:26:52 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-03-27 11:11:15 +0200 |
commit | 73c0809326670867642f8a36f68d8564e0e406b5 (patch) | |
tree | b2849106a252f8b2108318d90767dcb747d9dd6c /server/lib/activitypub/send/send-delete.ts | |
parent | 649f0334e0673a28d1674aa82de29326fa3cdb63 (diff) | |
download | PeerTube-73c0809326670867642f8a36f68d8564e0e406b5.tar.gz PeerTube-73c0809326670867642f8a36f68d8564e0e406b5.tar.zst PeerTube-73c0809326670867642f8a36f68d8564e0e406b5.zip |
Fix delete comment federation
Diffstat (limited to 'server/lib/activitypub/send/send-delete.ts')
-rw-r--r-- | server/lib/activitypub/send/send-delete.ts | 40 |
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 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityDelete } from '../../../../shared/models/activitypub' | 2 | import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub' |
3 | import { ActorModel } from '../../../models/activitypub/actor' | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
4 | import { VideoModel } from '../../../models/video/video' | 4 | import { VideoModel } from '../../../models/video/video' |
5 | import { VideoCommentModel } from '../../../models/video/video-comment' | 5 | import { VideoCommentModel } from '../../../models/video/video-comment' |
6 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
7 | import { getDeleteActivityPubUrl } from '../url' | 7 | import { getDeleteActivityPubUrl } from '../url' |
8 | import { broadcastToFollowers } from './misc' | 8 | import { audiencify, broadcastToActors, broadcastToFollowers, getActorsInvolvedInVideo, getVideoCommentAudience, unicastTo } from './misc' |
9 | 9 | ||
10 | async function sendDeleteVideo (video: VideoModel, t: Transaction) { | 10 | async 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 | ||
32 | async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) { | 32 | async 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 | ||
55 | function deleteActivityData (url: string, object: string, byActor: ActorModel): ActivityDelete { | 69 | function 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 | } |