Fix user subscription follows count
This commit is contained in:
parent
e89392d74a
commit
e1a570abff
|
@ -157,6 +157,7 @@
|
||||||
"htmlparser2",
|
"htmlparser2",
|
||||||
"markdown-it-emoji/light",
|
"markdown-it-emoji/light",
|
||||||
"linkifyjs/lib/linkify-html",
|
"linkifyjs/lib/linkify-html",
|
||||||
|
"linkifyjs/lib/plugins/mention",
|
||||||
"sanitize-html",
|
"sanitize-html",
|
||||||
"debug",
|
"debug",
|
||||||
"@peertube/p2p-media-loader-hlsjs",
|
"@peertube/p2p-media-loader-hlsjs",
|
||||||
|
|
|
@ -48,23 +48,15 @@ async function processFollow (byActor: MActorSignature, activityId: string, targ
|
||||||
return { actorFollow: undefined as MActorFollowActors }
|
return { actorFollow: undefined as MActorFollowActors }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't use findOrCreate by sequelize that breaks our actor follow hooks
|
const [ actorFollow, created ] = await ActorFollowModel.findOrCreateCustom({
|
||||||
let created = false
|
byActor,
|
||||||
let actorFollow: MActorFollowActors = await ActorFollowModel.loadByActorAndTarget(byActor.id, targetActor.id, t)
|
targetActor,
|
||||||
|
activityId,
|
||||||
if (!actorFollow) {
|
state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL
|
||||||
created = true
|
? 'pending'
|
||||||
|
: 'accepted',
|
||||||
actorFollow = await ActorFollowModel.create({
|
transaction: t
|
||||||
actorId: byActor.id,
|
})
|
||||||
targetActorId: targetActor.id,
|
|
||||||
url: 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
|
// Set the follow as accepted if the remote actor follows a channel or account
|
||||||
// Or if the instance automatically accepts followers
|
// 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 state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending'
|
||||||
|
|
||||||
const actorFollow = await sequelizeTypescript.transaction(async t => {
|
const actorFollow = await sequelizeTypescript.transaction(async t => {
|
||||||
const [ actorFollow ] = await ActorFollowModel.findOrCreate<MActorFollowActors>({
|
const [ actorFollow ] = await ActorFollowModel.findOrCreateCustom({
|
||||||
where: {
|
byActor: fromActor,
|
||||||
actorId: fromActor.id,
|
state,
|
||||||
targetActorId: targetActor.id
|
targetActor,
|
||||||
},
|
activityId: getLocalActorFollowActivityPubUrl(fromActor, targetActor),
|
||||||
defaults: {
|
|
||||||
state,
|
|
||||||
url: getLocalActorFollowActivityPubUrl(fromActor, targetActor),
|
|
||||||
actorId: fromActor.id,
|
|
||||||
targetActorId: targetActor.id
|
|
||||||
},
|
|
||||||
transaction: t
|
transaction: t
|
||||||
})
|
})
|
||||||
actorFollow.ActorFollowing = targetActor
|
|
||||||
actorFollow.ActorFollower = fromActor
|
|
||||||
|
|
||||||
// Send a notification to remote server if our follow is not already accepted
|
// Send a notification to remote server if our follow is not already accepted
|
||||||
if (actorFollow.state !== 'accepted') sendFollow(actorFollow, t)
|
if (actorFollow.state !== 'accepted') sendFollow(actorFollow, t)
|
||||||
|
|
|
@ -20,8 +20,11 @@ import {
|
||||||
} from 'sequelize-typescript'
|
} from 'sequelize-typescript'
|
||||||
import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
|
import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
|
||||||
import { afterCommitIfTransaction } from '@server/helpers/database-utils'
|
import { afterCommitIfTransaction } from '@server/helpers/database-utils'
|
||||||
|
import { CONFIG } from '@server/initializers/config'
|
||||||
import { getServerActor } from '@server/models/application/application'
|
import { getServerActor } from '@server/models/application/application'
|
||||||
import {
|
import {
|
||||||
|
MActor,
|
||||||
|
MActorFollowActors,
|
||||||
MActorFollowActorsDefault,
|
MActorFollowActorsDefault,
|
||||||
MActorFollowActorsDefaultSubscription,
|
MActorFollowActorsDefaultSubscription,
|
||||||
MActorFollowFollowingHost,
|
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) {
|
static removeFollowsOf (actorId: number, t?: Transaction) {
|
||||||
const query = {
|
const query = {
|
||||||
where: {
|
where: {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user