diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/actor/actor-follow.ts | 40 | ||||
-rw-r--r-- | server/models/actor/actor.ts | 2 |
2 files changed, 26 insertions, 16 deletions
diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.ts index 8870bec05..566bb5f31 100644 --- a/server/models/actor/actor-follow.ts +++ b/server/models/actor/actor-follow.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { difference, values } from 'lodash' | 1 | import { difference, values } from 'lodash' |
2 | import { Includeable, IncludeOptions, Op, QueryTypes, Transaction } from 'sequelize' | 2 | import { Attributes, FindOptions, Includeable, IncludeOptions, Op, QueryTypes, Transaction, WhereAttributeHash } from 'sequelize' |
3 | import { | 3 | import { |
4 | AfterCreate, | 4 | AfterCreate, |
5 | AfterDestroy, | 5 | AfterDestroy, |
@@ -209,7 +209,9 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo | |||
209 | } | 209 | } |
210 | 210 | ||
211 | static isFollowedBy (actorId: number, followerActorId: number) { | 211 | static isFollowedBy (actorId: number, followerActorId: number) { |
212 | const query = 'SELECT 1 FROM "actorFollow" WHERE "actorId" = $followerActorId AND "targetActorId" = $actorId LIMIT 1' | 212 | const query = `SELECT 1 FROM "actorFollow" ` + |
213 | `WHERE "actorId" = $followerActorId AND "targetActorId" = $actorId AND "state" = 'accepted' ` + | ||
214 | `LIMIT 1` | ||
213 | 215 | ||
214 | return doesExist(query, { actorId, followerActorId }) | 216 | return doesExist(query, { actorId, followerActorId }) |
215 | } | 217 | } |
@@ -238,12 +240,15 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo | |||
238 | return ActorFollowModel.findOne(query) | 240 | return ActorFollowModel.findOne(query) |
239 | } | 241 | } |
240 | 242 | ||
241 | static loadByActorAndTargetNameAndHostForAPI ( | 243 | static loadByActorAndTargetNameAndHostForAPI (options: { |
242 | actorId: number, | 244 | actorId: number |
243 | targetName: string, | 245 | targetName: string |
244 | targetHost: string, | 246 | targetHost: string |
245 | t?: Transaction | 247 | state?: FollowState |
246 | ): Promise<MActorFollowActorsDefaultSubscription> { | 248 | transaction?: Transaction |
249 | }): Promise<MActorFollowActorsDefaultSubscription> { | ||
250 | const { actorId, targetHost, targetName, state, transaction } = options | ||
251 | |||
247 | const actorFollowingPartInclude: IncludeOptions = { | 252 | const actorFollowingPartInclude: IncludeOptions = { |
248 | model: ActorModel, | 253 | model: ActorModel, |
249 | required: true, | 254 | required: true, |
@@ -271,10 +276,11 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo | |||
271 | }) | 276 | }) |
272 | } | 277 | } |
273 | 278 | ||
274 | const query = { | 279 | const where: WhereAttributeHash<Attributes<ActorFollowModel>> = { actorId} |
275 | where: { | 280 | if (state) where.state = state |
276 | actorId | 281 | |
277 | }, | 282 | const query: FindOptions<Attributes<ActorFollowModel>> = { |
283 | where, | ||
278 | include: [ | 284 | include: [ |
279 | actorFollowingPartInclude, | 285 | actorFollowingPartInclude, |
280 | { | 286 | { |
@@ -283,7 +289,7 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo | |||
283 | as: 'ActorFollower' | 289 | as: 'ActorFollower' |
284 | } | 290 | } |
285 | ], | 291 | ], |
286 | transaction: t | 292 | transaction |
287 | } | 293 | } |
288 | 294 | ||
289 | return ActorFollowModel.findOne(query) | 295 | return ActorFollowModel.findOne(query) |
@@ -325,6 +331,7 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo | |||
325 | [Op.or]: whereTab | 331 | [Op.or]: whereTab |
326 | }, | 332 | }, |
327 | { | 333 | { |
334 | state: 'accepted', | ||
328 | actorId | 335 | actorId |
329 | } | 336 | } |
330 | ] | 337 | ] |
@@ -372,6 +379,7 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo | |||
372 | }) { | 379 | }) { |
373 | const { actorId, start, count, sort } = options | 380 | const { actorId, start, count, sort } = options |
374 | const where = { | 381 | const where = { |
382 | state: 'accepted', | ||
375 | actorId | 383 | actorId |
376 | } | 384 | } |
377 | 385 | ||
@@ -512,13 +520,15 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo | |||
512 | 520 | ||
513 | const totalInstanceFollowing = await ActorFollowModel.count({ | 521 | const totalInstanceFollowing = await ActorFollowModel.count({ |
514 | where: { | 522 | where: { |
515 | actorId: serverActor.id | 523 | actorId: serverActor.id, |
524 | state: 'accepted' | ||
516 | } | 525 | } |
517 | }) | 526 | }) |
518 | 527 | ||
519 | const totalInstanceFollowers = await ActorFollowModel.count({ | 528 | const totalInstanceFollowers = await ActorFollowModel.count({ |
520 | where: { | 529 | where: { |
521 | targetActorId: serverActor.id | 530 | targetActorId: serverActor.id, |
531 | state: 'accepted' | ||
522 | } | 532 | } |
523 | }) | 533 | }) |
524 | 534 | ||
diff --git a/server/models/actor/actor.ts b/server/models/actor/actor.ts index 943b7364f..7be5a140c 100644 --- a/server/models/actor/actor.ts +++ b/server/models/actor/actor.ts | |||
@@ -462,7 +462,7 @@ export class ActorModel extends Model<Partial<AttributesOnly<ActorModel>>> { | |||
462 | } | 462 | } |
463 | 463 | ||
464 | return ActorModel.update({ | 464 | return ActorModel.update({ |
465 | [columnToUpdate]: literal(`(SELECT COUNT(*) FROM "actorFollow" WHERE "${columnOfCount}" = ${sanitizedOfId})`) | 465 | [columnToUpdate]: literal(`(SELECT COUNT(*) FROM "actorFollow" WHERE "${columnOfCount}" = ${sanitizedOfId} AND "state" = 'accepted')`) |
466 | }, { where, transaction }) | 466 | }, { where, transaction }) |
467 | } | 467 | } |
468 | 468 | ||