skip adding to the list if it already has
This commit is contained in:
parent
9292cde76a
commit
2c35acbd2e
|
@ -186,6 +186,12 @@ export class AccountMoveService {
|
||||||
});
|
});
|
||||||
if (oldJoinings.length === 0) return;
|
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<string, { createdAt: Date; userId: string; userListId: string; }> = new Map();
|
const newJoinings: Map<string, { createdAt: Date; userId: string; userListId: string; }> = new Map();
|
||||||
|
|
||||||
// 重複しないようにIDを生成
|
// 重複しないようにIDを生成
|
||||||
|
@ -197,6 +203,7 @@ export class AccountMoveService {
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
for (const joining of oldJoinings) {
|
for (const joining of oldJoinings) {
|
||||||
|
if (existingUserListIds.includes(joining.userListId)) continue; // skip if dst exists in this user's list
|
||||||
newJoinings.set(genId(), {
|
newJoinings.set(genId(), {
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
userId: dst.id,
|
userId: dst.id,
|
||||||
|
|
|
@ -148,11 +148,11 @@ describe('Account Move', () => {
|
||||||
await api('/i/update', {
|
await api('/i/update', {
|
||||||
alsoKnownAs: [`@alice@${url.hostname}`],
|
alsoKnownAs: [`@alice@${url.hostname}`],
|
||||||
}, root);
|
}, root);
|
||||||
const list = await api('/users/lists/create', {
|
const listRoot = await api('/users/lists/create', {
|
||||||
name: rndstr('0-9a-z', 8),
|
name: rndstr('0-9a-z', 8),
|
||||||
}, root);
|
}, root);
|
||||||
await api('/users/lists/push', {
|
await api('/users/lists/push', {
|
||||||
listId: list.body.id,
|
listId: listRoot.body.id,
|
||||||
userId: alice.id,
|
userId: alice.id,
|
||||||
}, root);
|
}, root);
|
||||||
|
|
||||||
|
@ -196,6 +196,13 @@ describe('Account Move', () => {
|
||||||
await api('/following/create', {
|
await api('/following/create', {
|
||||||
userId: dave.id,
|
userId: dave.id,
|
||||||
}, eve);
|
}, 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', {
|
await api('/i/update', {
|
||||||
isLocked: true,
|
isLocked: true,
|
||||||
|
@ -266,11 +273,16 @@ describe('Account Move', () => {
|
||||||
assert.strictEqual(mutings.body.length, 1);
|
assert.strictEqual(mutings.body.length, 1);
|
||||||
assert.strictEqual(mutings.body[0].muteeId, bob.id);
|
assert.strictEqual(mutings.body[0].muteeId, bob.id);
|
||||||
|
|
||||||
const lists = await api('/users/lists/list', {}, root);
|
const rootLists = await api('/users/lists/list', {}, root);
|
||||||
assert.strictEqual(lists.status, 200);
|
assert.strictEqual(rootLists.status, 200);
|
||||||
assert.strictEqual(lists.body[0].userIds.length, 2);
|
assert.strictEqual(rootLists.body[0].userIds.length, 2);
|
||||||
assert.ok(lists.body[0].userIds.find((id: string) => id === bob.id));
|
assert.ok(rootLists.body[0].userIds.find((id: string) => id === bob.id));
|
||||||
assert.ok(lists.body[0].userIds.find((id: string) => id === alice.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 () => {
|
test('Unable to move if the destination account has already moved.', async () => {
|
||||||
|
|
Loading…
Reference in a new issue