diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-12 20:04:58 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-12 20:37:51 +0200 |
commit | 2186386cca113506791583cb07d6ccacba7af4e0 (patch) | |
tree | 3c214c0b5fbd64332624267fa6e51fd4a9cf6474 /server/lib/activitypub/send | |
parent | 6ccdf3a23ecec5ba2eeaf487fd1fafdc7606b4bf (diff) | |
download | PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.tar.gz PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.tar.zst PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.zip |
Add concept of video state, and add ability to wait transcoding before
publishing a video
Diffstat (limited to 'server/lib/activitypub/send')
-rw-r--r-- | server/lib/activitypub/send/send-announce.ts | 14 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 43 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-like.ts | 33 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 42 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 36 |
5 files changed, 74 insertions, 94 deletions
diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts index fa1d47259..dfc099ff2 100644 --- a/server/lib/activitypub/send/send-announce.ts +++ b/server/lib/activitypub/send/send-announce.ts | |||
@@ -11,7 +11,7 @@ async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareMo | |||
11 | 11 | ||
12 | const accountsToForwardView = await getActorsInvolvedInVideo(video, t) | 12 | const accountsToForwardView = await getActorsInvolvedInVideo(video, t) |
13 | const audience = getObjectFollowersAudience(accountsToForwardView) | 13 | const audience = getObjectFollowersAudience(accountsToForwardView) |
14 | return announceActivityData(videoShare.url, byActor, announcedObject, t, audience) | 14 | return announceActivityData(videoShare.url, byActor, announcedObject, audience) |
15 | } | 15 | } |
16 | 16 | ||
17 | async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { | 17 | async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { |
@@ -20,16 +20,8 @@ async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareMod | |||
20 | return broadcastToFollowers(data, byActor, [ byActor ], t) | 20 | return broadcastToFollowers(data, byActor, [ byActor ], t) |
21 | } | 21 | } |
22 | 22 | ||
23 | async function announceActivityData ( | 23 | function announceActivityData (url: string, byActor: ActorModel, object: string, audience?: ActivityAudience): ActivityAnnounce { |
24 | url: string, | 24 | if (!audience) audience = getAudience(byActor) |
25 | byActor: ActorModel, | ||
26 | object: string, | ||
27 | t: Transaction, | ||
28 | audience?: ActivityAudience | ||
29 | ): Promise<ActivityAnnounce> { | ||
30 | if (!audience) { | ||
31 | audience = await getAudience(byActor, t) | ||
32 | } | ||
33 | 25 | ||
34 | return { | 26 | return { |
35 | type: 'Announce', | 27 | type: 'Announce', |
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 3ef4fcd3b..293947b05 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -23,8 +23,8 @@ async function sendCreateVideo (video: VideoModel, t: Transaction) { | |||
23 | const byActor = video.VideoChannel.Account.Actor | 23 | const byActor = video.VideoChannel.Account.Actor |
24 | const videoObject = video.toActivityPubObject() | 24 | const videoObject = video.toActivityPubObject() |
25 | 25 | ||
26 | const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) | 26 | const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) |
27 | const data = await createActivityData(video.url, byActor, videoObject, t, audience) | 27 | const data = createActivityData(video.url, byActor, videoObject, audience) |
28 | 28 | ||
29 | return broadcastToFollowers(data, byActor, [ byActor ], t) | 29 | return broadcastToFollowers(data, byActor, [ byActor ], t) |
30 | } | 30 | } |
@@ -33,7 +33,7 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, | |||
33 | const url = getVideoAbuseActivityPubUrl(videoAbuse) | 33 | const url = getVideoAbuseActivityPubUrl(videoAbuse) |
34 | 34 | ||
35 | const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] } | 35 | const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] } |
36 | const data = await createActivityData(url, byActor, videoAbuse.toActivityPubObject(), t, audience) | 36 | const data = createActivityData(url, byActor, videoAbuse.toActivityPubObject(), audience) |
37 | 37 | ||
38 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 38 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
39 | } | 39 | } |
@@ -57,7 +57,7 @@ async function sendCreateVideoComment (comment: VideoCommentModel, t: Transactio | |||
57 | audience = getObjectFollowersAudience(actorsInvolvedInComment.concat(parentsCommentActors)) | 57 | audience = getObjectFollowersAudience(actorsInvolvedInComment.concat(parentsCommentActors)) |
58 | } | 58 | } |
59 | 59 | ||
60 | const data = await createActivityData(comment.url, byActor, commentObject, t, audience) | 60 | const data = createActivityData(comment.url, byActor, commentObject, audience) |
61 | 61 | ||
62 | // This was a reply, send it to the parent actors | 62 | // This was a reply, send it to the parent actors |
63 | const actorsException = [ byActor ] | 63 | const actorsException = [ byActor ] |
@@ -82,14 +82,14 @@ async function sendCreateView (byActor: ActorModel, video: VideoModel, t: Transa | |||
82 | // Send to origin | 82 | // Send to origin |
83 | if (video.isOwned() === false) { | 83 | if (video.isOwned() === false) { |
84 | const audience = getVideoAudience(video, actorsInvolvedInVideo) | 84 | const audience = getVideoAudience(video, actorsInvolvedInVideo) |
85 | const data = await createActivityData(url, byActor, viewActivityData, t, audience) | 85 | const data = createActivityData(url, byActor, viewActivityData, audience) |
86 | 86 | ||
87 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 87 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
88 | } | 88 | } |
89 | 89 | ||
90 | // Send to followers | 90 | // Send to followers |
91 | const audience = getObjectFollowersAudience(actorsInvolvedInVideo) | 91 | const audience = getObjectFollowersAudience(actorsInvolvedInVideo) |
92 | const data = await createActivityData(url, byActor, viewActivityData, t, audience) | 92 | const data = createActivityData(url, byActor, viewActivityData, audience) |
93 | 93 | ||
94 | // Use the server actor to send the view | 94 | // Use the server actor to send the view |
95 | const serverActor = await getServerActor() | 95 | const serverActor = await getServerActor() |
@@ -106,34 +106,31 @@ async function sendCreateDislike (byActor: ActorModel, video: VideoModel, t: Tra | |||
106 | // Send to origin | 106 | // Send to origin |
107 | if (video.isOwned() === false) { | 107 | if (video.isOwned() === false) { |
108 | const audience = getVideoAudience(video, actorsInvolvedInVideo) | 108 | const audience = getVideoAudience(video, actorsInvolvedInVideo) |
109 | const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) | 109 | const data = createActivityData(url, byActor, dislikeActivityData, audience) |
110 | 110 | ||
111 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 111 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
112 | } | 112 | } |
113 | 113 | ||
114 | // Send to followers | 114 | // Send to followers |
115 | const audience = getObjectFollowersAudience(actorsInvolvedInVideo) | 115 | const audience = getObjectFollowersAudience(actorsInvolvedInVideo) |
116 | const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) | 116 | const data = createActivityData(url, byActor, dislikeActivityData, audience) |
117 | 117 | ||
118 | const actorsException = [ byActor ] | 118 | const actorsException = [ byActor ] |
119 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, actorsException) | 119 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, actorsException) |
120 | } | 120 | } |
121 | 121 | ||
122 | async function createActivityData (url: string, | 122 | function createActivityData (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityCreate { |
123 | byActor: ActorModel, | 123 | if (!audience) audience = getAudience(byActor) |
124 | object: any, | 124 | |
125 | t: Transaction, | 125 | return audiencify( |
126 | audience?: ActivityAudience): Promise<ActivityCreate> { | 126 | { |
127 | if (!audience) { | 127 | type: 'Create' as 'Create', |
128 | audience = await getAudience(byActor, t) | 128 | id: url + '/activity', |
129 | } | 129 | actor: byActor.url, |
130 | 130 | object: audiencify(object, audience) | |
131 | return audiencify({ | 131 | }, |
132 | type: 'Create' as 'Create', | 132 | audience |
133 | id: url + '/activity', | 133 | ) |
134 | actor: byActor.url, | ||
135 | object: audiencify(object, audience) | ||
136 | }, audience) | ||
137 | } | 134 | } |
138 | 135 | ||
139 | function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { | 136 | function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { |
diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts index ddeb1fcd2..37ee7c096 100644 --- a/server/lib/activitypub/send/send-like.ts +++ b/server/lib/activitypub/send/send-like.ts | |||
@@ -14,36 +14,31 @@ async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) | |||
14 | // Send to origin | 14 | // Send to origin |
15 | if (video.isOwned() === false) { | 15 | if (video.isOwned() === false) { |
16 | const audience = getVideoAudience(video, accountsInvolvedInVideo) | 16 | const audience = getVideoAudience(video, accountsInvolvedInVideo) |
17 | const data = await likeActivityData(url, byActor, video, t, audience) | 17 | const data = likeActivityData(url, byActor, video, audience) |
18 | 18 | ||
19 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 19 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
20 | } | 20 | } |
21 | 21 | ||
22 | // Send to followers | 22 | // Send to followers |
23 | const audience = getObjectFollowersAudience(accountsInvolvedInVideo) | 23 | const audience = getObjectFollowersAudience(accountsInvolvedInVideo) |
24 | const data = await likeActivityData(url, byActor, video, t, audience) | 24 | const data = likeActivityData(url, byActor, video, audience) |
25 | 25 | ||
26 | const followersException = [ byActor ] | 26 | const followersException = [ byActor ] |
27 | return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException) | 27 | return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException) |
28 | } | 28 | } |
29 | 29 | ||
30 | async function likeActivityData ( | 30 | function likeActivityData (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike { |
31 | url: string, | 31 | if (!audience) audience = getAudience(byActor) |
32 | byActor: ActorModel, | 32 | |
33 | video: VideoModel, | 33 | return audiencify( |
34 | t: Transaction, | 34 | { |
35 | audience?: ActivityAudience | 35 | type: 'Like' as 'Like', |
36 | ): Promise<ActivityLike> { | 36 | id: url, |
37 | if (!audience) { | 37 | actor: byActor.url, |
38 | audience = await getAudience(byActor, t) | 38 | object: video.url |
39 | } | 39 | }, |
40 | 40 | audience | |
41 | return audiencify({ | 41 | ) |
42 | type: 'Like' as 'Like', | ||
43 | id: url, | ||
44 | actor: byActor.url, | ||
45 | object: video.url | ||
46 | }, audience) | ||
47 | } | 42 | } |
48 | 43 | ||
49 | // --------------------------------------------------------------------------- | 44 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 9733e66dc..33c3d2429 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -27,7 +27,7 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { | |||
27 | const undoUrl = getUndoActivityPubUrl(followUrl) | 27 | const undoUrl = getUndoActivityPubUrl(followUrl) |
28 | 28 | ||
29 | const object = followActivityData(followUrl, me, following) | 29 | const object = followActivityData(followUrl, me, following) |
30 | const data = await undoActivityData(undoUrl, me, object, t) | 30 | const data = undoActivityData(undoUrl, me, object) |
31 | 31 | ||
32 | return unicastTo(data, me, following.inboxUrl) | 32 | return unicastTo(data, me, following.inboxUrl) |
33 | } | 33 | } |
@@ -37,18 +37,18 @@ async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transact | |||
37 | const undoUrl = getUndoActivityPubUrl(likeUrl) | 37 | const undoUrl = getUndoActivityPubUrl(likeUrl) |
38 | 38 | ||
39 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | 39 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
40 | const object = await likeActivityData(likeUrl, byActor, video, t) | 40 | const object = likeActivityData(likeUrl, byActor, video) |
41 | 41 | ||
42 | // Send to origin | 42 | // Send to origin |
43 | if (video.isOwned() === false) { | 43 | if (video.isOwned() === false) { |
44 | const audience = getVideoAudience(video, actorsInvolvedInVideo) | 44 | const audience = getVideoAudience(video, actorsInvolvedInVideo) |
45 | const data = await undoActivityData(undoUrl, byActor, object, t, audience) | 45 | const data = undoActivityData(undoUrl, byActor, object, audience) |
46 | 46 | ||
47 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 47 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
48 | } | 48 | } |
49 | 49 | ||
50 | const audience = getObjectFollowersAudience(actorsInvolvedInVideo) | 50 | const audience = getObjectFollowersAudience(actorsInvolvedInVideo) |
51 | const data = await undoActivityData(undoUrl, byActor, object, t, audience) | 51 | const data = undoActivityData(undoUrl, byActor, object, audience) |
52 | 52 | ||
53 | const followersException = [ byActor ] | 53 | const followersException = [ byActor ] |
54 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) | 54 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) |
@@ -60,16 +60,16 @@ async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Trans | |||
60 | 60 | ||
61 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | 61 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
62 | const dislikeActivity = createDislikeActivityData(byActor, video) | 62 | const dislikeActivity = createDislikeActivityData(byActor, video) |
63 | const object = await createActivityData(dislikeUrl, byActor, dislikeActivity, t) | 63 | const object = createActivityData(dislikeUrl, byActor, dislikeActivity) |
64 | 64 | ||
65 | if (video.isOwned() === false) { | 65 | if (video.isOwned() === false) { |
66 | const audience = getVideoAudience(video, actorsInvolvedInVideo) | 66 | const audience = getVideoAudience(video, actorsInvolvedInVideo) |
67 | const data = await undoActivityData(undoUrl, byActor, object, t, audience) | 67 | const data = undoActivityData(undoUrl, byActor, object, audience) |
68 | 68 | ||
69 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | 69 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
70 | } | 70 | } |
71 | 71 | ||
72 | const data = await undoActivityData(undoUrl, byActor, object, t) | 72 | const data = undoActivityData(undoUrl, byActor, object) |
73 | 73 | ||
74 | const followersException = [ byActor ] | 74 | const followersException = [ byActor ] |
75 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) | 75 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) |
@@ -80,7 +80,7 @@ async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareMode | |||
80 | 80 | ||
81 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) | 81 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
82 | const object = await buildVideoAnnounce(byActor, videoShare, video, t) | 82 | const object = await buildVideoAnnounce(byActor, videoShare, video, t) |
83 | const data = await undoActivityData(undoUrl, byActor, object, t) | 83 | const data = undoActivityData(undoUrl, byActor, object) |
84 | 84 | ||
85 | const followersException = [ byActor ] | 85 | const followersException = [ byActor ] |
86 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) | 86 | return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) |
@@ -97,21 +97,21 @@ export { | |||
97 | 97 | ||
98 | // --------------------------------------------------------------------------- | 98 | // --------------------------------------------------------------------------- |
99 | 99 | ||
100 | async function undoActivityData ( | 100 | function undoActivityData ( |
101 | url: string, | 101 | url: string, |
102 | byActor: ActorModel, | 102 | byActor: ActorModel, |
103 | object: ActivityFollow | ActivityLike | ActivityCreate | ActivityAnnounce, | 103 | object: ActivityFollow | ActivityLike | ActivityCreate | ActivityAnnounce, |
104 | t: Transaction, | ||
105 | audience?: ActivityAudience | 104 | audience?: ActivityAudience |
106 | ): Promise<ActivityUndo> { | 105 | ): ActivityUndo { |
107 | if (!audience) { | 106 | if (!audience) audience = getAudience(byActor) |
108 | audience = await getAudience(byActor, t) | 107 | |
109 | } | 108 | return audiencify( |
110 | 109 | { | |
111 | return audiencify({ | 110 | type: 'Undo' as 'Undo', |
112 | type: 'Undo' as 'Undo', | 111 | id: url, |
113 | id: url, | 112 | actor: byActor.url, |
114 | actor: byActor.url, | 113 | object |
115 | object | 114 | }, |
116 | }, audience) | 115 | audience |
116 | ) | ||
117 | } | 117 | } |
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index d64b88343..2fd374ec6 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -15,9 +15,9 @@ async function sendUpdateVideo (video: VideoModel, t: Transaction) { | |||
15 | 15 | ||
16 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) | 16 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) |
17 | const videoObject = video.toActivityPubObject() | 17 | const videoObject = video.toActivityPubObject() |
18 | const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) | 18 | const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) |
19 | 19 | ||
20 | const data = await updateActivityData(url, byActor, videoObject, t, audience) | 20 | const data = updateActivityData(url, byActor, videoObject, audience) |
21 | 21 | ||
22 | const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) | 22 | const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) |
23 | actorsInvolved.push(byActor) | 23 | actorsInvolved.push(byActor) |
@@ -30,8 +30,8 @@ async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelMod | |||
30 | 30 | ||
31 | const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString()) | 31 | const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString()) |
32 | const accountOrChannelObject = accountOrChannel.toActivityPubObject() | 32 | const accountOrChannelObject = accountOrChannel.toActivityPubObject() |
33 | const audience = await getAudience(byActor, t) | 33 | const audience = getAudience(byActor) |
34 | const data = await updateActivityData(url, byActor, accountOrChannelObject, t, audience) | 34 | const data = updateActivityData(url, byActor, accountOrChannelObject, audience) |
35 | 35 | ||
36 | let actorsInvolved: ActorModel[] | 36 | let actorsInvolved: ActorModel[] |
37 | if (accountOrChannel instanceof AccountModel) { | 37 | if (accountOrChannel instanceof AccountModel) { |
@@ -56,21 +56,17 @@ export { | |||
56 | 56 | ||
57 | // --------------------------------------------------------------------------- | 57 | // --------------------------------------------------------------------------- |
58 | 58 | ||
59 | async function updateActivityData ( | 59 | function updateActivityData (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityUpdate { |
60 | url: string, | 60 | if (!audience) audience = getAudience(byActor) |
61 | byActor: ActorModel, | ||
62 | object: any, | ||
63 | t: Transaction, | ||
64 | audience?: ActivityAudience | ||
65 | ): Promise<ActivityUpdate> { | ||
66 | if (!audience) { | ||
67 | audience = await getAudience(byActor, t) | ||
68 | } | ||
69 | 61 | ||
70 | return audiencify({ | 62 | return audiencify( |
71 | type: 'Update' as 'Update', | 63 | { |
72 | id: url, | 64 | type: 'Update' as 'Update', |
73 | actor: byActor.url, | 65 | id: url, |
74 | object: audiencify(object, audience) | 66 | actor: byActor.url, |
75 | }, audience) | 67 | object: audiencify(object, audience |
68 | ) | ||
69 | }, | ||
70 | audience | ||
71 | ) | ||
76 | } | 72 | } |