diff --git a/packages/backend/src/core/UserFollowingService.ts b/packages/backend/src/core/UserFollowingService.ts index 2f52d91b4d..8b5d9fdb1b 100644 --- a/packages/backend/src/core/UserFollowingService.ts +++ b/packages/backend/src/core/UserFollowingService.ts @@ -143,16 +143,32 @@ export class UserFollowingService implements OnModuleInit { // Automatically accept if the follower is an account who has moved and the locked followee had accepted the old account. if (followee.isLocked && !autoAccept) { let movedFollower = follower; + if (this.userEntityService.isRemoteUser(movedFollower)) { - await this.apPersonService.updatePerson(movedFollower.uri); - movedFollower = await this.apPersonService.resolvePerson(movedFollower.uri); + if ((new Date()).getTime() - (movedFollower.lastFetchedAt?.getTime() ?? 0) > 10 * 1000) { + await this.apPersonService.updatePerson(movedFollower.uri); + } + movedFollower = await this.apPersonService.fetchPerson(movedFollower.uri) ?? follower; } + if (movedFollower.alsoKnownAs) { for (const oldUri of movedFollower.alsoKnownAs) { try { - await this.apPersonService.updatePerson(oldUri); - const oldAccount = await this.apPersonService.resolvePerson(oldUri); - const newUri = this.userEntityService.isRemoteUser(movedFollower) ? movedFollower.uri : `${this.config.url}/users/${movedFollower.id}`; + let oldAccount = await this.apPersonService.fetchPerson(oldUri); + if (!oldAccount) continue; // oldAccountを探してもこのサーバーに存在しない場合はフォロー関係もないということなのでスルー + + let newUri: string; + + if (this.userEntityService.isRemoteUser(movedFollower)) { + if ((new Date()).getTime() - (oldAccount.lastFetchedAt?.getTime() ?? 0) > 10 * 1000) { + await this.apPersonService.updatePerson(oldUri); + } + + oldAccount = await this.apPersonService.fetchPerson(oldUri) ?? oldAccount; + newUri = movedFollower.uri; + } else { + newUri = `${this.config.url}/users/${movedFollower.id}`; + } autoAccept = oldAccount.movedToUri === newUri && await this.followingsRepository.exist({ where: { diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 7e5a03b103..515fafb2a0 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -205,12 +205,12 @@ export class ApPersonService implements OnModuleInit { } /** - * Personをフェッチします。 + * uriからUser(Person)をフェッチします。 * - * Misskeyに対象のPersonが登録されていればそれを返します。 + * Misskeyに対象のPersonが登録されていればそれを返し、登録がなければnullを返します。 */ @bindThis - public async fetchPerson(uri: string, resolver?: Resolver): Promise { + public async fetchPerson(uri: string): Promise { if (typeof uri !== 'string') throw new Error('uri is not string'); const cached = this.cacheService.uriPersonCache.get(uri);