From e79e4affb4a7f9670c6e60e5ac51b346e53595a9 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Mon, 2 Sep 2024 16:55:27 -0500 Subject: [PATCH] fixing bugs for re-order --- .dist/channel.js | 17 ++++++++++++----- .dist/guild.js | 31 ++++++++++++++++++------------- .dist/localuser.js | 9 ++++++--- webpage/channel.ts | 19 +++++++++++++------ webpage/guild.ts | 33 +++++++++++++++++++-------------- webpage/localuser.ts | 9 ++++++--- 6 files changed, 74 insertions(+), 44 deletions(-) diff --git a/.dist/channel.js b/.dist/channel.js index 446c721..5a0427b 100644 --- a/.dist/channel.js +++ b/.dist/channel.js @@ -321,16 +321,16 @@ class Channel { let position = -1; const build = []; for (const thing of this.children) { - const thisthing = { id: thing.snowflake, position: undefined, parent_id: undefined }; + const thisthing = { id: thing.id, position: undefined, parent_id: undefined }; if (thing.position < position) { thing.position = thisthing.position = position + 1; } position = thing.position; if (thing.move_id && thing.move_id !== thing.parent_id) { thing.parent_id = thing.move_id; - thisthing.parent_id = thing.parent_id; + thisthing.parent_id = thing.parent?.id; thing.move_id = null; - console.log(this.guild.channelids[thisthing.parent_id.id]); + //console.log(this.guild.channelids[thisthing.parent_id.id]); } if (thisthing.position || thisthing.parent_id) { build.push(thisthing); @@ -929,8 +929,15 @@ class Channel { updateChannel(json) { this.type = json.type; this.name = json.name; - this.parent_id = SnowFlake.getSnowFlakeFromID(json.parent_id, Channel); - this.parent = null; + const parent = this.guild.channelids[json.parent_id]; + if (parent) { + this.parent = parent; + this.parent_id = parent.snowflake; + } + else { + this.parent = null; + this.parent_id = null; + } this.children = []; this.guild_id = json.guild_id; this.messageids = new Map(); diff --git a/.dist/guild.js b/.dist/guild.js index 19f744b..d759c32 100644 --- a/.dist/guild.js +++ b/.dist/guild.js @@ -204,7 +204,7 @@ class Guild { let position = -1; const build = []; for (const thing of this.headchannels) { - const thisthing = { id: thing.snowflake, position: undefined, parent_id: undefined }; + const thisthing = { id: thing.id, position: undefined, parent_id: undefined }; if (thing.position <= position) { thing.position = (thisthing.position = position + 1); } @@ -212,7 +212,7 @@ class Guild { console.log(position); if (thing.move_id && thing.move_id !== thing.parent_id) { thing.parent_id = thing.move_id; - thisthing.parent_id = thing.parent_id; + thisthing.parent_id = thing.parent?.id; thing.move_id = null; } if (thisthing.position || thisthing.parent_id) { @@ -234,7 +234,7 @@ class Guild { if (serverbug) { for (const thing of build) { console.log(build, thing); - fetch(this.info.api + "/guilds/" + this.snowflake + "/channels", { + fetch(this.info.api + "/guilds/" + this.id + "/channels", { method: "PATCH", headers: this.headers, body: JSON.stringify([thing]) @@ -242,7 +242,7 @@ class Guild { } } else { - fetch(this.info.api + "/guilds/" + this.snowflake + "/channels", { + fetch(this.info.api + "/guilds/" + this.id + "/channels", { method: "PATCH", headers: this.headers, body: JSON.stringify(build) @@ -422,17 +422,22 @@ class Guild { this.localuser.loadGuild(this.id); } updateChannel(json) { - SnowFlake.getSnowFlakeFromID(json.id, Channel).getObject().updateChannel(json); - this.headchannels = []; - for (const thing of this.channels) { - thing.children = []; - } - for (const thing of this.channels) { - if (thing.resolveparent(this)) { - this.headchannels.push(thing); + const channel = this.channelids[json.id]; + if (channel) { + channel.updateChannel(json); + this.headchannels = []; + for (const thing of this.channels) { + thing.children = []; } + this.headchannels = []; + for (const thing of this.channels) { + const parent = thing.resolveparent(this); + if (!parent) { + this.headchannels.push(thing); + } + } + this.printServers(); } - this.printServers(); } createChannelpac(json) { const thischannel = new Channel(json, this); diff --git a/.dist/localuser.js b/.dist/localuser.js index 4be9c1f..bf063f5 100644 --- a/.dist/localuser.js +++ b/.dist/localuser.js @@ -423,9 +423,12 @@ class Localuser { return undefined; } updateChannel(json) { - SnowFlake.getSnowFlakeFromID(json.guild_id, Guild).getObject().updateChannel(json); - if (json.guild_id === this.lookingguild?.id) { - this.loadGuild(json.guild_id); + const guild = this.guildids.get(json.guild_id); + if (guild) { + guild.updateChannel(json); + if (json.guild_id === this.lookingguild?.id) { + this.loadGuild(json.guild_id); + } } } createChannel(json) { diff --git a/webpage/channel.ts b/webpage/channel.ts index 174125c..51ab476 100644 --- a/webpage/channel.ts +++ b/webpage/channel.ts @@ -330,18 +330,18 @@ class Channel{ } calculateReorder(){ let position=-1; - const build:{id:SnowFlake,position:number|undefined,parent_id:SnowFlake|undefined}[]=[]; + const build:{id:string,position:number|undefined,parent_id:string|undefined}[]=[]; for(const thing of this.children){ - const thisthing:{id:SnowFlake,position:number|undefined,parent_id:SnowFlake|undefined}={id: thing.snowflake,position: undefined,parent_id: undefined}; + const thisthing:{id:string,position:number|undefined,parent_id:string|undefined}={id: thing.id,position: undefined,parent_id: undefined}; if(thing.position,position:number|undefined,parent_id:SnowFlake|undefined}[]=[]; + const build:{id:string,position:number|undefined,parent_id:string|undefined}[]=[]; for(const thing of this.headchannels){ - const thisthing:{id:SnowFlake,position:number|undefined,parent_id:SnowFlake|undefined}={id: thing.snowflake,position: undefined,parent_id: undefined}; + const thisthing:{id:string,position:number|undefined,parent_id:string|undefined}={id: thing.id,position: undefined,parent_id: undefined}; if(thing.position<=position){ thing.position=(thisthing.position=position+1); } @@ -223,7 +223,7 @@ class Guild{ console.log(position); if(thing.move_id&&thing.move_id!==thing.parent_id){ thing.parent_id=thing.move_id; - thisthing.parent_id=thing.parent_id; + thisthing.parent_id=thing.parent?.id; thing.move_id=null; } if(thisthing.position||thisthing.parent_id){ @@ -245,14 +245,14 @@ class Guild{ if(serverbug){ for(const thing of build){ console.log(build,thing); - fetch(this.info.api+"/guilds/"+this.snowflake+"/channels",{ + fetch(this.info.api+"/guilds/"+this.id+"/channels",{ method: "PATCH", headers: this.headers, body: JSON.stringify([thing]) }); } }else{ - fetch(this.info.api+"/guilds/"+this.snowflake+"/channels",{ + fetch(this.info.api+"/guilds/"+this.id+"/channels",{ method: "PATCH", headers: this.headers, body: JSON.stringify(build) @@ -431,17 +431,22 @@ class Guild{ this.localuser.loadGuild(this.id); } updateChannel(json:channeljson){ - SnowFlake.getSnowFlakeFromID(json.id,Channel).getObject().updateChannel(json); - this.headchannels=[]; - for(const thing of this.channels){ - thing.children=[]; - } - for(const thing of this.channels){ - if(thing.resolveparent(this)){ - this.headchannels.push(thing); + const channel=this.channelids[json.id]; + if(channel){ + channel.updateChannel(json); + this.headchannels=[]; + for(const thing of this.channels){ + thing.children=[]; } + this.headchannels=[]; + for(const thing of this.channels){ + const parent=thing.resolveparent(this); + if(!parent){ + this.headchannels.push(thing); + } + } + this.printServers(); } - this.printServers(); } createChannelpac(json:channeljson){ const thischannel=new Channel(json,this); diff --git a/webpage/localuser.ts b/webpage/localuser.ts index 475ab6b..115c526 100644 --- a/webpage/localuser.ts +++ b/webpage/localuser.ts @@ -426,9 +426,12 @@ class Localuser{ return undefined; } updateChannel(json:channeljson):void{ - SnowFlake.getSnowFlakeFromID(json.guild_id,Guild).getObject().updateChannel(json); - if(json.guild_id===this.lookingguild?.id){ - this.loadGuild(json.guild_id); + const guild=this.guildids.get(json.guild_id); + if(guild){ + guild.updateChannel(json); + if(json.guild_id===this.lookingguild?.id){ + this.loadGuild(json.guild_id); + } } } createChannel(json:channeljson):void{