aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process-follow.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-13 17:39:41 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit7a7724e66e4533523083e7336cd0d0c747c4a33b (patch)
tree805299eb9c6829158cd17e5a823a84a3a54d8209 /server/lib/activitypub/process-follow.ts
parent571389d43b8fc8aaf27e77c06f19b320b08dbbc9 (diff)
downloadPeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.gz
PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.zst
PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.zip
Handle follow/accept
Diffstat (limited to 'server/lib/activitypub/process-follow.ts')
-rw-r--r--server/lib/activitypub/process-follow.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/server/lib/activitypub/process-follow.ts b/server/lib/activitypub/process-follow.ts
new file mode 100644
index 000000000..a04fc7994
--- /dev/null
+++ b/server/lib/activitypub/process-follow.ts
@@ -0,0 +1,32 @@
1import { ActivityFollow } from '../../../shared/models/activitypub/activity'
2import { getOrCreateAccount } from '../../helpers'
3import { database as db } from '../../initializers'
4import { AccountInstance } from '../../models/account/account-interface'
5
6async function processFollowActivity (activity: ActivityFollow) {
7 const activityObject = activity.object
8 const account = await getOrCreateAccount(activity.actor)
9
10 return processFollow(account, activityObject)
11}
12
13// ---------------------------------------------------------------------------
14
15export {
16 processFollowActivity
17}
18
19// ---------------------------------------------------------------------------
20
21async function processFollow (account: AccountInstance, targetAccountURL: string) {
22 const targetAccount = await db.Account.loadByUrl(targetAccountURL)
23
24 if (targetAccount === undefined) throw new Error('Unknown account')
25 if (targetAccount.isOwned() === false) throw new Error('This is not a local account.')
26
27 return db.AccountFollow.create({
28 accountId: account.id,
29 targetAccountId: targetAccount.id,
30 state: 'accepted'
31 })
32}