Fix user subscription follows count
This commit is contained in:
parent
e89392d74a
commit
e1a570abff
|
@ -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",
|
||||
|
|
|
@ -48,23 +48,15 @@ async function processFollow (byActor: MActorSignature, activityId: string, targ
|
|||
return { 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 followers
|
||||
|
|
|
@ -54,21 +54,13 @@ async function follow (fromActor: MActor, targetActor: MActorFull, isAutoFollow
|
|||
const 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 accepted
|
||||
if (actorFollow.state !== 'accepted') sendFollow(actorFollow, t)
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Reference in New Issue