aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send
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
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')
-rw-r--r--server/lib/activitypub/send/index.ts1
-rw-r--r--server/lib/activitypub/send/misc.ts80
-rw-r--r--server/lib/activitypub/send/send-accept.ts22
-rw-r--r--server/lib/activitypub/send/send-add.ts45
-rw-r--r--server/lib/activitypub/send/send-announce.ts84
-rw-r--r--server/lib/activitypub/send/send-create.ts107
-rw-r--r--server/lib/activitypub/send/send-delete.ts38
-rw-r--r--server/lib/activitypub/send/send-follow.ts20
-rw-r--r--server/lib/activitypub/send/send-like.ts34
-rw-r--r--server/lib/activitypub/send/send-undo.ts84
-rw-r--r--server/lib/activitypub/send/send-update.ts52
11 files changed, 226 insertions, 341 deletions
diff --git a/server/lib/activitypub/send/index.ts b/server/lib/activitypub/send/index.ts
index ee8f3ad7e..79ba6c7fe 100644
--- a/server/lib/activitypub/send/index.ts
+++ b/server/lib/activitypub/send/index.ts
@@ -1,5 +1,4 @@
1export * from './send-accept' 1export * from './send-accept'
2export * from './send-add'
3export * from './send-announce' 2export * from './send-announce'
4export * from './send-create' 3export * from './send-create'
5export * from './send-delete' 4export * from './send-delete'
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}
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts
index f160af3c9..7579884a7 100644
--- a/server/lib/activitypub/send/send-accept.ts
+++ b/server/lib/activitypub/send/send-accept.ts
@@ -1,15 +1,15 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAccept } from '../../../../shared/models/activitypub' 2import { ActivityAccept } from '../../../../shared/models/activitypub'
3import { AccountModel } from '../../../models/account/account' 3import { ActorModel } from '../../../models/activitypub/actor'
4import { AccountFollowModel } from '../../../models/account/account-follow' 4import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
5import { getAccountFollowAcceptActivityPubUrl } from '../url' 5import { getActorFollowAcceptActivityPubUrl } from '../url'
6import { unicastTo } from './misc' 6import { unicastTo } from './misc'
7 7
8async function sendAccept (accountFollow: AccountFollowModel, t: Transaction) { 8async function sendAccept (actorFollow: ActorFollowModel, t: Transaction) {
9 const follower = accountFollow.AccountFollower 9 const follower = actorFollow.ActorFollower
10 const me = accountFollow.AccountFollowing 10 const me = actorFollow.ActorFollowing
11 11
12 const url = getAccountFollowAcceptActivityPubUrl(accountFollow) 12 const url = getActorFollowAcceptActivityPubUrl(actorFollow)
13 const data = acceptActivityData(url, me) 13 const data = acceptActivityData(url, me)
14 14
15 return unicastTo(data, me, follower.inboxUrl, t) 15 return unicastTo(data, me, follower.inboxUrl, t)
@@ -23,12 +23,10 @@ export {
23 23
24// --------------------------------------------------------------------------- 24// ---------------------------------------------------------------------------
25 25
26function acceptActivityData (url: string, byAccount: AccountModel) { 26function acceptActivityData (url: string, byActor: ActorModel): ActivityAccept {
27 const activity: ActivityAccept = { 27 return {
28 type: 'Accept', 28 type: 'Accept',
29 id: url, 29 id: url,
30 actor: byAccount.url 30 actor: byActor.url
31 } 31 }
32
33 return activity
34} 32}
diff --git a/server/lib/activitypub/send/send-add.ts b/server/lib/activitypub/send/send-add.ts
deleted file mode 100644
index fd614db75..000000000
--- a/server/lib/activitypub/send/send-add.ts
+++ /dev/null
@@ -1,45 +0,0 @@
1import { Transaction } from 'sequelize'
2import { ActivityAdd } from '../../../../shared/models/activitypub'
3import { VideoPrivacy } from '../../../../shared/models/videos'
4import { AccountModel } from '../../../models/account/account'
5import { VideoModel } from '../../../models/video/video'
6import { broadcastToFollowers, getAudience } from './misc'
7
8async function sendAddVideo (video: VideoModel, t: Transaction) {
9 const byAccount = video.VideoChannel.Account
10
11 const videoObject = video.toActivityPubObject()
12 const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject, t)
13
14 return broadcastToFollowers(data, byAccount, [ byAccount ], t)
15}
16
17async function addActivityData (
18 url: string,
19 byAccount: AccountModel,
20 video: VideoModel,
21 target: string,
22 object: any,
23 t: Transaction
24): Promise<ActivityAdd> {
25 const videoPublic = video.privacy === VideoPrivacy.PUBLIC
26
27 const { to, cc } = await getAudience(byAccount, t, videoPublic)
28
29 return {
30 type: 'Add',
31 id: url,
32 actor: byAccount.url,
33 to,
34 cc,
35 object,
36 target
37 }
38}
39
40// ---------------------------------------------------------------------------
41
42export {
43 addActivityData,
44 sendAddVideo
45}
diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts
index e685323e8..578fbc630 100644
--- a/server/lib/activitypub/send/send-announce.ts
+++ b/server/lib/activitypub/send/send-announce.ts
@@ -1,88 +1,59 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAdd } from '../../../../shared/index'
3import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' 2import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub'
4import { AccountModel } from '../../../models/account/account' 3import { VideoPrivacy } from '../../../../shared/models/videos'
4import { ActorModel } from '../../../models/activitypub/actor'
5import { VideoModel } from '../../../models/video/video' 5import { VideoModel } from '../../../models/video/video'
6import { VideoChannelModel } from '../../../models/video/video-channel'
7import { getAnnounceActivityPubUrl } from '../url' 6import { getAnnounceActivityPubUrl } from '../url'
8import { 7import {
9 broadcastToFollowers, 8 broadcastToFollowers,
10 getAccountsInvolvedInVideo, 9 getActorsInvolvedInVideo,
11 getAccountsInvolvedInVideoChannel,
12 getAudience, 10 getAudience,
13 getObjectFollowersAudience, 11 getObjectFollowersAudience,
14 getOriginVideoAudience, 12 getOriginVideoAudience,
15 getOriginVideoChannelAudience,
16 unicastTo 13 unicastTo
17} from './misc' 14} from './misc'
18import { addActivityData } from './send-add'
19import { createActivityData } from './send-create' 15import { createActivityData } from './send-create'
20 16
21async function buildVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { 17async function buildVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
22 const url = getAnnounceActivityPubUrl(video.url, byAccount) 18 const url = getAnnounceActivityPubUrl(video.url, byActor)
19 const videoObject = video.toActivityPubObject()
23 20
24 const videoChannel = video.VideoChannel 21 const announcedAudience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC)
25 const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t) 22 const announcedActivity = await createActivityData(url, video.VideoChannel.Account.Actor, videoObject, t, announcedAudience)
26 23
27 const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) 24 const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
28 const audience = getObjectFollowersAudience(accountsToForwardView) 25 const audience = getObjectFollowersAudience(accountsToForwardView)
29 return announceActivityData(url, byAccount, announcedActivity, t, audience) 26 return announceActivityData(url, byActor, announcedActivity, t, audience)
30} 27}
31 28
32async function sendVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { 29async function sendVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
33 const data = await buildVideoAnnounceToFollowers(byAccount, video, t) 30 const data = await buildVideoAnnounceToFollowers(byActor, video, t)
34 31
35 return broadcastToFollowers(data, byAccount, [ byAccount ], t) 32 return broadcastToFollowers(data, byActor, [ byActor ], t)
36} 33}
37 34
38async function sendVideoAnnounceToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { 35async function sendVideoAnnounceToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
39 const url = getAnnounceActivityPubUrl(video.url, byAccount) 36 const url = getAnnounceActivityPubUrl(video.url, byActor)
40 37
41 const videoChannel = video.VideoChannel 38 const videoObject = video.toActivityPubObject()
42 const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t) 39 const announcedActivity = await createActivityData(url, video.VideoChannel.Account.Actor, videoObject, t)
43 40
44 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) 41 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
45 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 42 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
46 const data = await createActivityData(url, byAccount, announcedActivity, t, audience) 43 const data = await createActivityData(url, byActor, announcedActivity, t, audience)
47 44
48 return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) 45 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
49}
50
51async function buildVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) {
52 const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
53 const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t)
54
55 const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t)
56 const audience = getObjectFollowersAudience(accountsToForwardView)
57 return announceActivityData(url, byAccount, announcedActivity, t, audience)
58}
59
60async function sendVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) {
61 const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t)
62
63 return broadcastToFollowers(data, byAccount, [ byAccount ], t)
64}
65
66async function sendVideoChannelAnnounceToOrigin (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) {
67 const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
68 const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t)
69
70 const accountsInvolvedInVideo = await getAccountsInvolvedInVideoChannel(videoChannel, t)
71 const audience = getOriginVideoChannelAudience(videoChannel, accountsInvolvedInVideo)
72 const data = await createActivityData(url, byAccount, announcedActivity, t, audience)
73
74 return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
75} 46}
76 47
77async function announceActivityData ( 48async function announceActivityData (
78 url: string, 49 url: string,
79 byAccount: AccountModel, 50 byActor: ActorModel,
80 object: ActivityCreate | ActivityAdd, 51 object: ActivityCreate,
81 t: Transaction, 52 t: Transaction,
82 audience?: ActivityAudience 53 audience?: ActivityAudience
83): Promise<ActivityAnnounce> { 54): Promise<ActivityAnnounce> {
84 if (!audience) { 55 if (!audience) {
85 audience = await getAudience(byAccount, t) 56 audience = await getAudience(byActor, t)
86 } 57 }
87 58
88 return { 59 return {
@@ -90,7 +61,7 @@ async function announceActivityData (
90 to: audience.to, 61 to: audience.to,
91 cc: audience.cc, 62 cc: audience.cc,
92 id: url, 63 id: url,
93 actor: byAccount.url, 64 actor: byActor.url,
94 object 65 object
95 } 66 }
96} 67}
@@ -99,10 +70,7 @@ async function announceActivityData (
99 70
100export { 71export {
101 sendVideoAnnounceToFollowers, 72 sendVideoAnnounceToFollowers,
102 sendVideoChannelAnnounceToFollowers,
103 sendVideoAnnounceToOrigin, 73 sendVideoAnnounceToOrigin,
104 sendVideoChannelAnnounceToOrigin,
105 announceActivityData, 74 announceActivityData,
106 buildVideoAnnounceToFollowers, 75 buildVideoAnnounceToFollowers
107 buildVideoChannelAnnounceToFollowers
108} 76}
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}
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts
index 0a45ea10f..4bc5db77e 100644
--- a/server/lib/activitypub/send/send-delete.ts
+++ b/server/lib/activitypub/send/send-delete.ts
@@ -1,54 +1,40 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityDelete } from '../../../../shared/models/activitypub' 2import { ActivityDelete } from '../../../../shared/models/activitypub'
3import { AccountModel } from '../../../models/account/account' 3import { ActorModel } from '../../../models/activitypub/actor'
4import { VideoModel } from '../../../models/video/video' 4import { VideoModel } from '../../../models/video/video'
5import { VideoChannelModel } from '../../../models/video/video-channel'
6import { VideoChannelShareModel } from '../../../models/video/video-channel-share'
7import { VideoShareModel } from '../../../models/video/video-share' 5import { VideoShareModel } from '../../../models/video/video-share'
8import { broadcastToFollowers } from './misc' 6import { broadcastToFollowers } from './misc'
9 7
10async function sendDeleteVideoChannel (videoChannel: VideoChannelModel, t: Transaction) {
11 const byAccount = videoChannel.Account
12
13 const data = deleteActivityData(videoChannel.url, byAccount)
14
15 const accountsInvolved = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t)
16 accountsInvolved.push(byAccount)
17
18 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
19}
20
21async function sendDeleteVideo (video: VideoModel, t: Transaction) { 8async function sendDeleteVideo (video: VideoModel, t: Transaction) {
22 const byAccount = video.VideoChannel.Account 9 const byActor = video.VideoChannel.Account.Actor
23 10
24 const data = deleteActivityData(video.url, byAccount) 11 const data = deleteActivityData(video.url, byActor)
25 12
26 const accountsInvolved = await VideoShareModel.loadAccountsByShare(video.id, t) 13 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
27 accountsInvolved.push(byAccount) 14 actorsInvolved.push(byActor)
28 15
29 return broadcastToFollowers(data, byAccount, accountsInvolved, t) 16 return broadcastToFollowers(data, byActor, actorsInvolved, t)
30} 17}
31 18
32async function sendDeleteAccount (account: AccountModel, t: Transaction) { 19async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
33 const data = deleteActivityData(account.url, account) 20 const data = deleteActivityData(byActor.url, byActor)
34 21
35 return broadcastToFollowers(data, account, [ account ], t) 22 return broadcastToFollowers(data, byActor, [ byActor ], t)
36} 23}
37 24
38// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
39 26
40export { 27export {
41 sendDeleteVideoChannel,
42 sendDeleteVideo, 28 sendDeleteVideo,
43 sendDeleteAccount 29 sendDeleteActor
44} 30}
45 31
46// --------------------------------------------------------------------------- 32// ---------------------------------------------------------------------------
47 33
48function deleteActivityData (url: string, byAccount: AccountModel): ActivityDelete { 34function deleteActivityData (url: string, byActor: ActorModel): ActivityDelete {
49 return { 35 return {
50 type: 'Delete', 36 type: 'Delete',
51 id: url, 37 id: url,
52 actor: byAccount.url 38 actor: byActor.url
53 } 39 }
54} 40}
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts
index 51735ddfd..eac60e94f 100644
--- a/server/lib/activitypub/send/send-follow.ts
+++ b/server/lib/activitypub/send/send-follow.ts
@@ -1,26 +1,26 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityFollow } from '../../../../shared/models/activitypub' 2import { ActivityFollow } from '../../../../shared/models/activitypub'
3import { AccountModel } from '../../../models/account/account' 3import { ActorModel } from '../../../models/activitypub/actor'
4import { AccountFollowModel } from '../../../models/account/account-follow' 4import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
5import { getAccountFollowActivityPubUrl } from '../url' 5import { getActorFollowActivityPubUrl } from '../url'
6import { unicastTo } from './misc' 6import { unicastTo } from './misc'
7 7
8function sendFollow (accountFollow: AccountFollowModel, t: Transaction) { 8function sendFollow (actorFollow: ActorFollowModel, t: Transaction) {
9 const me = accountFollow.AccountFollower 9 const me = actorFollow.ActorFollower
10 const following = accountFollow.AccountFollowing 10 const following = actorFollow.ActorFollowing
11 11
12 const url = getAccountFollowActivityPubUrl(accountFollow) 12 const url = getActorFollowActivityPubUrl(actorFollow)
13 const data = followActivityData(url, me, following) 13 const data = followActivityData(url, me, following)
14 14
15 return unicastTo(data, me, following.inboxUrl, t) 15 return unicastTo(data, me, following.inboxUrl, t)
16} 16}
17 17
18function followActivityData (url: string, byAccount: AccountModel, targetAccount: AccountModel): ActivityFollow { 18function followActivityData (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow {
19 return { 19 return {
20 type: 'Follow', 20 type: 'Follow',
21 id: url, 21 id: url,
22 actor: byAccount.url, 22 actor: byActor.url,
23 object: targetAccount.url 23 object: targetActor.url
24 } 24 }
25} 25}
26 26
diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts
index 1a35d0db0..7e0c73796 100644
--- a/server/lib/activitypub/send/send-like.ts
+++ b/server/lib/activitypub/send/send-like.ts
@@ -1,53 +1,53 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' 2import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub'
3import { AccountModel } from '../../../models/account/account' 3import { ActorModel } from '../../../models/activitypub/actor'
4import { VideoModel } from '../../../models/video/video' 4import { VideoModel } from '../../../models/video/video'
5import { getVideoLikeActivityPubUrl } from '../url' 5import { getVideoLikeActivityPubUrl } from '../url'
6import { 6import {
7 broadcastToFollowers, 7 broadcastToFollowers,
8 getAccountsInvolvedInVideo, 8 getActorsInvolvedInVideo,
9 getAudience, 9 getAudience,
10 getOriginVideoAudience,
11 getObjectFollowersAudience, 10 getObjectFollowersAudience,
11 getOriginVideoAudience,
12 unicastTo 12 unicastTo
13} from './misc' 13} from './misc'
14 14
15async function sendLikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { 15async function sendLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
16 const url = getVideoLikeActivityPubUrl(byAccount, video) 16 const url = getVideoLikeActivityPubUrl(byActor, video)
17 17
18 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) 18 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
19 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 19 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
20 const data = await likeActivityData(url, byAccount, video, t, audience) 20 const data = await likeActivityData(url, byActor, video, t, audience)
21 21
22 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 22 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
23} 23}
24 24
25async function sendLikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { 25async function sendLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
26 const url = getVideoLikeActivityPubUrl(byAccount, video) 26 const url = getVideoLikeActivityPubUrl(byActor, video)
27 27
28 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) 28 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
29 const audience = getObjectFollowersAudience(accountsInvolvedInVideo) 29 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
30 const data = await likeActivityData(url, byAccount, video, t, audience) 30 const data = await likeActivityData(url, byActor, video, t, audience)
31 31
32 const followersException = [ byAccount ] 32 const followersException = [ byActor ]
33 return broadcastToFollowers(data, byAccount, accountsInvolvedInVideo, t, followersException) 33 return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
34} 34}
35 35
36async function likeActivityData ( 36async function likeActivityData (
37 url: string, 37 url: string,
38 byAccount: AccountModel, 38 byActor: ActorModel,
39 video: VideoModel, 39 video: VideoModel,
40 t: Transaction, 40 t: Transaction,
41 audience?: ActivityAudience 41 audience?: ActivityAudience
42): Promise<ActivityLike> { 42): Promise<ActivityLike> {
43 if (!audience) { 43 if (!audience) {
44 audience = await getAudience(byAccount, t) 44 audience = await getAudience(byActor, t)
45 } 45 }
46 46
47 return { 47 return {
48 type: 'Like', 48 type: 'Like',
49 id: url, 49 id: url,
50 actor: byAccount.url, 50 actor: byActor.url,
51 to: audience.to, 51 to: audience.to,
52 cc: audience.cc, 52 cc: audience.cc,
53 object: video.url 53 object: video.url
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts
index 699f920f0..92271b700 100644
--- a/server/lib/activitypub/send/send-undo.ts
+++ b/server/lib/activitypub/send/send-undo.ts
@@ -6,13 +6,13 @@ import {
6 ActivityLike, 6 ActivityLike,
7 ActivityUndo 7 ActivityUndo
8} from '../../../../shared/models/activitypub' 8} from '../../../../shared/models/activitypub'
9import { AccountModel } from '../../../models/account/account' 9import { ActorModel } from '../../../models/activitypub/actor'
10import { AccountFollowModel } from '../../../models/account/account-follow' 10import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
11import { VideoModel } from '../../../models/video/video' 11import { VideoModel } from '../../../models/video/video'
12import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' 12import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
13import { 13import {
14 broadcastToFollowers, 14 broadcastToFollowers,
15 getAccountsInvolvedInVideo, 15 getActorsInvolvedInVideo,
16 getAudience, 16 getAudience,
17 getObjectFollowersAudience, 17 getObjectFollowersAudience,
18 getOriginVideoAudience, 18 getOriginVideoAudience,
@@ -22,11 +22,11 @@ import { createActivityData, createDislikeActivityData } from './send-create'
22import { followActivityData } from './send-follow' 22import { followActivityData } from './send-follow'
23import { likeActivityData } from './send-like' 23import { likeActivityData } from './send-like'
24 24
25async function sendUndoFollow (accountFollow: AccountFollowModel, t: Transaction) { 25async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
26 const me = accountFollow.AccountFollower 26 const me = actorFollow.ActorFollower
27 const following = accountFollow.AccountFollowing 27 const following = actorFollow.ActorFollowing
28 28
29 const followUrl = getAccountFollowActivityPubUrl(accountFollow) 29 const followUrl = getActorFollowActivityPubUrl(actorFollow)
30 const undoUrl = getUndoActivityPubUrl(followUrl) 30 const undoUrl = getUndoActivityPubUrl(followUrl)
31 31
32 const object = followActivityData(followUrl, me, following) 32 const object = followActivityData(followUrl, me, following)
@@ -35,58 +35,58 @@ async function sendUndoFollow (accountFollow: AccountFollowModel, t: Transaction
35 return unicastTo(data, me, following.inboxUrl, t) 35 return unicastTo(data, me, following.inboxUrl, t)
36} 36}
37 37
38async function sendUndoLikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { 38async function sendUndoLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
39 const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) 39 const likeUrl = getVideoLikeActivityPubUrl(byActor, video)
40 const undoUrl = getUndoActivityPubUrl(likeUrl) 40 const undoUrl = getUndoActivityPubUrl(likeUrl)
41 41
42 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) 42 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
43 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 43 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
44 const object = await likeActivityData(likeUrl, byAccount, video, t) 44 const object = await likeActivityData(likeUrl, byActor, video, t)
45 const data = await undoActivityData(undoUrl, byAccount, object, t, audience) 45 const data = await undoActivityData(undoUrl, byActor, object, t, audience)
46 46
47 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 47 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
48} 48}
49 49
50async function sendUndoLikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { 50async function sendUndoLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
51 const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) 51 const likeUrl = getVideoLikeActivityPubUrl(byActor, video)
52 const undoUrl = getUndoActivityPubUrl(likeUrl) 52 const undoUrl = getUndoActivityPubUrl(likeUrl)
53 53
54 const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t) 54 const toActorsFollowers = await getActorsInvolvedInVideo(video, t)
55 const audience = getObjectFollowersAudience(toAccountsFollowers) 55 const audience = getObjectFollowersAudience(toActorsFollowers)
56 const object = await likeActivityData(likeUrl, byAccount, video, t) 56 const object = await likeActivityData(likeUrl, byActor, video, t)
57 const data = await undoActivityData(undoUrl, byAccount, object, t, audience) 57 const data = await undoActivityData(undoUrl, byActor, object, t, audience)
58 58
59 const followersException = [ byAccount ] 59 const followersException = [ byActor ]
60 return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) 60 return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException)
61} 61}
62 62
63async function sendUndoDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { 63async function sendUndoDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
64 const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) 64 const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
65 const undoUrl = getUndoActivityPubUrl(dislikeUrl) 65 const undoUrl = getUndoActivityPubUrl(dislikeUrl)
66 66
67 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) 67 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
68 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 68 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
69 const dislikeActivity = createDislikeActivityData(byAccount, video) 69 const dislikeActivity = createDislikeActivityData(byActor, video)
70 const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t) 70 const object = await createActivityData(undoUrl, byActor, dislikeActivity, t)
71 71
72 const data = await undoActivityData(undoUrl, byAccount, object, t, audience) 72 const data = await undoActivityData(undoUrl, byActor, object, t, audience)
73 73
74 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 74 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
75} 75}
76 76
77async function sendUndoDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { 77async function sendUndoDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
78 const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) 78 const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
79 const undoUrl = getUndoActivityPubUrl(dislikeUrl) 79 const undoUrl = getUndoActivityPubUrl(dislikeUrl)
80 80
81 const dislikeActivity = createDislikeActivityData(byAccount, video) 81 const dislikeActivity = createDislikeActivityData(byActor, video)
82 const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t) 82 const object = await createActivityData(undoUrl, byActor, dislikeActivity, t)
83 83
84 const data = await undoActivityData(undoUrl, byAccount, object, t) 84 const data = await undoActivityData(undoUrl, byActor, object, t)
85 85
86 const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t) 86 const toActorsFollowers = await getActorsInvolvedInVideo(video, t)
87 87
88 const followersException = [ byAccount ] 88 const followersException = [ byActor ]
89 return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) 89 return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException)
90} 90}
91 91
92// --------------------------------------------------------------------------- 92// ---------------------------------------------------------------------------
@@ -103,19 +103,19 @@ export {
103 103
104async function undoActivityData ( 104async function undoActivityData (
105 url: string, 105 url: string,
106 byAccount: AccountModel, 106 byActor: ActorModel,
107 object: ActivityFollow | ActivityLike | ActivityCreate, 107 object: ActivityFollow | ActivityLike | ActivityCreate,
108 t: Transaction, 108 t: Transaction,
109 audience?: ActivityAudience 109 audience?: ActivityAudience
110): Promise<ActivityUndo> { 110): Promise<ActivityUndo> {
111 if (!audience) { 111 if (!audience) {
112 audience = await getAudience(byAccount, t) 112 audience = await getAudience(byActor, t)
113 } 113 }
114 114
115 return { 115 return {
116 type: 'Undo', 116 type: 'Undo',
117 id: url, 117 id: url,
118 actor: byAccount.url, 118 actor: byActor.url,
119 to: audience.to, 119 to: audience.to,
120 cc: audience.cc, 120 cc: audience.cc,
121 object 121 object
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts
index 9baf13a87..48bbbcac1 100644
--- a/server/lib/activitypub/send/send-update.ts
+++ b/server/lib/activitypub/send/send-update.ts
@@ -1,56 +1,52 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityUpdate } from '../../../../shared/models/activitypub' 2import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub'
3import { AccountModel } from '../../../models/account/account' 3import { VideoPrivacy } from '../../../../shared/models/videos'
4import { ActorModel } from '../../../models/activitypub/actor'
4import { VideoModel } from '../../../models/video/video' 5import { VideoModel } from '../../../models/video/video'
5import { VideoChannelModel } from '../../../models/video/video-channel'
6import { VideoChannelShareModel } from '../../../models/video/video-channel-share'
7import { VideoShareModel } from '../../../models/video/video-share' 6import { VideoShareModel } from '../../../models/video/video-share'
8import { getUpdateActivityPubUrl } from '../url' 7import { getUpdateActivityPubUrl } from '../url'
9import { broadcastToFollowers, getAudience } from './misc' 8import { broadcastToFollowers, getAudience } from './misc'
10 9
11async function sendUpdateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) {
12 const byAccount = videoChannel.Account
13
14 const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString())
15 const videoChannelObject = videoChannel.toActivityPubObject()
16 const data = await updateActivityData(url, byAccount, videoChannelObject, t)
17
18 const accountsInvolved = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t)
19 accountsInvolved.push(byAccount)
20
21 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
22}
23
24async function sendUpdateVideo (video: VideoModel, t: Transaction) { 10async function sendUpdateVideo (video: VideoModel, t: Transaction) {
25 const byAccount = video.VideoChannel.Account 11 const byActor = video.VideoChannel.Account.Actor
26 12
27 const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) 13 const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
28 const videoObject = video.toActivityPubObject() 14 const videoObject = video.toActivityPubObject()
29 const data = await updateActivityData(url, byAccount, videoObject, t) 15 const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC)
16
17 const data = await updateActivityData(url, byActor, videoObject, t, audience)
30 18
31 const accountsInvolved = await VideoShareModel.loadAccountsByShare(video.id, t) 19 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
32 accountsInvolved.push(byAccount) 20 actorsInvolved.push(byActor)
33 21
34 return broadcastToFollowers(data, byAccount, accountsInvolved, t) 22 return broadcastToFollowers(data, byActor, actorsInvolved, t)
35} 23}
36 24
37// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
38 26
39export { 27export {
40 sendUpdateVideoChannel,
41 sendUpdateVideo 28 sendUpdateVideo
42} 29}
43 30
44// --------------------------------------------------------------------------- 31// ---------------------------------------------------------------------------
45 32
46async function updateActivityData (url: string, byAccount: AccountModel, object: any, t: Transaction): Promise<ActivityUpdate> { 33async function updateActivityData (
47 const { to, cc } = await getAudience(byAccount, t) 34 url: string,
35 byActor: ActorModel,
36 object: any,
37 t: Transaction,
38 audience?: ActivityAudience
39): Promise<ActivityUpdate> {
40 if (!audience) {
41 audience = await getAudience(byActor, t)
42 }
43
48 return { 44 return {
49 type: 'Update', 45 type: 'Update',
50 id: url, 46 id: url,
51 actor: byAccount.url, 47 actor: byActor.url,
52 to, 48 to: audience.to,
53 cc, 49 cc: audience.cc,
54 object 50 object
55 } 51 }
56} 52}