make sure no dupes

This commit is contained in:
MathMan05 2025-04-30 22:54:13 -05:00
parent 7a93e5f9b5
commit a41cbe89ca
2 changed files with 16 additions and 3 deletions

View file

@ -530,7 +530,7 @@ class Channel extends SnowFlake {
}
return this.parent !== undefined;
}
calculateReorder() {
calculateReorder(numbset: Set<number>) {
let position = -1;
const build: {
id: string;
@ -544,9 +544,15 @@ class Channel extends SnowFlake {
parent_id: string | undefined;
} = {id: thing.id, position: undefined, parent_id: undefined};
if (thing.position < position) {
if (thing.position <= position) {
thing.position = thisthing.position = position + 1;
}
while (numbset.has(thing.position)) {
thing.position++;
thisthing.position = thing.position;
console.log(thing.position - 1);
}
numbset.add(thing.position);
position = thing.position;
if (thing.move_id && thing.move_id !== thing.parent_id) {
thing.parent_id = thing.move_id;

View file

@ -1163,6 +1163,7 @@ class Guild extends SnowFlake {
position: number | undefined;
parent_id: string | undefined | null;
}[] = [];
const numbset = new Set<number>();
for (const thing of this.headchannels) {
const thisthing: {
id: string;
@ -1172,6 +1173,12 @@ class Guild extends SnowFlake {
if (thing.position <= position) {
thing.position = thisthing.position = position + 1;
}
while (numbset.has(thing.position)) {
thing.position++;
thisthing.position = thing.position;
console.log(thing.position - 1);
}
numbset.add(thing.position);
position = thing.position;
console.log(position);
if (thing.move_id && thing.move_id !== thing.parent_id) {
@ -1183,7 +1190,7 @@ class Guild extends SnowFlake {
build.push(thisthing);
}
if (thing.children.length > 0) {
const things = thing.calculateReorder();
const things = thing.calculateReorder(numbset);
for (const thing of things) {
build.push(thing);
}