aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/misc.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/misc.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/misc.ts')
-rw-r--r--server/lib/activitypub/send/misc.ts80
1 files changed, 31 insertions, 49 deletions
diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/misc.ts
index ffc221477..14101e630 100644
--- a/server/lib/activitypub/send/misc.ts
+++ b/server/lib/activitypub/send/misc.ts
@@ -2,18 +2,16 @@ import { Transaction } from 'sequelize'
2import { Activity } from '../../../../shared/models/activitypub' 2import { Activity } from '../../../../shared/models/activitypub'
3import { logger } from '../../../helpers' 3import { logger } from '../../../helpers'
4import { ACTIVITY_PUB } from '../../../initializers' 4import { ACTIVITY_PUB } from '../../../initializers'
5import { AccountModel } from '../../../models/account/account' 5import { ActorModel } from '../../../models/activitypub/actor'
6import { AccountFollowModel } from '../../../models/account/account-follow' 6import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
7import { VideoModel } from '../../../models/video/video' 7import { VideoModel } from '../../../models/video/video'
8import { VideoChannelModel } from '../../../models/video/video-channel'
9import { VideoChannelShareModel } from '../../../models/video/video-channel-share'
10import { VideoShareModel } from '../../../models/video/video-share' 8import { VideoShareModel } from '../../../models/video/video-share'
11import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../../jobs/activitypub-http-job-scheduler' 9import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../../jobs/activitypub-http-job-scheduler'
12 10
13async function forwardActivity ( 11async function forwardActivity (
14 activity: Activity, 12 activity: Activity,
15 t: Transaction, 13 t: Transaction,
16 followersException: AccountModel[] = [] 14 followersException: ActorModel[] = []
17) { 15) {
18 const to = activity.to || [] 16 const to = activity.to || []
19 const cc = activity.cc || [] 17 const cc = activity.cc || []
@@ -25,11 +23,11 @@ async function forwardActivity (
25 } 23 }
26 } 24 }
27 25
28 const toAccountFollowers = await AccountModel.listByFollowersUrls(followersUrls, t) 26 const toActorFollowers = await ActorModel.listByFollowersUrls(followersUrls, t)
29 const uris = await computeFollowerUris(toAccountFollowers, followersException, t) 27 const uris = await computeFollowerUris(toActorFollowers, followersException, t)
30 28
31 if (uris.length === 0) { 29 if (uris.length === 0) {
32 logger.info('0 followers for %s, no forwarding.', toAccountFollowers.map(a => a.id).join(', ')) 30 logger.info('0 followers for %s, no forwarding.', toActorFollowers.map(a => a.id).join(', '))
33 return undefined 31 return undefined
34 } 32 }
35 33
@@ -45,14 +43,14 @@ async function forwardActivity (
45 43
46async function broadcastToFollowers ( 44async function broadcastToFollowers (
47 data: any, 45 data: any,
48 byAccount: AccountModel, 46 byActor: ActorModel,
49 toAccountFollowers: AccountModel[], 47 toActorFollowers: ActorModel[],
50 t: Transaction, 48 t: Transaction,
51 followersException: AccountModel[] = [] 49 followersException: ActorModel[] = []
52) { 50) {
53 const uris = await computeFollowerUris(toAccountFollowers, followersException, t) 51 const uris = await computeFollowerUris(toActorFollowers, followersException, t)
54 if (uris.length === 0) { 52 if (uris.length === 0) {
55 logger.info('0 followers for %s, no broadcasting.', toAccountFollowers.map(a => a.id).join(', ')) 53 logger.info('0 followers for %s, no broadcasting.', toActorFollowers.map(a => a.id).join(', '))
56 return undefined 54 return undefined
57 } 55 }
58 56
@@ -60,62 +58,48 @@ async function broadcastToFollowers (
60 58
61 const jobPayload: ActivityPubHttpPayload = { 59 const jobPayload: ActivityPubHttpPayload = {
62 uris, 60 uris,
63 signatureAccountId: byAccount.id, 61 signatureActorId: byActor.id,
64 body: data 62 body: data
65 } 63 }
66 64
67 return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload) 65 return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload)
68} 66}
69 67
70async function unicastTo (data: any, byAccount: AccountModel, toAccountUrl: string, t: Transaction) { 68async function unicastTo (data: any, byActor: ActorModel, toActorUrl: string, t: Transaction) {
71 logger.debug('Creating unicast job.', { uri: toAccountUrl }) 69 logger.debug('Creating unicast job.', { uri: toActorUrl })
72 70
73 const jobPayload: ActivityPubHttpPayload = { 71 const jobPayload: ActivityPubHttpPayload = {
74 uris: [ toAccountUrl ], 72 uris: [ toActorUrl ],
75 signatureAccountId: byAccount.id, 73 signatureActorId: byActor.id,
76 body: data 74 body: data
77 } 75 }
78 76
79 return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload) 77 return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload)
80} 78}
81 79
82function getOriginVideoAudience (video: VideoModel, accountsInvolvedInVideo: AccountModel[]) { 80function getOriginVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]) {
83 return { 81 return {
84 to: [ video.VideoChannel.Account.url ], 82 to: [ video.VideoChannel.Account.Actor.url ],
85 cc: accountsInvolvedInVideo.map(a => a.followersUrl) 83 cc: actorsInvolvedInVideo.map(a => a.followersUrl)
86 } 84 }
87} 85}
88 86
89function getOriginVideoChannelAudience (videoChannel: VideoChannelModel, accountsInvolved: AccountModel[]) { 87function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) {
90 return { 88 return {
91 to: [ videoChannel.Account.url ], 89 to: actorsInvolvedInObject.map(a => a.followersUrl),
92 cc: accountsInvolved.map(a => a.followersUrl)
93 }
94}
95
96function getObjectFollowersAudience (accountsInvolvedInObject: AccountModel[]) {
97 return {
98 to: accountsInvolvedInObject.map(a => a.followersUrl),
99 cc: [] 90 cc: []
100 } 91 }
101} 92}
102 93
103async function getAccountsInvolvedInVideo (video: VideoModel, t: Transaction) { 94async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) {
104 const accountsToForwardView = await VideoShareModel.loadAccountsByShare(video.id, t) 95 const actorsToForwardView = await VideoShareModel.loadActorsByShare(video.id, t)
105 accountsToForwardView.push(video.VideoChannel.Account) 96 actorsToForwardView.push(video.VideoChannel.Account.Actor)
106
107 return accountsToForwardView
108}
109
110async function getAccountsInvolvedInVideoChannel (videoChannel: VideoChannelModel, t: Transaction) {
111 const accountsToForwardView = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t)
112 accountsToForwardView.push(videoChannel.Account)
113 97
114 return accountsToForwardView 98 return actorsToForwardView
115} 99}
116 100
117async function getAudience (accountSender: AccountModel, t: Transaction, isPublic = true) { 101async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) {
118 const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls(t) 102 const followerInboxUrls = await actorSender.getFollowerSharedInboxUrls(t)
119 103
120 // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47 104 // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47
121 let to = [] 105 let to = []
@@ -132,10 +116,10 @@ async function getAudience (accountSender: AccountModel, t: Transaction, isPubli
132 return { to, cc } 116 return { to, cc }
133} 117}
134 118
135async function computeFollowerUris (toAccountFollower: AccountModel[], followersException: AccountModel[], t: Transaction) { 119async function computeFollowerUris (toActorFollower: ActorModel[], followersException: ActorModel[], t: Transaction) {
136 const toAccountFollowerIds = toAccountFollower.map(a => a.id) 120 const toActorFollowerIds = toActorFollower.map(a => a.id)
137 121
138 const result = await AccountFollowModel.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds, t) 122 const result = await ActorFollowModel.listAcceptedFollowerSharedInboxUrls(toActorFollowerIds, t)
139 const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl) 123 const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl)
140 return result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1) 124 return result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1)
141} 125}
@@ -144,12 +128,10 @@ async function computeFollowerUris (toAccountFollower: AccountModel[], followers
144 128
145export { 129export {
146 broadcastToFollowers, 130 broadcastToFollowers,
147 getOriginVideoChannelAudience,
148 unicastTo, 131 unicastTo,
149 getAudience, 132 getAudience,
150 getOriginVideoAudience, 133 getOriginVideoAudience,
151 getAccountsInvolvedInVideo, 134 getActorsInvolvedInVideo,
152 getAccountsInvolvedInVideoChannel,
153 getObjectFollowersAudience, 135 getObjectFollowersAudience,
154 forwardActivity 136 forwardActivity
155} 137}