This commit is contained in:
tamaina 2023-04-22 14:37:11 +00:00
parent 5115ff1466
commit d2ea04fbf2
5 changed files with 24 additions and 14 deletions

View file

@ -70,14 +70,18 @@ export class AccountMoveService {
*/ */
@bindThis @bindThis
public async moveFromLocal(src: LocalUser, dst: LocalUser | RemoteUser): Promise<unknown> { public async moveFromLocal(src: LocalUser, dst: LocalUser | RemoteUser): Promise<unknown> {
const srcUri = this.userEntityService.getUserUri(src);
const dstUri = this.userEntityService.getUserUri(dst); const dstUri = this.userEntityService.getUserUri(dst);
// add movedToUri to indicate that the user has moved // add movedToUri to indicate that the user has moved
const update = {} as Partial<User>; const update = {} as Partial<LocalUser>;
update.alsoKnownAs = src.alsoKnownAs?.includes(dstUri) ? src.alsoKnownAs : src.alsoKnownAs?.concat([dstUri]) ?? [dstUri]; update.alsoKnownAs = src.alsoKnownAs?.includes(dstUri) ? src.alsoKnownAs : src.alsoKnownAs?.concat([dstUri]) ?? [dstUri];
update.movedToUri = dstUri; update.movedToUri = dstUri;
await this.usersRepository.update(src.id, update); 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 srcPerson = await this.apRendererService.renderPerson(src);
const updateAct = this.apRendererService.addContext(this.apRendererService.renderUpdate(srcPerson, src)); const updateAct = this.apRendererService.addContext(this.apRendererService.renderUpdate(srcPerson, src));
@ -101,14 +105,13 @@ export class AccountMoveService {
to: { id: following.followeeId }, to: { id: following.followeeId },
}))); })));
// Move! await this.postMoveProcess(src, dst);
await this.move(src, dst);
return iObj; return iObj;
} }
@bindThis @bindThis
public async move(src: User, dst: User): Promise<void> { public async postMoveProcess(src: User, dst: User): Promise<void> {
// Copy blockings and mutings, and update lists // Copy blockings and mutings, and update lists
try { try {
await Promise.all([ await Promise.all([

View file

@ -744,7 +744,7 @@ export class ApInboxService {
if (!targetUri) return 'skip: invalid activity target'; if (!targetUri) return 'skip: invalid activity target';
await Promise.all([ await Promise.all([
this.apPersonService.updatePerson(targetUri), 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([ const [newAccount, oldAccount] = await Promise.all([
this.apPersonService.resolvePerson(targetUri), this.apPersonService.resolvePerson(targetUri),
@ -774,7 +774,7 @@ export class ApInboxService {
} }
// Move! // Move!
await this.accountMoveService.move(oldAccount, newAccount); await this.accountMoveService.postMoveProcess(oldAccount, newAccount);
return 'ok'; return 'ok';
} }

View file

@ -84,9 +84,9 @@ export class InboxProcessorService {
// HTTP-Signature keyIdを元にDBから取得 // HTTP-Signature keyIdを元にDBから取得
let authUser: { let authUser: {
user: RemoteUser; user: RemoteUser;
key: UserPublickey | null; key: UserPublickey | null;
} | null = await this.apDbResolverService.getAuthUserFromKeyId(signature.keyId); } | null = await this.apDbResolverService.getAuthUserFromKeyId(signature.keyId);
// keyIdでわからなければ、activity.actorを元にDBから取得 || activity.actorを元にリモートから取得 // keyIdでわからなければ、activity.actorを元にDBから取得 || activity.actorを元にリモートから取得
if (authUser == null) { if (authUser == null) {

View file

@ -350,6 +350,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
//#endregion //#endregion
if (Object.keys(updates).length > 0) await this.usersRepository.update(user.id, updates); 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); if (Object.keys(profileUpdates).length > 0) await this.userProfilesRepository.update(user.id, profileUpdates);
const iObj = await this.userEntityService.pack<true, true>(user.id, user, { const iObj = await this.userEntityService.pack<true, true>(user.id, user, {

View file

@ -5,7 +5,7 @@ import rndstr from 'rndstr';
import { loadConfig } from '@/config.js'; import { loadConfig } from '@/config.js';
import { User, UsersRepository } from '@/models/index.js'; import { User, UsersRepository } from '@/models/index.js';
import { jobQueue } from '@/boot/common.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'; import type { INestApplicationContext } from '@nestjs/common';
describe('Account Move', () => { 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 () => { test('A locked account automatically accept the follow request if it had already accepted the old account.', async () => {
await api('/following/create', { await successfulApiCall({
userId: frank.id, endpoint: '/following/create',
}, bob); parameters: {
userId: frank.id,
},
user: bob,
});
const followers = await api('/users/followers', { const followers = await api('/users/followers', {
userId: frank.id, userId: frank.id,
}, frank); }, frank);