mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Add auto follow instances index support
This commit is contained in:
parent
8424c4026a
commit
6f1b4fa417
8 changed files with 234 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
|||
import * as Bluebird from 'bluebird'
|
||||
import { values } from 'lodash'
|
||||
import { values, difference } from 'lodash'
|
||||
import {
|
||||
AfterCreate,
|
||||
AfterDestroy,
|
||||
|
@ -21,7 +21,7 @@ import { FollowState } from '../../../shared/models/actors'
|
|||
import { ActorFollow } from '../../../shared/models/actors/follow.model'
|
||||
import { logger } from '../../helpers/logger'
|
||||
import { getServerActor } from '../../helpers/utils'
|
||||
import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES } from '../../initializers/constants'
|
||||
import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES, SERVER_ACTOR_NAME } from '../../initializers/constants'
|
||||
import { ServerModel } from '../server/server'
|
||||
import { createSafeIn, getSort } from '../utils'
|
||||
import { ActorModel, unusedActorAttributesForAPI } from './actor'
|
||||
|
@ -435,6 +435,45 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
|
|||
})
|
||||
}
|
||||
|
||||
static async keepUnfollowedInstance (hosts: string[]) {
|
||||
const followerId = (await getServerActor()).id
|
||||
|
||||
const query = {
|
||||
attributes: [],
|
||||
where: {
|
||||
actorId: followerId
|
||||
},
|
||||
include: [
|
||||
{
|
||||
attributes: [ ],
|
||||
model: ActorModel.unscoped(),
|
||||
required: true,
|
||||
as: 'ActorFollowing',
|
||||
where: {
|
||||
preferredUsername: SERVER_ACTOR_NAME
|
||||
},
|
||||
include: [
|
||||
{
|
||||
attributes: [ 'host' ],
|
||||
model: ServerModel.unscoped(),
|
||||
required: true,
|
||||
where: {
|
||||
host: {
|
||||
[Op.in]: hosts
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const res = await ActorFollowModel.findAll(query)
|
||||
const followedHosts = res.map(res => res.ActorFollowing.Server.host)
|
||||
|
||||
return difference(hosts, followedHosts)
|
||||
}
|
||||
|
||||
static listAcceptedFollowerUrlsForAP (actorIds: number[], t: Transaction, start?: number, count?: number) {
|
||||
return ActorFollowModel.createListAcceptedFollowForApiQuery('followers', actorIds, t, start, count)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue