X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Ffollow.ts;h=f6e2a48fdec3e889bb04a9c72d832fbb110eef35;hb=f50bff17f5b69c576960360857e25224cea13c0a;hp=a1c95504e3d7d6af694598bc5b8c8b306592d99a;hpb=c2777c1dfe688c8fab1ef2fed50e360100fa9198;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/follow.ts b/server/lib/activitypub/follow.ts index a1c95504e..f6e2a48fd 100644 --- a/server/lib/activitypub/follow.ts +++ b/server/lib/activitypub/follow.ts @@ -1,12 +1,13 @@ -import { MActorFollowActors } from '../../typings/models' +import { Transaction } from 'sequelize' +import { getServerActor } from '@server/models/application/application' +import { logger } from '../../helpers/logger' import { CONFIG } from '../../initializers/config' import { SERVER_ACTOR_NAME } from '../../initializers/constants' -import { JobQueue } from '../job-queue' -import { logger } from '../../helpers/logger' -import { getServerActor } from '../../helpers/utils' import { ServerModel } from '../../models/server/server' +import { MActorFollowActors } from '../../types/models' +import { JobQueue } from '../job-queue' -async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) { +async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors, transaction?: Transaction) { if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return const follower = actorFollow.ActorFollower @@ -16,7 +17,7 @@ async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) { const me = await getServerActor() - const server = await ServerModel.load(follower.serverId) + const server = await ServerModel.load(follower.serverId, transaction) const host = server.host const payload = { @@ -26,10 +27,25 @@ async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) { isAutoFollow: true } - JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) + JobQueue.Instance.createJobAsync({ type: 'activitypub-follow', payload }) } } +// If we only have an host, use a default account handle +function getRemoteNameAndHost (handleOrHost: string) { + let name = SERVER_ACTOR_NAME + let host = handleOrHost + + const splitted = handleOrHost.split('@') + if (splitted.length === 2) { + name = splitted[0] + host = splitted[1] + } + + return { name, host } +} + export { - autoFollowBackIfNeeded + autoFollowBackIfNeeded, + getRemoteNameAndHost }