1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 10:49:28 +02:00

Handle follow/accept

This commit is contained in:
Chocobozzz 2017-11-13 17:39:41 +01:00
parent 571389d43b
commit 7a7724e66e
No known key found for this signature in database
GPG key ID: 583A612D890159BE
29 changed files with 493 additions and 208 deletions

View file

@ -0,0 +1,27 @@
import { ActivityAccept } from '../../../shared/models/activitypub/activity'
import { database as db } from '../../initializers'
import { AccountInstance } from '../../models/account/account-interface'
async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountInstance) {
if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.')
const targetAccount = await db.Account.loadByUrl(activity.actor)
return processFollow(inboxAccount, targetAccount)
}
// ---------------------------------------------------------------------------
export {
processAcceptActivity
}
// ---------------------------------------------------------------------------
async function processFollow (account: AccountInstance, targetAccount: AccountInstance) {
const follow = await db.AccountFollow.loadByAccountAndTarget(account.id, targetAccount.id)
if (!follow) throw new Error('Cannot find associated follow.')
follow.set('state', 'accepted')
return follow.save()
}