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.ts46
1 files changed, 45 insertions, 1 deletions
diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts
index ce9a96f14..e6ef5f37a 100644
--- a/server/lib/activitypub/send-request.ts
+++ b/server/lib/activitypub/send-request.ts
@@ -56,6 +56,18 @@ function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction)
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) {
60 const data = acceptActivityData(fromAccount)
61
62 return unicastTo(data, toAccount, t)
63}
64
65function sendFollow (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) {
66 const data = followActivityData(toAccount.url, fromAccount)
67
68 return unicastTo(data, toAccount, t)
69}
70
59// --------------------------------------------------------------------------- 71// ---------------------------------------------------------------------------
60 72
61export { 73export {
@@ -65,7 +77,9 @@ export {
65 sendAddVideo, 77 sendAddVideo,
66 sendUpdateVideo, 78 sendUpdateVideo,
67 sendDeleteVideo, 79 sendDeleteVideo,
68 sendDeleteAccount 80 sendDeleteAccount,
81 sendAccept,
82 sendFollow
69} 83}
70 84
71// --------------------------------------------------------------------------- 85// ---------------------------------------------------------------------------
@@ -81,6 +95,15 @@ async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t:
81 return httpRequestJobScheduler.createJob(t, 'httpRequestBroadcastHandler', jobPayload) 95 return httpRequestJobScheduler.createJob(t, 'httpRequestBroadcastHandler', jobPayload)
82} 96}
83 97
98async function unicastTo (data: any, toAccount: AccountInstance, t: Sequelize.Transaction) {
99 const jobPayload = {
100 uris: [ toAccount.url ],
101 body: data
102 }
103
104 return httpRequestJobScheduler.createJob(t, 'httpRequestUnicastHandler', jobPayload)
105}
106
84function buildSignedActivity (byAccount: AccountInstance, data: Object) { 107function buildSignedActivity (byAccount: AccountInstance, data: Object) {
85 const activity = activityPubContextify(data) 108 const activity = activityPubContextify(data)
86 109
@@ -142,3 +165,24 @@ async function addActivityData (url: string, byAccount: AccountInstance, target:
142 165
143 return buildSignedActivity(byAccount, base) 166 return buildSignedActivity(byAccount, base)
144} 167}
168
169async function followActivityData (url: string, byAccount: AccountInstance) {
170 const base = {
171 type: 'Follow',
172 id: byAccount.url,
173 actor: byAccount.url,
174 object: url
175 }
176
177 return buildSignedActivity(byAccount, base)
178}
179
180async function acceptActivityData (byAccount: AccountInstance) {
181 const base = {
182 type: 'Accept',
183 id: byAccount.url,
184 actor: byAccount.url
185 }
186
187 return buildSignedActivity(byAccount, base)
188}