diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-06 17:19:53 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-06 17:26:51 +0200 |
commit | 6b9c966f6428c9e47bead3410a0401e8ebd744bf (patch) | |
tree | 282218ec56725b0e2e878b0471cd08a54fd91998 /server/models/video | |
parent | 466e3f20a537f1eff4b4fd03297df11ba371d049 (diff) | |
download | PeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.tar.gz PeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.tar.zst PeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.zip |
Automatically remove bad followings
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-comment.ts | 38 | ||||
-rw-r--r-- | server/models/video/video-share.ts | 18 |
2 files changed, 20 insertions, 36 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 28e5818cd..6eda32f05 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -22,7 +22,7 @@ import { AccountModel } from '../account/account' | |||
22 | import { ActorModel } from '../activitypub/actor' | 22 | import { ActorModel } from '../activitypub/actor' |
23 | import { AvatarModel } from '../avatar/avatar' | 23 | import { AvatarModel } from '../avatar/avatar' |
24 | import { ServerModel } from '../server/server' | 24 | import { ServerModel } from '../server/server' |
25 | import { buildBlockedAccountSQL, getSort, throwIfNotValid } from '../utils' | 25 | import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' |
26 | import { VideoModel } from './video' | 26 | import { VideoModel } from './video' |
27 | import { VideoChannelModel } from './video-channel' | 27 | import { VideoChannelModel } from './video-channel' |
28 | import { getServerActor } from '../../helpers/utils' | 28 | import { getServerActor } from '../../helpers/utils' |
@@ -30,7 +30,7 @@ import { UserModel } from '../account/user' | |||
30 | import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' | 30 | import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' |
31 | import { regexpCapture } from '../../helpers/regexp' | 31 | import { regexpCapture } from '../../helpers/regexp' |
32 | import { uniq } from 'lodash' | 32 | import { uniq } from 'lodash' |
33 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' | 33 | import { FindOptions, literal, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' |
34 | 34 | ||
35 | enum ScopeNames { | 35 | enum ScopeNames { |
36 | WITH_ACCOUNT = 'WITH_ACCOUNT', | 36 | WITH_ACCOUNT = 'WITH_ACCOUNT', |
@@ -281,16 +281,22 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
281 | return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query) | 281 | return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query) |
282 | } | 282 | } |
283 | 283 | ||
284 | static loadByUrlAndPopulateReplyAndVideo (url: string, t?: Transaction) { | 284 | static loadByUrlAndPopulateReplyAndVideoUrlAndAccount (url: string, t?: Transaction) { |
285 | const query: FindOptions = { | 285 | const query: FindOptions = { |
286 | where: { | 286 | where: { |
287 | url | 287 | url |
288 | } | 288 | }, |
289 | include: [ | ||
290 | { | ||
291 | attributes: [ 'id', 'url' ], | ||
292 | model: VideoModel.unscoped() | ||
293 | } | ||
294 | ] | ||
289 | } | 295 | } |
290 | 296 | ||
291 | if (t !== undefined) query.transaction = t | 297 | if (t !== undefined) query.transaction = t |
292 | 298 | ||
293 | return VideoCommentModel.scope([ ScopeNames.WITH_IN_REPLY_TO, ScopeNames.WITH_VIDEO ]).findOne(query) | 299 | return VideoCommentModel.scope([ ScopeNames.WITH_IN_REPLY_TO, ScopeNames.WITH_ACCOUNT ]).findOne(query) |
294 | } | 300 | } |
295 | 301 | ||
296 | static async listThreadsForApi (parameters: { | 302 | static async listThreadsForApi (parameters: { |
@@ -471,25 +477,11 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
471 | updatedAt: { | 477 | updatedAt: { |
472 | [Op.lt]: beforeUpdatedAt | 478 | [Op.lt]: beforeUpdatedAt |
473 | }, | 479 | }, |
474 | videoId | 480 | videoId, |
475 | }, | 481 | accountId: { |
476 | include: [ | 482 | [Op.notIn]: buildLocalAccountIdsIn() |
477 | { | ||
478 | required: true, | ||
479 | model: AccountModel.unscoped(), | ||
480 | include: [ | ||
481 | { | ||
482 | required: true, | ||
483 | model: ActorModel.unscoped(), | ||
484 | where: { | ||
485 | serverId: { | ||
486 | [Op.ne]: null | ||
487 | } | ||
488 | } | ||
489 | } | ||
490 | ] | ||
491 | } | 483 | } |
492 | ] | 484 | } |
493 | } | 485 | } |
494 | 486 | ||
495 | return VideoCommentModel.destroy(query) | 487 | return VideoCommentModel.destroy(query) |
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 3bab3c027..d8ed64557 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts | |||
@@ -4,7 +4,7 @@ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activityp | |||
4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
5 | import { AccountModel } from '../account/account' | 5 | import { AccountModel } from '../account/account' |
6 | import { ActorModel } from '../activitypub/actor' | 6 | import { ActorModel } from '../activitypub/actor' |
7 | import { throwIfNotValid } from '../utils' | 7 | import { buildLocalActorIdsIn, throwIfNotValid } from '../utils' |
8 | import { VideoModel } from './video' | 8 | import { VideoModel } from './video' |
9 | import { VideoChannelModel } from './video-channel' | 9 | import { VideoChannelModel } from './video-channel' |
10 | import { Op, Transaction } from 'sequelize' | 10 | import { Op, Transaction } from 'sequelize' |
@@ -207,19 +207,11 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
207 | updatedAt: { | 207 | updatedAt: { |
208 | [Op.lt]: beforeUpdatedAt | 208 | [Op.lt]: beforeUpdatedAt |
209 | }, | 209 | }, |
210 | videoId | 210 | videoId, |
211 | }, | 211 | actorId: { |
212 | include: [ | 212 | [Op.notIn]: buildLocalActorIdsIn() |
213 | { | ||
214 | model: ActorModel.unscoped(), | ||
215 | required: true, | ||
216 | where: { | ||
217 | serverId: { | ||
218 | [ Op.ne ]: null | ||
219 | } | ||
220 | } | ||
221 | } | 213 | } |
222 | ] | 214 | } |
223 | } | 215 | } |
224 | 216 | ||
225 | return VideoShareModel.destroy(query) | 217 | return VideoShareModel.destroy(query) |