diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 14:44:51 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:53 +0100 |
commit | 4e50b6a1c9a3eb261e04ede73241648e6edf21d6 (patch) | |
tree | e1c6c121d561ffc1cf2996daec03a1e7f27f0a25 /server/lib/activitypub/send/send-announce.ts | |
parent | 74bb2cb8348d6794ed3a0e2ec94c8c9abdde82cf (diff) | |
download | PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.gz PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.zst PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.zip |
Add shares forward and collection on videos/video channels
Diffstat (limited to 'server/lib/activitypub/send/send-announce.ts')
-rw-r--r-- | server/lib/activitypub/send/send-announce.ts | 86 |
1 files changed, 76 insertions, 10 deletions
diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts index b8ea51bc0..efc23af46 100644 --- a/server/lib/activitypub/send/send-announce.ts +++ b/server/lib/activitypub/send/send-announce.ts | |||
@@ -1,34 +1,96 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAdd } from '../../../../shared/index' | 2 | import { ActivityAdd } from '../../../../shared/index' |
3 | import { ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub/activity' | 3 | import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub/activity' |
4 | import { AccountInstance, VideoInstance } from '../../../models' | 4 | import { AccountInstance, VideoInstance } from '../../../models' |
5 | import { VideoChannelInstance } from '../../../models/video/video-channel-interface' | 5 | import { VideoChannelInstance } from '../../../models/video/video-channel-interface' |
6 | import { getAnnounceActivityPubUrl } from '../url' | 6 | import { getAnnounceActivityPubUrl } from '../url' |
7 | import { broadcastToFollowers } from './misc' | 7 | import { |
8 | broadcastToFollowers, | ||
9 | getAccountsInvolvedInVideo, | ||
10 | getAccountsInvolvedInVideoChannel, | ||
11 | getAudience, | ||
12 | getObjectFollowersAudience, | ||
13 | getOriginVideoAudience, | ||
14 | getOriginVideoChannelAudience, | ||
15 | unicastTo | ||
16 | } from './misc' | ||
8 | import { addActivityData } from './send-add' | 17 | import { addActivityData } from './send-add' |
9 | import { createActivityData } from './send-create' | 18 | import { createActivityData } from './send-create' |
10 | 19 | ||
11 | async function sendVideoAnnounce (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 20 | async function buildVideoAnnounceToFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { |
12 | const url = getAnnounceActivityPubUrl(video.url, byAccount) | 21 | const url = getAnnounceActivityPubUrl(video.url, byAccount) |
13 | 22 | ||
14 | const videoChannel = video.VideoChannel | 23 | const videoChannel = video.VideoChannel |
15 | const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject()) | 24 | const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject()) |
16 | 25 | ||
17 | const data = await announceActivityData(url, byAccount, announcedActivity) | 26 | const accountsToForwardView = await getAccountsInvolvedInVideo(video) |
27 | const audience = getObjectFollowersAudience(accountsToForwardView) | ||
28 | const data = await announceActivityData(url, byAccount, announcedActivity, audience) | ||
29 | |||
30 | return data | ||
31 | } | ||
32 | |||
33 | async function sendVideoAnnounceToFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | ||
34 | const data = await buildVideoAnnounceToFollowers(byAccount, video, t) | ||
35 | |||
18 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 36 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
19 | } | 37 | } |
20 | 38 | ||
21 | async function sendVideoChannelAnnounce (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { | 39 | async function sendVideoAnnounceToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { |
40 | const url = getAnnounceActivityPubUrl(video.url, byAccount) | ||
41 | |||
42 | const videoChannel = video.VideoChannel | ||
43 | const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject()) | ||
44 | |||
45 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) | ||
46 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | ||
47 | const data = await createActivityData(url, byAccount, announcedActivity, audience) | ||
48 | |||
49 | return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) | ||
50 | } | ||
51 | |||
52 | async function buildVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { | ||
22 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) | 53 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) |
23 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject()) | 54 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject()) |
24 | 55 | ||
25 | const data = await announceActivityData(url, byAccount, announcedActivity) | 56 | const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel) |
57 | const audience = getObjectFollowersAudience(accountsToForwardView) | ||
58 | const data = await announceActivityData(url, byAccount, announcedActivity, audience) | ||
59 | |||
60 | return data | ||
61 | } | ||
62 | |||
63 | async function sendVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { | ||
64 | const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t) | ||
65 | |||
26 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 66 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
27 | } | 67 | } |
28 | 68 | ||
29 | async function announceActivityData (url: string, byAccount: AccountInstance, object: ActivityCreate | ActivityAdd) { | 69 | async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { |
70 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) | ||
71 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject()) | ||
72 | |||
73 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideoChannel(videoChannel) | ||
74 | const audience = getOriginVideoChannelAudience(videoChannel, accountsInvolvedInVideo) | ||
75 | const data = await createActivityData(url, byAccount, announcedActivity, audience) | ||
76 | |||
77 | return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) | ||
78 | } | ||
79 | |||
80 | async function announceActivityData ( | ||
81 | url: string, | ||
82 | byAccount: AccountInstance, | ||
83 | object: ActivityCreate | ActivityAdd, | ||
84 | audience?: ActivityAudience | ||
85 | ) { | ||
86 | if (!audience) { | ||
87 | audience = await getAudience(byAccount) | ||
88 | } | ||
89 | |||
30 | const activity: ActivityAnnounce = { | 90 | const activity: ActivityAnnounce = { |
31 | type: 'Announce', | 91 | type: 'Announce', |
92 | to: audience.to, | ||
93 | cc: audience.cc, | ||
32 | id: url, | 94 | id: url, |
33 | actor: byAccount.url, | 95 | actor: byAccount.url, |
34 | object | 96 | object |
@@ -40,7 +102,11 @@ async function announceActivityData (url: string, byAccount: AccountInstance, ob | |||
40 | // --------------------------------------------------------------------------- | 102 | // --------------------------------------------------------------------------- |
41 | 103 | ||
42 | export { | 104 | export { |
43 | sendVideoAnnounce, | 105 | sendVideoAnnounceToFollowers, |
44 | sendVideoChannelAnnounce, | 106 | sendVideoChannelAnnounceToFollowers, |
45 | announceActivityData | 107 | sendVideoAnnounceToOrigin, |
108 | sendVideoChannelAnnounceToOrigin, | ||
109 | announceActivityData, | ||
110 | buildVideoAnnounceToFollowers, | ||
111 | buildVideoChannelAnnounceToFollowers | ||
46 | } | 112 | } |