diff options
author | Chocobozzz <me@florianbigard.com> | 2021-10-14 10:52:15 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-10-14 10:52:15 +0200 |
commit | e1a570abff3ebf375433e58e7362d56bd32d4cd8 (patch) | |
tree | ba3c5e58698305c3b20ed1a14c79431d873dd329 /server/lib | |
parent | e89392d74aabddbee1c43dcb7e1b40d3d7eec1ed (diff) | |
download | PeerTube-e1a570abff3ebf375433e58e7362d56bd32d4cd8.tar.gz PeerTube-e1a570abff3ebf375433e58e7362d56bd32d4cd8.tar.zst PeerTube-e1a570abff3ebf375433e58e7362d56bd32d4cd8.zip |
Fix user subscription follows count
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/process/process-follow.ts | 26 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-follow.ts | 18 |
2 files changed, 14 insertions, 30 deletions
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index 5562f0798..e44590ffc 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts | |||
@@ -48,23 +48,15 @@ async function processFollow (byActor: MActorSignature, activityId: string, targ | |||
48 | return { actorFollow: undefined as MActorFollowActors } | 48 | return { actorFollow: undefined as MActorFollowActors } |
49 | } | 49 | } |
50 | 50 | ||
51 | // Don't use findOrCreate by sequelize that breaks our actor follow hooks | 51 | const [ actorFollow, created ] = await ActorFollowModel.findOrCreateCustom({ |
52 | let created = false | 52 | byActor, |
53 | let actorFollow: MActorFollowActors = await ActorFollowModel.loadByActorAndTarget(byActor.id, targetActor.id, t) | 53 | targetActor, |
54 | 54 | activityId, | |
55 | if (!actorFollow) { | 55 | state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL |
56 | created = true | 56 | ? 'pending' |
57 | 57 | : 'accepted', | |
58 | actorFollow = await ActorFollowModel.create({ | 58 | transaction: t |
59 | actorId: byActor.id, | 59 | }) |
60 | targetActorId: targetActor.id, | ||
61 | url: activityId, | ||
62 | |||
63 | state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL | ||
64 | ? 'pending' | ||
65 | : 'accepted' | ||
66 | }, { transaction: t }) | ||
67 | } | ||
68 | 60 | ||
69 | // Set the follow as accepted if the remote actor follows a channel or account | 61 | // Set the follow as accepted if the remote actor follows a channel or account |
70 | // Or if the instance automatically accepts followers | 62 | // Or if the instance automatically accepts followers |
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts index 91e3d33c6..55a15930a 100644 --- a/server/lib/job-queue/handlers/activitypub-follow.ts +++ b/server/lib/job-queue/handlers/activitypub-follow.ts | |||
@@ -54,21 +54,13 @@ async function follow (fromActor: MActor, targetActor: MActorFull, isAutoFollow | |||
54 | const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending' | 54 | const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending' |
55 | 55 | ||
56 | const actorFollow = await sequelizeTypescript.transaction(async t => { | 56 | const actorFollow = await sequelizeTypescript.transaction(async t => { |
57 | const [ actorFollow ] = await ActorFollowModel.findOrCreate<MActorFollowActors>({ | 57 | const [ actorFollow ] = await ActorFollowModel.findOrCreateCustom({ |
58 | where: { | 58 | byActor: fromActor, |
59 | actorId: fromActor.id, | 59 | state, |
60 | targetActorId: targetActor.id | 60 | targetActor, |
61 | }, | 61 | activityId: getLocalActorFollowActivityPubUrl(fromActor, targetActor), |
62 | defaults: { | ||
63 | state, | ||
64 | url: getLocalActorFollowActivityPubUrl(fromActor, targetActor), | ||
65 | actorId: fromActor.id, | ||
66 | targetActorId: targetActor.id | ||
67 | }, | ||
68 | transaction: t | 62 | transaction: t |
69 | }) | 63 | }) |
70 | actorFollow.ActorFollowing = targetActor | ||
71 | actorFollow.ActorFollower = fromActor | ||
72 | 64 | ||
73 | // Send a notification to remote server if our follow is not already accepted | 65 | // Send a notification to remote server if our follow is not already accepted |
74 | if (actorFollow.state !== 'accepted') sendFollow(actorFollow, t) | 66 | if (actorFollow.state !== 'accepted') sendFollow(actorFollow, t) |