-
- // We process each host in a specific transaction
- // First, we add the follow request in the database
- // Then we send the follow request to other account
- const p = loadLocalOrGetAccountFromWebfinger(accountName, host)
- .then(accountResult => {
- let targetAccount = accountResult.account
-
- return db.sequelize.transaction(async t => {
- if (accountResult.loadedFromDB === false) {
- targetAccount = await targetAccount.save({ transaction: t })
- }
-
- const [ accountFollow ] = await db.AccountFollow.findOrCreate({
- where: {
- accountId: fromAccount.id,
- targetAccountId: targetAccount.id
- },
- defaults: {
- state: 'pending',
- accountId: fromAccount.id,
- targetAccountId: targetAccount.id
- },
- transaction: t
- })
-
- // Send a notification to remote server
- if (accountFollow.state === 'pending') {
- await sendFollow(fromAccount, targetAccount, t)
- }
- })
- })
- .catch(err => logger.warn('Cannot follow server %s.', `${accountName}@${host}`, err))
-
- tasks.push(p)
+ const payload = {
+ host,
+ name: SERVER_ACTOR_NAME,
+ followerActorId: follower.id
+ }
+
+ JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
+ .catch(err => logger.error('Cannot create follow job for %s.', host, err))