mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Send follow/accept
This commit is contained in:
parent
7a7724e66e
commit
ce548a10db
9 changed files with 160 additions and 19 deletions
|
@ -1,7 +1,9 @@
|
|||
import { ActivityFollow } from '../../../shared/models/activitypub/activity'
|
||||
import { getOrCreateAccount } from '../../helpers'
|
||||
import { getOrCreateAccount, retryTransactionWrapper } from '../../helpers'
|
||||
import { database as db } from '../../initializers'
|
||||
import { AccountInstance } from '../../models/account/account-interface'
|
||||
import { sendAccept } from './send-request'
|
||||
import { logger } from '../../helpers/logger'
|
||||
|
||||
async function processFollowActivity (activity: ActivityFollow) {
|
||||
const activityObject = activity.object
|
||||
|
@ -18,15 +20,34 @@ export {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function processFollow (account: AccountInstance, targetAccountURL: string) {
|
||||
const targetAccount = await db.Account.loadByUrl(targetAccountURL)
|
||||
function processFollow (account: AccountInstance, targetAccountURL: string) {
|
||||
const options = {
|
||||
arguments: [ account, targetAccountURL ],
|
||||
errorMessage: 'Cannot follow with many retries.'
|
||||
}
|
||||
|
||||
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'
|
||||
})
|
||||
return retryTransactionWrapper(follow, options)
|
||||
}
|
||||
|
||||
async function follow (account: AccountInstance, targetAccountURL: string) {
|
||||
await db.sequelize.transaction(async t => {
|
||||
const targetAccount = await db.Account.loadByUrl(targetAccountURL, t)
|
||||
|
||||
if (targetAccount === undefined) throw new Error('Unknown account')
|
||||
if (targetAccount.isOwned() === false) throw new Error('This is not a local account.')
|
||||
|
||||
const sequelizeOptions = {
|
||||
transaction: t
|
||||
}
|
||||
await db.AccountFollow.create({
|
||||
accountId: account.id,
|
||||
targetAccountId: targetAccount.id,
|
||||
state: 'accepted'
|
||||
}, sequelizeOptions)
|
||||
|
||||
// Target sends to account he accepted the follow request
|
||||
return sendAccept(targetAccount, account, t)
|
||||
})
|
||||
|
||||
logger.info('Account uuid %s is followed by account %s.', account.url, targetAccountURL)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue