blob: a04fc79945060fd84d843fd0c08d902ea8c314e3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import { ActivityFollow } from '../../../shared/models/activitypub/activity'
import { getOrCreateAccount } from '../../helpers'
import { database as db } from '../../initializers'
import { AccountInstance } from '../../models/account/account-interface'
async function processFollowActivity (activity: ActivityFollow) {
const activityObject = activity.object
const account = await getOrCreateAccount(activity.actor)
return processFollow(account, activityObject)
}
// ---------------------------------------------------------------------------
export {
processFollowActivity
}
// ---------------------------------------------------------------------------
async function processFollow (account: AccountInstance, targetAccountURL: string) {
const targetAccount = await db.Account.loadByUrl(targetAccountURL)
if (targetAccount === undefined) throw new Error('Unknown account')
if (targetAccount.isOwned() === false) throw new Error('This is not a local account.')
return db.AccountFollow.create({
accountId: account.id,
targetAccountId: targetAccount.id,
state: 'accepted'
})
}
|