mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-26 17:00:19 +01:00
skip adding to the list if it already has
This commit is contained in:
parent
9292cde76a
commit
2c35acbd2e
2 changed files with 26 additions and 7 deletions
|
@ -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<string, { createdAt: Date; userId: string; userListId: string; }> = 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,
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
Loading…
Reference in a new issue