diff --git a/packages/backend/src/core/AccountMoveService.ts b/packages/backend/src/core/AccountMoveService.ts index 381e3f3435..77757e0f20 100644 --- a/packages/backend/src/core/AccountMoveService.ts +++ b/packages/backend/src/core/AccountMoveService.ts @@ -70,14 +70,18 @@ export class AccountMoveService { */ @bindThis public async moveFromLocal(src: LocalUser, dst: LocalUser | RemoteUser): Promise { + const srcUri = this.userEntityService.getUserUri(src); const dstUri = this.userEntityService.getUserUri(dst); // add movedToUri to indicate that the user has moved - const update = {} as Partial; + const update = {} as Partial; update.alsoKnownAs = src.alsoKnownAs?.includes(dstUri) ? src.alsoKnownAs : src.alsoKnownAs?.concat([dstUri]) ?? [dstUri]; update.movedToUri = dstUri; await this.usersRepository.update(src.id, update); - src = Object.assign(src, update); + Object.assign(src, update); + + // Update cache + this.cacheService.uriPersonCache.set(srcUri, src); const srcPerson = await this.apRendererService.renderPerson(src); const updateAct = this.apRendererService.addContext(this.apRendererService.renderUpdate(srcPerson, src)); @@ -101,14 +105,13 @@ export class AccountMoveService { to: { id: following.followeeId }, }))); - // Move! - await this.move(src, dst); + await this.postMoveProcess(src, dst); return iObj; } @bindThis - public async move(src: User, dst: User): Promise { + public async postMoveProcess(src: User, dst: User): Promise { // Copy blockings and mutings, and update lists try { await Promise.all([ diff --git a/packages/backend/src/core/activitypub/ApInboxService.ts b/packages/backend/src/core/activitypub/ApInboxService.ts index e98e7a3d8f..d3925aeaf6 100644 --- a/packages/backend/src/core/activitypub/ApInboxService.ts +++ b/packages/backend/src/core/activitypub/ApInboxService.ts @@ -744,7 +744,7 @@ export class ApInboxService { if (!targetUri) return 'skip: invalid activity target'; await Promise.all([ this.apPersonService.updatePerson(targetUri), - this.apPersonService.updatePerson(actor.uri), + this.apPersonService.updatePerson(actor.uri), // actor may cached for a day or more ]); const [newAccount, oldAccount] = await Promise.all([ this.apPersonService.resolvePerson(targetUri), @@ -774,7 +774,7 @@ export class ApInboxService { } // Move! - await this.accountMoveService.move(oldAccount, newAccount); + await this.accountMoveService.postMoveProcess(oldAccount, newAccount); return 'ok'; } diff --git a/packages/backend/src/queue/processors/InboxProcessorService.ts b/packages/backend/src/queue/processors/InboxProcessorService.ts index ada6f9e967..ab8b1e9e22 100644 --- a/packages/backend/src/queue/processors/InboxProcessorService.ts +++ b/packages/backend/src/queue/processors/InboxProcessorService.ts @@ -84,9 +84,9 @@ export class InboxProcessorService { // HTTP-Signature keyIdを元にDBから取得 let authUser: { - user: RemoteUser; - key: UserPublickey | null; - } | null = await this.apDbResolverService.getAuthUserFromKeyId(signature.keyId); + user: RemoteUser; + key: UserPublickey | null; + } | null = await this.apDbResolverService.getAuthUserFromKeyId(signature.keyId); // keyIdでわからなければ、activity.actorを元にDBから取得 || activity.actorを元にリモートから取得 if (authUser == null) { diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index c32618475c..738edf3978 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -350,6 +350,9 @@ export default class extends Endpoint { //#endregion if (Object.keys(updates).length > 0) await this.usersRepository.update(user.id, updates); + if (Object.keys(updates).includes('alsoKnownAs')) { + this.cacheService.uriPersonCache.set(this.userEntityService.genLocalUserUri(user.id), { ...user, ...updates }); + } if (Object.keys(profileUpdates).length > 0) await this.userProfilesRepository.update(user.id, profileUpdates); const iObj = await this.userEntityService.pack(user.id, user, { diff --git a/packages/backend/test/e2e/move.ts b/packages/backend/test/e2e/move.ts index d589654dcd..657934ba42 100644 --- a/packages/backend/test/e2e/move.ts +++ b/packages/backend/test/e2e/move.ts @@ -5,7 +5,7 @@ import rndstr from 'rndstr'; import { loadConfig } from '@/config.js'; import { User, UsersRepository } from '@/models/index.js'; import { jobQueue } from '@/boot/common.js'; -import { uploadFile, signup, startServer, initTestDb, api, sleep } from '../utils.js'; +import { uploadFile, signup, startServer, initTestDb, api, sleep, successfulApiCall } from '../utils.js'; import type { INestApplicationContext } from '@nestjs/common'; describe('Account Move', () => { @@ -346,9 +346,13 @@ describe('Account Move', () => { }); test('A locked account automatically accept the follow request if it had already accepted the old account.', async () => { - await api('/following/create', { - userId: frank.id, - }, bob); + await successfulApiCall({ + endpoint: '/following/create', + parameters: { + userId: frank.id, + }, + user: bob, + }); const followers = await api('/users/followers', { userId: frank.id, }, frank);