aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-create.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-14 17:38:41 +0100
committerChocobozzz <me@florianbigard.com>2017-12-19 10:53:16 +0100
commit50d6de9c286abcb34ff4234d56d9cbb803db7665 (patch)
treef1732b27edcd05c7877a8358b8312f1e38c287ed /server/lib/activitypub/send/send-create.ts
parentfadf619ad61a016c1c7fc53de5a8f398a4f77519 (diff)
downloadPeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.gz
PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.zst
PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.zip
Begin moving video channel to actor
Diffstat (limited to 'server/lib/activitypub/send/send-create.ts')
-rw-r--r--server/lib/activitypub/send/send-create.ts107
1 files changed, 54 insertions, 53 deletions
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index 9fbaa8196..d26c24838 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -1,111 +1,112 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' 2import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub'
3import { getServerAccount } from '../../../helpers' 3import { VideoPrivacy } from '../../../../shared/models/videos'
4import { AccountModel } from '../../../models/account/account' 4import { getServerActor } from '../../../helpers'
5import { ActorModel } from '../../../models/activitypub/actor'
5import { VideoModel } from '../../../models/video/video' 6import { VideoModel } from '../../../models/video/video'
6import { VideoAbuseModel } from '../../../models/video/video-abuse' 7import { VideoAbuseModel } from '../../../models/video/video-abuse'
7import { VideoChannelModel } from '../../../models/video/video-channel'
8import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' 8import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
9import { 9import {
10 broadcastToFollowers, 10 broadcastToFollowers,
11 getAccountsInvolvedInVideo, 11 getActorsInvolvedInVideo,
12 getAudience, 12 getAudience,
13 getObjectFollowersAudience, 13 getObjectFollowersAudience,
14 getOriginVideoAudience, 14 getOriginVideoAudience,
15 unicastTo 15 unicastTo
16} from './misc' 16} from './misc'
17 17
18async function sendCreateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { 18async function sendCreateVideo (video: VideoModel, t: Transaction) {
19 const byAccount = videoChannel.Account 19 const byActor = video.VideoChannel.Account.Actor
20 20
21 const videoChannelObject = videoChannel.toActivityPubObject() 21 const videoObject = video.toActivityPubObject()
22 const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject, t) 22 const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC)
23 const data = await createActivityData(video.url, byActor, videoObject, t, audience)
23 24
24 return broadcastToFollowers(data, byAccount, [ byAccount ], t) 25 return broadcastToFollowers(data, byActor, [ byActor ], t)
25} 26}
26 27
27async function sendVideoAbuse (byAccount: AccountModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { 28async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) {
28 const url = getVideoAbuseActivityPubUrl(videoAbuse) 29 const url = getVideoAbuseActivityPubUrl(videoAbuse)
29 30
30 const audience = { to: [ video.VideoChannel.Account.url ], cc: [] } 31 const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] }
31 const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), t, audience) 32 const data = await createActivityData(url, byActor, videoAbuse.toActivityPubObject(), t, audience)
32 33
33 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 34 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
34} 35}
35 36
36async function sendCreateViewToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { 37async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
37 const url = getVideoViewActivityPubUrl(byAccount, video) 38 const url = getVideoViewActivityPubUrl(byActor, video)
38 const viewActivity = createViewActivityData(byAccount, video) 39 const viewActivity = createViewActivityData(byActor, video)
39 40
40 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) 41 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
41 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 42 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
42 const data = await createActivityData(url, byAccount, viewActivity, t, audience) 43 const data = await createActivityData(url, byActor, viewActivity, t, audience)
43 44
44 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 45 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
45} 46}
46 47
47async function sendCreateViewToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { 48async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
48 const url = getVideoViewActivityPubUrl(byAccount, video) 49 const url = getVideoViewActivityPubUrl(byActor, video)
49 const viewActivity = createViewActivityData(byAccount, video) 50 const viewActivity = createViewActivityData(byActor, video)
50 51
51 const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) 52 const actorsToForwardView = await getActorsInvolvedInVideo(video, t)
52 const audience = getObjectFollowersAudience(accountsToForwardView) 53 const audience = getObjectFollowersAudience(actorsToForwardView)
53 const data = await createActivityData(url, byAccount, viewActivity, t, audience) 54 const data = await createActivityData(url, byActor, viewActivity, t, audience)
54 55
55 // Use the server account to send the view, because it could be an unregistered account 56 // Use the server actor to send the view
56 const serverAccount = await getServerAccount() 57 const serverActor = await getServerActor()
57 const followersException = [ byAccount ] 58 const followersException = [ byActor ]
58 return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) 59 return broadcastToFollowers(data, serverActor, actorsToForwardView, t, followersException)
59} 60}
60 61
61async function sendCreateDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { 62async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
62 const url = getVideoDislikeActivityPubUrl(byAccount, video) 63 const url = getVideoDislikeActivityPubUrl(byActor, video)
63 const dislikeActivity = createDislikeActivityData(byAccount, video) 64 const dislikeActivity = createDislikeActivityData(byActor, video)
64 65
65 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) 66 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
66 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 67 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
67 const data = await createActivityData(url, byAccount, dislikeActivity, t, audience) 68 const data = await createActivityData(url, byActor, dislikeActivity, t, audience)
68 69
69 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 70 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
70} 71}
71 72
72async function sendCreateDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { 73async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
73 const url = getVideoDislikeActivityPubUrl(byAccount, video) 74 const url = getVideoDislikeActivityPubUrl(byActor, video)
74 const dislikeActivity = createDislikeActivityData(byAccount, video) 75 const dislikeActivity = createDislikeActivityData(byActor, video)
75 76
76 const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) 77 const actorsToForwardView = await getActorsInvolvedInVideo(video, t)
77 const audience = getObjectFollowersAudience(accountsToForwardView) 78 const audience = getObjectFollowersAudience(actorsToForwardView)
78 const data = await createActivityData(url, byAccount, dislikeActivity, t, audience) 79 const data = await createActivityData(url, byActor, dislikeActivity, t, audience)
79 80
80 const followersException = [ byAccount ] 81 const followersException = [ byActor ]
81 return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException) 82 return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException)
82} 83}
83 84
84async function createActivityData ( 85async function createActivityData (
85 url: string, 86 url: string,
86 byAccount: AccountModel, 87 byActor: ActorModel,
87 object: any, 88 object: any,
88 t: Transaction, 89 t: Transaction,
89 audience?: ActivityAudience 90 audience?: ActivityAudience
90): Promise<ActivityCreate> { 91): Promise<ActivityCreate> {
91 if (!audience) { 92 if (!audience) {
92 audience = await getAudience(byAccount, t) 93 audience = await getAudience(byActor, t)
93 } 94 }
94 95
95 return { 96 return {
96 type: 'Create', 97 type: 'Create',
97 id: url, 98 id: url,
98 actor: byAccount.url, 99 actor: byActor.url,
99 to: audience.to, 100 to: audience.to,
100 cc: audience.cc, 101 cc: audience.cc,
101 object 102 object
102 } 103 }
103} 104}
104 105
105function createDislikeActivityData (byAccount: AccountModel, video: VideoModel) { 106function createDislikeActivityData (byActor: ActorModel, video: VideoModel) {
106 return { 107 return {
107 type: 'Dislike', 108 type: 'Dislike',
108 actor: byAccount.url, 109 actor: byActor.url,
109 object: video.url 110 object: video.url
110 } 111 }
111} 112}
@@ -113,7 +114,7 @@ function createDislikeActivityData (byAccount: AccountModel, video: VideoModel)
113// --------------------------------------------------------------------------- 114// ---------------------------------------------------------------------------
114 115
115export { 116export {
116 sendCreateVideoChannel, 117 sendCreateVideo,
117 sendVideoAbuse, 118 sendVideoAbuse,
118 createActivityData, 119 createActivityData,
119 sendCreateViewToOrigin, 120 sendCreateViewToOrigin,
@@ -125,10 +126,10 @@ export {
125 126
126// --------------------------------------------------------------------------- 127// ---------------------------------------------------------------------------
127 128
128function createViewActivityData (byAccount: AccountModel, video: VideoModel) { 129function createViewActivityData (byActor: ActorModel, video: VideoModel) {
129 return { 130 return {
130 type: 'View', 131 type: 'View',
131 actor: byAccount.url, 132 actor: byActor.url,
132 object: video.url 133 object: video.url
133 } 134 }
134} 135}