-async function follow (fromAccount: AccountModel, targetAccount: AccountModel, targetAlreadyInDB: boolean) {
- try {
- await sequelizeTypescript.transaction(async t => {
- if (targetAlreadyInDB === false) {
- await saveAccountAndServerIfNotExist(targetAccount, t)
- }
-
- const [ accountFollow ] = await AccountFollowModel.findOrCreate({
- where: {
- accountId: fromAccount.id,
- targetAccountId: targetAccount.id
- },
- defaults: {
- state: 'pending',
- accountId: fromAccount.id,
- targetAccountId: targetAccount.id
- },
- transaction: t
- })
- accountFollow.AccountFollowing = targetAccount
- accountFollow.AccountFollower = fromAccount
-
- // Send a notification to remote server
- if (accountFollow.state === 'pending') {
- await sendFollow(accountFollow, t)
- }
+function follow (fromActor: ActorModel, targetActor: ActorModel) {
+ return sequelizeTypescript.transaction(async t => {
+ const [ actorFollow ] = await ActorFollowModel.findOrCreate({
+ where: {
+ actorId: fromActor.id,
+ targetActorId: targetActor.id
+ },
+ defaults: {
+ state: 'pending',
+ actorId: fromActor.id,
+ targetActorId: targetActor.id
+ },
+ transaction: t