aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/misc.ts6
-rw-r--r--server/lib/activitypub/process-create.ts4
-rw-r--r--server/lib/activitypub/send-request.ts56
3 files changed, 50 insertions, 16 deletions
diff --git a/server/lib/activitypub/misc.ts b/server/lib/activitypub/misc.ts
index 2cf0c4fd1..43d26c328 100644
--- a/server/lib/activitypub/misc.ts
+++ b/server/lib/activitypub/misc.ts
@@ -28,9 +28,9 @@ async function videoActivityObjectToDBAttributes (
28 description: videoObject.content, 28 description: videoObject.content,
29 channelId: videoChannel.id, 29 channelId: videoChannel.id,
30 duration: parseInt(duration, 10), 30 duration: parseInt(duration, 10),
31 createdAt: videoObject.published, 31 createdAt: new Date(videoObject.published),
32 // FIXME: updatedAt does not seems to be considered by Sequelize 32 // FIXME: updatedAt does not seems to be considered by Sequelize
33 updatedAt: videoObject.updated, 33 updatedAt: new Date(videoObject.updated),
34 views: videoObject.views, 34 views: videoObject.views,
35 likes: 0, 35 likes: 0,
36 dislikes: 0, 36 dislikes: 0,
@@ -46,7 +46,7 @@ async function videoActivityObjectToDBAttributes (
46 46
47function videoFileActivityUrlToDBAttributes (videoCreated: VideoInstance, videoObject: VideoTorrentObject) { 47function videoFileActivityUrlToDBAttributes (videoCreated: VideoInstance, videoObject: VideoTorrentObject) {
48 const fileUrls = videoObject.url 48 const fileUrls = videoObject.url
49 .filter(u => Object.keys(VIDEO_MIMETYPE_EXT).indexOf(u.mimeType) !== -1) 49 .filter(u => Object.keys(VIDEO_MIMETYPE_EXT).indexOf(u.mimeType) !== -1 && u.url.startsWith('video/'))
50 50
51 const attributes: VideoFileAttributes[] = [] 51 const attributes: VideoFileAttributes[] = []
52 for (const url of fileUrls) { 52 for (const url of fileUrls) {
diff --git a/server/lib/activitypub/process-create.ts b/server/lib/activitypub/process-create.ts
index 1b825ebbc..4e4c9f703 100644
--- a/server/lib/activitypub/process-create.ts
+++ b/server/lib/activitypub/process-create.ts
@@ -48,8 +48,8 @@ async function addRemoteVideoChannel (account: AccountInstance, videoChannelToCr
48 name: videoChannelToCreateData.name, 48 name: videoChannelToCreateData.name,
49 description: videoChannelToCreateData.content, 49 description: videoChannelToCreateData.content,
50 uuid: videoChannelToCreateData.uuid, 50 uuid: videoChannelToCreateData.uuid,
51 createdAt: videoChannelToCreateData.published, 51 createdAt: new Date(videoChannelToCreateData.published),
52 updatedAt: videoChannelToCreateData.updated, 52 updatedAt: new Date(videoChannelToCreateData.updated),
53 remote: true, 53 remote: true,
54 accountId: account.id 54 accountId: account.id
55 } 55 }
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',