From 2c35acbd2ecc50e5732b03c115243c94dd6e0b72 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Fri, 21 Apr 2023 05:26:14 -0400 Subject: [PATCH] skip adding to the list if it already has --- .../backend/src/core/AccountMoveService.ts | 7 +++++ packages/backend/test/e2e/move.ts | 26 ++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/AccountMoveService.ts b/packages/backend/src/core/AccountMoveService.ts index aace2d2bd7..e2b38a396f 100644 --- a/packages/backend/src/core/AccountMoveService.ts +++ b/packages/backend/src/core/AccountMoveService.ts @@ -186,6 +186,12 @@ export class AccountMoveService { }); if (oldJoinings.length === 0) return; + const existingUserListIds = await this.userListJoiningsRepository.find({ + where: { + userId: dst.id, + }, + }).then(joinings => joinings.map(joining => joining.userListId)); + const newJoinings: Map = new Map(); // 重複しないようにIDを生成 @@ -197,6 +203,7 @@ export class AccountMoveService { return id; }; for (const joining of oldJoinings) { + if (existingUserListIds.includes(joining.userListId)) continue; // skip if dst exists in this user's list newJoinings.set(genId(), { createdAt: new Date(), userId: dst.id, diff --git a/packages/backend/test/e2e/move.ts b/packages/backend/test/e2e/move.ts index 1d9fb07ee5..5c6e5937a1 100644 --- a/packages/backend/test/e2e/move.ts +++ b/packages/backend/test/e2e/move.ts @@ -148,11 +148,11 @@ describe('Account Move', () => { await api('/i/update', { alsoKnownAs: [`@alice@${url.hostname}`], }, root); - const list = await api('/users/lists/create', { + const listRoot = await api('/users/lists/create', { name: rndstr('0-9a-z', 8), }, root); await api('/users/lists/push', { - listId: list.body.id, + listId: listRoot.body.id, userId: alice.id, }, root); @@ -196,6 +196,13 @@ describe('Account Move', () => { await api('/following/create', { userId: dave.id, }, eve); + const listEve = await api('/users/lists/create', { + name: rndstr('0-9a-z', 8), + }, eve); + await api('/users/lists/push', { + listId: listEve.body.id, + userId: bob.id, + }, eve); await api('/i/update', { isLocked: true, @@ -266,11 +273,16 @@ describe('Account Move', () => { assert.strictEqual(mutings.body.length, 1); assert.strictEqual(mutings.body[0].muteeId, bob.id); - const lists = await api('/users/lists/list', {}, root); - assert.strictEqual(lists.status, 200); - assert.strictEqual(lists.body[0].userIds.length, 2); - assert.ok(lists.body[0].userIds.find((id: string) => id === bob.id)); - assert.ok(lists.body[0].userIds.find((id: string) => id === alice.id)); + const rootLists = await api('/users/lists/list', {}, root); + assert.strictEqual(rootLists.status, 200); + assert.strictEqual(rootLists.body[0].userIds.length, 2); + assert.ok(rootLists.body[0].userIds.find((id: string) => id === bob.id)); + assert.ok(rootLists.body[0].userIds.find((id: string) => id === alice.id)); + + const eveLists = await api('/users/lists/list', {}, eve); + assert.strictEqual(eveLists.status, 200); + assert.strictEqual(eveLists.body[0].userIds.length, 1); + assert.ok(eveLists.body[0].userIds.find((id: string) => id === bob.id)); }); test('Unable to move if the destination account has already moved.', async () => {