aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-14 10:52:15 +0200
committerChocobozzz <me@florianbigard.com>2021-10-14 10:52:15 +0200
commite1a570abff3ebf375433e58e7362d56bd32d4cd8 (patch)
treeba3c5e58698305c3b20ed1a14c79431d873dd329
parente89392d74aabddbee1c43dcb7e1b40d3d7eec1ed (diff)
downloadPeerTube-e1a570abff3ebf375433e58e7362d56bd32d4cd8.tar.gz
PeerTube-e1a570abff3ebf375433e58e7362d56bd32d4cd8.tar.zst
PeerTube-e1a570abff3ebf375433e58e7362d56bd32d4cd8.zip
Fix user subscription follows count
-rw-r--r--client/angular.json1
-rw-r--r--server/lib/activitypub/process/process-follow.ts26
-rw-r--r--server/lib/job-queue/handlers/activitypub-follow.ts18
-rw-r--r--server/models/actor/actor-follow.ts41
4 files changed, 56 insertions, 30 deletions
diff --git a/client/angular.json b/client/angular.json
index 1dd745f09..13be6e555 100644
--- a/client/angular.json
+++ b/client/angular.json
@@ -157,6 +157,7 @@
157 "htmlparser2", 157 "htmlparser2",
158 "markdown-it-emoji/light", 158 "markdown-it-emoji/light",
159 "linkifyjs/lib/linkify-html", 159 "linkifyjs/lib/linkify-html",
160 "linkifyjs/lib/plugins/mention",
160 "sanitize-html", 161 "sanitize-html",
161 "debug", 162 "debug",
162 "@peertube/p2p-media-loader-hlsjs", 163 "@peertube/p2p-media-loader-hlsjs",
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)
diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.ts
index 95bb2df56..c522a7c05 100644
--- a/server/models/actor/actor-follow.ts
+++ b/server/models/actor/actor-follow.ts
@@ -20,8 +20,11 @@ import {
20} from 'sequelize-typescript' 20} from 'sequelize-typescript'
21import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' 21import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
22import { afterCommitIfTransaction } from '@server/helpers/database-utils' 22import { afterCommitIfTransaction } from '@server/helpers/database-utils'
23import { CONFIG } from '@server/initializers/config'
23import { getServerActor } from '@server/models/application/application' 24import { getServerActor } from '@server/models/application/application'
24import { 25import {
26 MActor,
27 MActorFollowActors,
25 MActorFollowActorsDefault, 28 MActorFollowActorsDefault,
26 MActorFollowActorsDefaultSubscription, 29 MActorFollowActorsDefaultSubscription,
27 MActorFollowFollowingHost, 30 MActorFollowFollowingHost,
@@ -137,6 +140,44 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo
137 }) 140 })
138 } 141 }
139 142
143 /*
144 * @deprecated Use `findOrCreateCustom` instead
145 */
146 static findOrCreate (): any {
147 throw new Error('Should not be called')
148 }
149
150 // findOrCreate has issues with actor follow hooks
151 static async findOrCreateCustom (options: {
152 byActor: MActor
153 targetActor: MActor
154 activityId: string
155 state: FollowState
156 transaction: Transaction
157 }): Promise<[ MActorFollowActors, boolean ]> {
158 const { byActor, targetActor, activityId, state, transaction } = options
159
160 let created = false
161 let actorFollow: MActorFollowActors = await ActorFollowModel.loadByActorAndTarget(byActor.id, targetActor.id, transaction)
162
163 if (!actorFollow) {
164 created = true
165
166 actorFollow = await ActorFollowModel.create({
167 actorId: byActor.id,
168 targetActorId: targetActor.id,
169 url: activityId,
170
171 state
172 }, { transaction })
173
174 actorFollow.ActorFollowing = targetActor
175 actorFollow.ActorFollower = byActor
176 }
177
178 return [ actorFollow, created ]
179 }
180
140 static removeFollowsOf (actorId: number, t?: Transaction) { 181 static removeFollowsOf (actorId: number, t?: Transaction) {
141 const query = { 182 const query = {
142 where: { 183 where: {