aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-04 16:56:36 +0100
committerChocobozzz <me@florianbigard.com>2018-01-04 16:56:36 +0100
commitc3badc81fe3d78601fb278a7f28eeed63060d300 (patch)
treee060a547202d6a3422dc738c6cb02fb5c15f141f /server/lib
parentbb82394c0d41cc939a35782e50ce908c92e3ecfe (diff)
downloadPeerTube-c3badc81fe3d78601fb278a7f28eeed63060d300.tar.gz
PeerTube-c3badc81fe3d78601fb278a7f28eeed63060d300.tar.zst
PeerTube-c3badc81fe3d78601fb278a7f28eeed63060d300.zip
Fix delete activities
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/process/process-delete.ts6
-rw-r--r--server/lib/activitypub/send/send-delete.ts17
-rw-r--r--server/lib/activitypub/url.ts7
3 files changed, 20 insertions, 10 deletions
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts
index 604570e74..01751422d 100644
--- a/server/lib/activitypub/process/process-delete.ts
+++ b/server/lib/activitypub/process/process-delete.ts
@@ -12,7 +12,7 @@ import { getOrCreateActorAndServerAndModel } from '../actor'
12async function processDeleteActivity (activity: ActivityDelete) { 12async function processDeleteActivity (activity: ActivityDelete) {
13 const actor = await getOrCreateActorAndServerAndModel(activity.actor) 13 const actor = await getOrCreateActorAndServerAndModel(activity.actor)
14 14
15 if (actor.url === activity.id) { 15 if (actor.url === activity.object) {
16 if (actor.type === 'Person') { 16 if (actor.type === 'Person') {
17 if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.') 17 if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.')
18 18
@@ -25,14 +25,14 @@ async function processDeleteActivity (activity: ActivityDelete) {
25 } 25 }
26 26
27 { 27 {
28 const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(activity.id) 28 const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(activity.object)
29 if (videoCommentInstance) { 29 if (videoCommentInstance) {
30 return processDeleteVideoComment(actor, videoCommentInstance) 30 return processDeleteVideoComment(actor, videoCommentInstance)
31 } 31 }
32 } 32 }
33 33
34 { 34 {
35 const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(activity.id) 35 const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(activity.object)
36 if (videoInstance) { 36 if (videoInstance) {
37 return processDeleteVideo(actor, videoInstance) 37 return processDeleteVideo(actor, videoInstance)
38 } 38 }
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts
index 1ca031898..995a534a6 100644
--- a/server/lib/activitypub/send/send-delete.ts
+++ b/server/lib/activitypub/send/send-delete.ts
@@ -4,12 +4,14 @@ import { 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 { broadcastToFollowers } from './misc' 8import { broadcastToFollowers } from './misc'
8 9
9async function sendDeleteVideo (video: VideoModel, t: Transaction) { 10async function sendDeleteVideo (video: VideoModel, t: Transaction) {
11 const url = getDeleteActivityPubUrl(video.url)
10 const byActor = video.VideoChannel.Account.Actor 12 const byActor = video.VideoChannel.Account.Actor
11 13
12 const data = deleteActivityData(video.url, byActor) 14 const data = deleteActivityData(url, video.url, byActor)
13 15
14 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) 16 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
15 actorsInvolved.push(byActor) 17 actorsInvolved.push(byActor)
@@ -18,15 +20,17 @@ async function sendDeleteVideo (video: VideoModel, t: Transaction) {
18} 20}
19 21
20async function sendDeleteActor (byActor: ActorModel, t: Transaction) { 22async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
21 const data = deleteActivityData(byActor.url, byActor) 23 const url = getDeleteActivityPubUrl(byActor.url)
24 const data = deleteActivityData(url, byActor.url, byActor)
22 25
23 return broadcastToFollowers(data, byActor, [ byActor ], t) 26 return broadcastToFollowers(data, byActor, [ byActor ], t)
24} 27}
25 28
26async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) { 29async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
27 const byActor = videoComment.Account.Actor 30 const url = getDeleteActivityPubUrl(videoComment.url)
28 31
29 const data = deleteActivityData(videoComment.url, byActor) 32 const byActor = videoComment.Account.Actor
33 const data = deleteActivityData(url, videoComment.url, byActor)
30 34
31 const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t) 35 const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t)
32 actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor) 36 actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor)
@@ -45,10 +49,11 @@ export {
45 49
46// --------------------------------------------------------------------------- 50// ---------------------------------------------------------------------------
47 51
48function deleteActivityData (url: string, byActor: ActorModel): ActivityDelete { 52function deleteActivityData (url: string, object: string, byActor: ActorModel): ActivityDelete {
49 return { 53 return {
50 type: 'Delete', 54 type: 'Delete',
51 id: url, 55 id: url,
52 actor: byActor.url 56 actor: byActor.url,
57 object
53 } 58 }
54} 59}
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts
index 0d76922e0..5705afbd6 100644
--- a/server/lib/activitypub/url.ts
+++ b/server/lib/activitypub/url.ts
@@ -55,6 +55,10 @@ function getAnnounceActivityPubUrl (originalUrl: string, byActor: ActorModel) {
55 return originalUrl + '/announces/' + byActor.id 55 return originalUrl + '/announces/' + byActor.id
56} 56}
57 57
58function getDeleteActivityPubUrl (originalUrl: string) {
59 return originalUrl + '/delete'
60}
61
58function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) { 62function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
59 return originalUrl + '/updates/' + updatedAt 63 return originalUrl + '/updates/' + updatedAt
60} 64}
@@ -76,5 +80,6 @@ export {
76 getVideoViewActivityPubUrl, 80 getVideoViewActivityPubUrl,
77 getVideoLikeActivityPubUrl, 81 getVideoLikeActivityPubUrl,
78 getVideoDislikeActivityPubUrl, 82 getVideoDislikeActivityPubUrl,
79 getVideoCommentActivityPubUrl 83 getVideoCommentActivityPubUrl,
84 getDeleteActivityPubUrl
80} 85}