From 51a867473bfa9a6e2cf61a8be5f5bb7a435080e5 Mon Sep 17 00:00:00 2001 From: tamaina Date: Thu, 20 Apr 2023 20:50:19 +0000 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E8=A1=8C=E3=82=92=E8=A1=8C=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3=E3=83=88=E3=81=8B?= =?UTF-8?q?=E3=82=89=E3=81=AE=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC=E3=83=AA?= =?UTF-8?q?=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E3=81=AE=E8=87=AA=E5=8B=95?= =?UTF-8?q?=E8=A8=B1=E5=8F=AF=E3=82=92=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/src/core/UserFollowingService.ts | 26 +++++++++++++++---- .../activitypub/models/ApPersonService.ts | 6 ++--- 2 files changed, 24 insertions(+), 8 deletions(-) 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);