ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix user subscription follows count
Chocobozzze1a570abff3e
diff --git a/client/angular.json b/client/angular.jsonindex 1dd745f097..13be6e5558 100644--- a/client/angular.json+++ b/client/angular.json@@ -157,6 +157,7 @@"htmlparser2","markdown-it-emoji/light","linkifyjs/lib/linkify-html",+ "linkifyjs/lib/plugins/mention","sanitize-html","debug","@peertube/p2p-media-loader-hlsjs",diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.tsindex 5562f07989..e44590ffc5 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, targreturn { actorFollow: undefined as MActorFollowActors }}- // Don't use findOrCreate by sequelize that breaks our actor follow hooks- let created = false- let actorFollow: MActorFollowActors = await ActorFollowModel.loadByActorAndTarget(byActor.id, targetActor.id, t)-- if (!actorFollow) {- created = true-- actorFollow = await ActorFollowModel.create({- actorId: byActor.id,- targetActorId: targetActor.id,- url: activityId,-- state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL- ? 'pending'- : 'accepted'- }, { transaction: t })- }+ const [ actorFollow, created ] = await ActorFollowModel.findOrCreateCustom({+ byActor,+ targetActor,+ activityId,+ state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL+ ? 'pending'+ : 'accepted',+ transaction: t+ })// Set the follow as accepted if the remote actor follows a channel or account// Or if the instance automatically accepts followersdiff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.tsindex 91e3d33c60..55a15930af 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, isAutoFollowconst state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending'const actorFollow = await sequelizeTypescript.transaction(async t => {- const [ actorFollow ] = await ActorFollowModel.findOrCreate<MActorFollowActors>({- where: {- actorId: fromActor.id,- targetActorId: targetActor.id- },- defaults: {- state,- url: getLocalActorFollowActivityPubUrl(fromActor, targetActor),- actorId: fromActor.id,- targetActorId: targetActor.id- },+ const [ actorFollow ] = await ActorFollowModel.findOrCreateCustom({+ byActor: fromActor,+ state,+ targetActor,+ activityId: getLocalActorFollowActivityPubUrl(fromActor, targetActor),transaction: t})- actorFollow.ActorFollowing = targetActor- actorFollow.ActorFollower = fromActor// Send a notification to remote server if our follow is not already acceptedif (actorFollow.state !== 'accepted') sendFollow(actorFollow, t)diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.tsindex 95bb2df566..c522a7c054 100644--- a/server/models/actor/actor-follow.ts+++ b/server/models/actor/actor-follow.ts@@ -20,8 +20,11 @@ import {} from 'sequelize-typescript'import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc'import { afterCommitIfTransaction } from '@server/helpers/database-utils'+import { CONFIG } from '@server/initializers/config'import { getServerActor } from '@server/models/application/application'import {+ MActor,+ MActorFollowActors,MActorFollowActorsDefault,MActorFollowActorsDefaultSubscription,MActorFollowFollowingHost,@@ -137,6 +140,44 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo})}+ /*+ * @deprecated Use `findOrCreateCustom` instead+ */+ static findOrCreate (): any {+ throw new Error('Should not be called')+ }++ // findOrCreate has issues with actor follow hooks+ static async findOrCreateCustom (options: {+ byActor: MActor+ targetActor: MActor+ activityId: string+ state: FollowState+ transaction: Transaction+ }): Promise<[ MActorFollowActors, boolean ]> {+ const { byActor, targetActor, activityId, state, transaction } = options++ let created = false+ let actorFollow: MActorFollowActors = await ActorFollowModel.loadByActorAndTarget(byActor.id, targetActor.id, transaction)++ if (!actorFollow) {+ created = true++ actorFollow = await ActorFollowModel.create({+ actorId: byActor.id,+ targetActorId: targetActor.id,+ url: activityId,++ state+ }, { transaction })++ actorFollow.ActorFollowing = targetActor+ actorFollow.ActorFollower = byActor+ }++ return [ actorFollow, created ]+ }+static removeFollowsOf (actorId: number, t?: Transaction) {const query = {where: {