From 71a2fbd232bb36394d9c0804eccfd6a29134b7d7 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Thu, 13 Apr 2023 11:46:32 -0400 Subject: [PATCH] automatically accept if a locked account had accepted an old account --- .../backend/src/core/UserFollowingService.ts | 20 +++++++++++++++++++ .../activitypub/models/ApPersonService.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/UserFollowingService.ts b/packages/backend/src/core/UserFollowingService.ts index a8eded6733..f32048bf38 100644 --- a/packages/backend/src/core/UserFollowingService.ts +++ b/packages/backend/src/core/UserFollowingService.ts @@ -22,6 +22,7 @@ import { MetaService } from '@/core/MetaService.js'; import { CacheService } from '@/core/CacheService.js'; import type { Config } from '@/config.js'; import Logger from '../logger.js'; +import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js'; const logger = new Logger('following/create'); @@ -73,6 +74,7 @@ export class UserFollowingService implements OnModuleInit { private federatedInstanceService: FederatedInstanceService, private webhookService: WebhookService, private apRendererService: ApRendererService, + private apPersonService: ApPersonService, private perUserFollowingChart: PerUserFollowingChart, private instanceChart: InstanceChart, ) { @@ -137,6 +139,24 @@ export class UserFollowingService implements OnModuleInit { if (followed) autoAccept = true; } + // Automatically accept if the follower is an account who has moved and the locked followee had accepted the old account. + if (followee.isLocked && !autoAccept && follower.alsoKnownAs) { + for (const oldUri of follower.alsoKnownAs) { + try { + await this.apPersonService.updatePerson(oldUri); + const oldAccount = await this.apPersonService.resolvePerson(oldUri); + autoAccept = await this.followingsRepository.exist({ + where: { + followeeId: followee.id, + followerId: oldAccount.id, + }, + }); + } catch { + /* skip if any error happens */ + } + } + } + if (!autoAccept) { await this.createFollowRequest(follower, followee, requestId); return; diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 819e8b9bf5..21a53ea85f 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -217,7 +217,7 @@ export class ApPersonService implements OnModuleInit { if (cached) return cached; // URIがこのサーバーを指しているならデータベースからフェッチ - if (uri.startsWith(this.config.url + '/')) { + if (uri.startsWith(`${this.config.url}/`)) { const id = uri.split('/').pop(); const u = await this.usersRepository.findOneBy({ id }); if (u) this.cacheService.uriPersonCache.set(uri, u);