aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send-request.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/send-request.ts')
-rw-r--r--server/lib/activitypub/send-request.ts56
1 files changed, 45 insertions, 11 deletions
diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts
index 1dad51828..664b9d826 100644
--- a/server/lib/activitypub/send-request.ts
+++ b/server/lib/activitypub/send-request.ts
@@ -17,46 +17,67 @@ async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Se
17 const videoChannelObject = videoChannel.toActivityPubObject() 17 const videoChannelObject = videoChannel.toActivityPubObject()
18 const data = await createActivityData(videoChannel.url, videoChannel.Account, videoChannelObject) 18 const data = await createActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
19 19
20 return broadcastToFollowers(data, videoChannel.Account, t) 20 return broadcastToFollowers(data, [ videoChannel.Account ], t)
21} 21}
22 22
23async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { 23async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
24 const videoChannelObject = videoChannel.toActivityPubObject() 24 const videoChannelObject = videoChannel.toActivityPubObject()
25 const data = await updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject) 25 const data = await updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
26 26
27 return broadcastToFollowers(data, videoChannel.Account, t) 27 return broadcastToFollowers(data, [ videoChannel.Account ], t)
28} 28}
29 29
30async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { 30async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
31 const data = await deleteActivityData(videoChannel.url, videoChannel.Account) 31 const data = await deleteActivityData(videoChannel.url, videoChannel.Account)
32 32
33 return broadcastToFollowers(data, videoChannel.Account, t) 33 return broadcastToFollowers(data, [ videoChannel.Account ], t)
34} 34}
35 35
36async function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) { 36async function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) {
37 const videoObject = video.toActivityPubObject() 37 const videoObject = video.toActivityPubObject()
38 const data = await addActivityData(video.url, video.VideoChannel.Account, video.VideoChannel.url, videoObject) 38 const data = await addActivityData(video.url, video.VideoChannel.Account, video.VideoChannel.url, videoObject)
39 39
40 return broadcastToFollowers(data, video.VideoChannel.Account, t) 40 return broadcastToFollowers(data, [ video.VideoChannel.Account ], t)
41} 41}
42 42
43async function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction) { 43async function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction) {
44 const videoObject = video.toActivityPubObject() 44 const videoObject = video.toActivityPubObject()
45 const data = await updateActivityData(video.url, video.VideoChannel.Account, videoObject) 45 const data = await updateActivityData(video.url, video.VideoChannel.Account, videoObject)
46 46
47 return broadcastToFollowers(data, video.VideoChannel.Account, t) 47 return broadcastToFollowers(data, [ video.VideoChannel.Account ], t)
48} 48}
49 49
50async function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) { 50async function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) {
51 const data = await deleteActivityData(video.url, video.VideoChannel.Account) 51 const data = await deleteActivityData(video.url, video.VideoChannel.Account)
52 52
53 return broadcastToFollowers(data, video.VideoChannel.Account, t) 53 return broadcastToFollowers(data, [ video.VideoChannel.Account ], t)
54} 54}
55 55
56async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) { 56async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) {
57 const data = await deleteActivityData(account.url, account) 57 const data = await deleteActivityData(account.url, account)
58 58
59 return broadcastToFollowers(data, account, t) 59 return broadcastToFollowers(data, [ account ], t)
60}
61
62async function sendAnnounce (byAccount: AccountInstance, instance: VideoInstance | VideoChannelInstance, t: Sequelize.Transaction) {
63 const object = instance.toActivityPubObject()
64
65 let url = ''
66 let objectActorUrl: string
67 if ((instance as any).VideoChannel !== undefined) {
68 objectActorUrl = (instance as VideoInstance).VideoChannel.Account.url
69 url = getActivityPubUrl('video', instance.uuid) + '#announce'
70 } else {
71 objectActorUrl = (instance as VideoChannelInstance).Account.url
72 url = getActivityPubUrl('videoChannel', instance.uuid) + '#announce'
73 }
74
75 const objectWithActor = Object.assign(object, {
76 actor: objectActorUrl
77 })
78
79 const data = await announceActivityData(url, byAccount, objectWithActor)
80 return broadcastToFollowers(data, [ byAccount ], t)
60} 81}
61 82
62async function sendVideoAbuse ( 83async function sendVideoAbuse (
@@ -95,15 +116,17 @@ export {
95 sendDeleteAccount, 116 sendDeleteAccount,
96 sendAccept, 117 sendAccept,
97 sendFollow, 118 sendFollow,
98 sendVideoAbuse 119 sendVideoAbuse,
120 sendAnnounce
99} 121}
100 122
101// --------------------------------------------------------------------------- 123// ---------------------------------------------------------------------------
102 124
103async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t: Sequelize.Transaction) { 125async function broadcastToFollowers (data: any, toAccountFollowers: AccountInstance[], t: Sequelize.Transaction) {
104 const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi(fromAccount.id) 126 const toAccountFollowerIds = toAccountFollowers.map(a => a.id)
127 const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds)
105 if (result.data.length === 0) { 128 if (result.data.length === 0) {
106 logger.info('Not broadcast because of 0 followers.') 129 logger.info('Not broadcast because of 0 followers for %s.', toAccountFollowerIds.join(', '))
107 return 130 return
108 } 131 }
109 132
@@ -186,6 +209,17 @@ async function addActivityData (url: string, byAccount: AccountInstance, target:
186 return buildSignedActivity(byAccount, base) 209 return buildSignedActivity(byAccount, base)
187} 210}
188 211
212async function announceActivityData (url: string, byAccount: AccountInstance, object: any) {
213 const base = {
214 type: 'Announce',
215 id: url,
216 actor: byAccount.url,
217 object
218 }
219
220 return buildSignedActivity(byAccount, base)
221}
222
189async function followActivityData (url: string, byAccount: AccountInstance) { 223async function followActivityData (url: string, byAccount: AccountInstance) {
190 const base = { 224 const base = {
191 type: 'Follow', 225 type: 'Follow',