aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-14 17:31:26 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad (patch)
treef4191f3c04a5230fcf8ca3d6ca3248643fc4151d /server/lib/activitypub
parente34c85e527100c0b5c44567bd951e95be41b8d7e (diff)
downloadPeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.gz
PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.zst
PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.zip
Follow works
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/process-add.ts2
-rw-r--r--server/lib/activitypub/process-follow.ts18
-rw-r--r--server/lib/activitypub/send-request.ts38
3 files changed, 31 insertions, 27 deletions
diff --git a/server/lib/activitypub/process-add.ts b/server/lib/activitypub/process-add.ts
index 024dee559..06d23a2ea 100644
--- a/server/lib/activitypub/process-add.ts
+++ b/server/lib/activitypub/process-add.ts
@@ -54,7 +54,7 @@ async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string
54 54
55 // Don't block on request 55 // Don't block on request
56 generateThumbnailFromUrl(video, videoToCreateData.icon) 56 generateThumbnailFromUrl(video, videoToCreateData.icon)
57 .catch(err => logger.warning('Cannot generate thumbnail of %s.', videoToCreateData.id, err)) 57 .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoToCreateData.id, err))
58 58
59 const videoCreated = await video.save(sequelizeOptions) 59 const videoCreated = await video.save(sequelizeOptions)
60 60
diff --git a/server/lib/activitypub/process-follow.ts b/server/lib/activitypub/process-follow.ts
index ee5d97a0b..a805c0757 100644
--- a/server/lib/activitypub/process-follow.ts
+++ b/server/lib/activitypub/process-follow.ts
@@ -36,14 +36,18 @@ async function follow (account: AccountInstance, targetAccountURL: string) {
36 if (targetAccount === undefined) throw new Error('Unknown account') 36 if (targetAccount === undefined) throw new Error('Unknown account')
37 if (targetAccount.isOwned() === false) throw new Error('This is not a local account.') 37 if (targetAccount.isOwned() === false) throw new Error('This is not a local account.')
38 38
39 const sequelizeOptions = { 39 await db.AccountFollow.findOrCreate({
40 where: {
41 accountId: account.id,
42 targetAccountId: targetAccount.id
43 },
44 defaults: {
45 accountId: account.id,
46 targetAccountId: targetAccount.id,
47 state: 'accepted'
48 },
40 transaction: t 49 transaction: t
41 } 50 })
42 await db.AccountFollow.create({
43 accountId: account.id,
44 targetAccountId: targetAccount.id,
45 state: 'accepted'
46 }, sequelizeOptions)
47 51
48 // Target sends to account he accepted the follow request 52 // Target sends to account he accepted the follow request
49 return sendAccept(targetAccount, account, t) 53 return sendAccept(targetAccount, account, t)
diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts
index c18a69784..d47040d6d 100644
--- a/server/lib/activitypub/send-request.ts
+++ b/server/lib/activitypub/send-request.ts
@@ -10,60 +10,60 @@ import { httpRequestJobScheduler } from '../jobs'
10import { signObject, activityPubContextify } from '../../helpers' 10import { signObject, activityPubContextify } from '../../helpers'
11import { Activity } from '../../../shared' 11import { Activity } from '../../../shared'
12 12
13function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { 13async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
14 const videoChannelObject = videoChannel.toActivityPubObject() 14 const videoChannelObject = videoChannel.toActivityPubObject()
15 const data = createActivityData(videoChannel.url, videoChannel.Account, videoChannelObject) 15 const data = await createActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
16 16
17 return broadcastToFollowers(data, videoChannel.Account, t) 17 return broadcastToFollowers(data, videoChannel.Account, t)
18} 18}
19 19
20function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { 20async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
21 const videoChannelObject = videoChannel.toActivityPubObject() 21 const videoChannelObject = videoChannel.toActivityPubObject()
22 const data = updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject) 22 const data = await updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
23 23
24 return broadcastToFollowers(data, videoChannel.Account, t) 24 return broadcastToFollowers(data, videoChannel.Account, t)
25} 25}
26 26
27function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { 27async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
28 const data = deleteActivityData(videoChannel.url, videoChannel.Account) 28 const data = await deleteActivityData(videoChannel.url, videoChannel.Account)
29 29
30 return broadcastToFollowers(data, videoChannel.Account, t) 30 return broadcastToFollowers(data, videoChannel.Account, t)
31} 31}
32 32
33function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) { 33async function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) {
34 const videoObject = video.toActivityPubObject() 34 const videoObject = video.toActivityPubObject()
35 const data = addActivityData(video.url, video.VideoChannel.Account, video.VideoChannel.url, videoObject) 35 const data = await addActivityData(video.url, video.VideoChannel.Account, video.VideoChannel.url, videoObject)
36 36
37 return broadcastToFollowers(data, video.VideoChannel.Account, t) 37 return broadcastToFollowers(data, video.VideoChannel.Account, t)
38} 38}
39 39
40function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction) { 40async function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction) {
41 const videoObject = video.toActivityPubObject() 41 const videoObject = video.toActivityPubObject()
42 const data = updateActivityData(video.url, video.VideoChannel.Account, videoObject) 42 const data = await updateActivityData(video.url, video.VideoChannel.Account, videoObject)
43 43
44 return broadcastToFollowers(data, video.VideoChannel.Account, t) 44 return broadcastToFollowers(data, video.VideoChannel.Account, t)
45} 45}
46 46
47function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) { 47async function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) {
48 const data = deleteActivityData(video.url, video.VideoChannel.Account) 48 const data = await deleteActivityData(video.url, video.VideoChannel.Account)
49 49
50 return broadcastToFollowers(data, video.VideoChannel.Account, t) 50 return broadcastToFollowers(data, video.VideoChannel.Account, t)
51} 51}
52 52
53function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) { 53async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) {
54 const data = deleteActivityData(account.url, account) 54 const data = await deleteActivityData(account.url, account)
55 55
56 return broadcastToFollowers(data, account, t) 56 return broadcastToFollowers(data, account, t)
57} 57}
58 58
59function sendAccept (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) { 59async function sendAccept (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) {
60 const data = acceptActivityData(fromAccount) 60 const data = await acceptActivityData(fromAccount)
61 61
62 return unicastTo(data, toAccount, t) 62 return unicastTo(data, toAccount, t)
63} 63}
64 64
65function sendFollow (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) { 65async function sendFollow (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) {
66 const data = followActivityData(toAccount.url, fromAccount) 66 const data = await followActivityData(toAccount.url, fromAccount)
67 67
68 return unicastTo(data, toAccount, t) 68 return unicastTo(data, toAccount, t)
69} 69}
@@ -97,7 +97,7 @@ async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t:
97 97
98async function unicastTo (data: any, toAccount: AccountInstance, t: Sequelize.Transaction) { 98async function unicastTo (data: any, toAccount: AccountInstance, t: Sequelize.Transaction) {
99 const jobPayload = { 99 const jobPayload = {
100 uris: [ toAccount.url ], 100 uris: [ toAccount.inboxUrl ],
101 body: data 101 body: data
102 } 102 }
103 103