fixing bugs for re-order
This commit is contained in:
parent
19f08a6408
commit
e79e4affb4
6 changed files with 74 additions and 44 deletions
|
@ -321,16 +321,16 @@ class Channel {
|
||||||
let position = -1;
|
let position = -1;
|
||||||
const build = [];
|
const build = [];
|
||||||
for (const thing of this.children) {
|
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) {
|
if (thing.position < position) {
|
||||||
thing.position = thisthing.position = position + 1;
|
thing.position = thisthing.position = position + 1;
|
||||||
}
|
}
|
||||||
position = thing.position;
|
position = thing.position;
|
||||||
if (thing.move_id && thing.move_id !== thing.parent_id) {
|
if (thing.move_id && thing.move_id !== thing.parent_id) {
|
||||||
thing.parent_id = thing.move_id;
|
thing.parent_id = thing.move_id;
|
||||||
thisthing.parent_id = thing.parent_id;
|
thisthing.parent_id = thing.parent?.id;
|
||||||
thing.move_id = null;
|
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) {
|
if (thisthing.position || thisthing.parent_id) {
|
||||||
build.push(thisthing);
|
build.push(thisthing);
|
||||||
|
@ -929,8 +929,15 @@ class Channel {
|
||||||
updateChannel(json) {
|
updateChannel(json) {
|
||||||
this.type = json.type;
|
this.type = json.type;
|
||||||
this.name = json.name;
|
this.name = json.name;
|
||||||
this.parent_id = SnowFlake.getSnowFlakeFromID(json.parent_id, Channel);
|
const parent = this.guild.channelids[json.parent_id];
|
||||||
this.parent = null;
|
if (parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
this.parent_id = parent.snowflake;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.parent = null;
|
||||||
|
this.parent_id = null;
|
||||||
|
}
|
||||||
this.children = [];
|
this.children = [];
|
||||||
this.guild_id = json.guild_id;
|
this.guild_id = json.guild_id;
|
||||||
this.messageids = new Map();
|
this.messageids = new Map();
|
||||||
|
|
|
@ -204,7 +204,7 @@ class Guild {
|
||||||
let position = -1;
|
let position = -1;
|
||||||
const build = [];
|
const build = [];
|
||||||
for (const thing of this.headchannels) {
|
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) {
|
if (thing.position <= position) {
|
||||||
thing.position = (thisthing.position = position + 1);
|
thing.position = (thisthing.position = position + 1);
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ class Guild {
|
||||||
console.log(position);
|
console.log(position);
|
||||||
if (thing.move_id && thing.move_id !== thing.parent_id) {
|
if (thing.move_id && thing.move_id !== thing.parent_id) {
|
||||||
thing.parent_id = thing.move_id;
|
thing.parent_id = thing.move_id;
|
||||||
thisthing.parent_id = thing.parent_id;
|
thisthing.parent_id = thing.parent?.id;
|
||||||
thing.move_id = null;
|
thing.move_id = null;
|
||||||
}
|
}
|
||||||
if (thisthing.position || thisthing.parent_id) {
|
if (thisthing.position || thisthing.parent_id) {
|
||||||
|
@ -234,7 +234,7 @@ class Guild {
|
||||||
if (serverbug) {
|
if (serverbug) {
|
||||||
for (const thing of build) {
|
for (const thing of build) {
|
||||||
console.log(build, thing);
|
console.log(build, thing);
|
||||||
fetch(this.info.api + "/guilds/" + this.snowflake + "/channels", {
|
fetch(this.info.api + "/guilds/" + this.id + "/channels", {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify([thing])
|
body: JSON.stringify([thing])
|
||||||
|
@ -242,7 +242,7 @@ class Guild {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fetch(this.info.api + "/guilds/" + this.snowflake + "/channels", {
|
fetch(this.info.api + "/guilds/" + this.id + "/channels", {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify(build)
|
body: JSON.stringify(build)
|
||||||
|
@ -422,17 +422,22 @@ class Guild {
|
||||||
this.localuser.loadGuild(this.id);
|
this.localuser.loadGuild(this.id);
|
||||||
}
|
}
|
||||||
updateChannel(json) {
|
updateChannel(json) {
|
||||||
SnowFlake.getSnowFlakeFromID(json.id, Channel).getObject().updateChannel(json);
|
const channel = this.channelids[json.id];
|
||||||
this.headchannels = [];
|
if (channel) {
|
||||||
for (const thing of this.channels) {
|
channel.updateChannel(json);
|
||||||
thing.children = [];
|
this.headchannels = [];
|
||||||
}
|
for (const thing of this.channels) {
|
||||||
for (const thing of this.channels) {
|
thing.children = [];
|
||||||
if (thing.resolveparent(this)) {
|
|
||||||
this.headchannels.push(thing);
|
|
||||||
}
|
}
|
||||||
|
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) {
|
createChannelpac(json) {
|
||||||
const thischannel = new Channel(json, this);
|
const thischannel = new Channel(json, this);
|
||||||
|
|
|
@ -423,9 +423,12 @@ class Localuser {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
updateChannel(json) {
|
updateChannel(json) {
|
||||||
SnowFlake.getSnowFlakeFromID(json.guild_id, Guild).getObject().updateChannel(json);
|
const guild = this.guildids.get(json.guild_id);
|
||||||
if (json.guild_id === this.lookingguild?.id) {
|
if (guild) {
|
||||||
this.loadGuild(json.guild_id);
|
guild.updateChannel(json);
|
||||||
|
if (json.guild_id === this.lookingguild?.id) {
|
||||||
|
this.loadGuild(json.guild_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createChannel(json) {
|
createChannel(json) {
|
||||||
|
|
|
@ -330,18 +330,18 @@ class Channel{
|
||||||
}
|
}
|
||||||
calculateReorder(){
|
calculateReorder(){
|
||||||
let position=-1;
|
let position=-1;
|
||||||
const build:{id:SnowFlake<Channel>,position:number|undefined,parent_id:SnowFlake<Channel>|undefined}[]=[];
|
const build:{id:string,position:number|undefined,parent_id:string|undefined}[]=[];
|
||||||
for(const thing of this.children){
|
for(const thing of this.children){
|
||||||
const thisthing:{id:SnowFlake<Channel>,position:number|undefined,parent_id:SnowFlake<Channel>|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){
|
if(thing.position<position){
|
||||||
thing.position=thisthing.position=position+1;
|
thing.position=thisthing.position=position+1;
|
||||||
}
|
}
|
||||||
position=thing.position;
|
position=thing.position;
|
||||||
if(thing.move_id&&thing.move_id!==thing.parent_id){
|
if(thing.move_id&&thing.move_id!==thing.parent_id){
|
||||||
thing.parent_id=thing.move_id;
|
thing.parent_id=thing.move_id;
|
||||||
thisthing.parent_id=thing.parent_id;
|
thisthing.parent_id=thing.parent?.id;
|
||||||
thing.move_id=null;
|
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){
|
if(thisthing.position||thisthing.parent_id){
|
||||||
build.push(thisthing);
|
build.push(thisthing);
|
||||||
|
@ -933,8 +933,15 @@ class Channel{
|
||||||
updateChannel(json:channeljson){
|
updateChannel(json:channeljson){
|
||||||
this.type=json.type;
|
this.type=json.type;
|
||||||
this.name=json.name;
|
this.name=json.name;
|
||||||
this.parent_id=SnowFlake.getSnowFlakeFromID(json.parent_id,Channel);
|
const parent=this.guild.channelids[json.parent_id];
|
||||||
this.parent=null;
|
if(parent){
|
||||||
|
this.parent=parent;
|
||||||
|
this.parent_id=parent.snowflake;
|
||||||
|
}else{
|
||||||
|
this.parent=null;
|
||||||
|
this.parent_id=null;
|
||||||
|
}
|
||||||
|
|
||||||
this.children=[];
|
this.children=[];
|
||||||
this.guild_id=json.guild_id;
|
this.guild_id=json.guild_id;
|
||||||
this.messageids=new Map();
|
this.messageids=new Map();
|
||||||
|
|
|
@ -213,9 +213,9 @@ class Guild{
|
||||||
}
|
}
|
||||||
calculateReorder(){
|
calculateReorder(){
|
||||||
let position=-1;
|
let position=-1;
|
||||||
const build:{id:SnowFlake<Channel>,position:number|undefined,parent_id:SnowFlake<Channel>|undefined}[]=[];
|
const build:{id:string,position:number|undefined,parent_id:string|undefined}[]=[];
|
||||||
for(const thing of this.headchannels){
|
for(const thing of this.headchannels){
|
||||||
const thisthing:{id:SnowFlake<Channel>,position:number|undefined,parent_id:SnowFlake<Channel>|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){
|
if(thing.position<=position){
|
||||||
thing.position=(thisthing.position=position+1);
|
thing.position=(thisthing.position=position+1);
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ class Guild{
|
||||||
console.log(position);
|
console.log(position);
|
||||||
if(thing.move_id&&thing.move_id!==thing.parent_id){
|
if(thing.move_id&&thing.move_id!==thing.parent_id){
|
||||||
thing.parent_id=thing.move_id;
|
thing.parent_id=thing.move_id;
|
||||||
thisthing.parent_id=thing.parent_id;
|
thisthing.parent_id=thing.parent?.id;
|
||||||
thing.move_id=null;
|
thing.move_id=null;
|
||||||
}
|
}
|
||||||
if(thisthing.position||thisthing.parent_id){
|
if(thisthing.position||thisthing.parent_id){
|
||||||
|
@ -245,14 +245,14 @@ class Guild{
|
||||||
if(serverbug){
|
if(serverbug){
|
||||||
for(const thing of build){
|
for(const thing of build){
|
||||||
console.log(build,thing);
|
console.log(build,thing);
|
||||||
fetch(this.info.api+"/guilds/"+this.snowflake+"/channels",{
|
fetch(this.info.api+"/guilds/"+this.id+"/channels",{
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify([thing])
|
body: JSON.stringify([thing])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
fetch(this.info.api+"/guilds/"+this.snowflake+"/channels",{
|
fetch(this.info.api+"/guilds/"+this.id+"/channels",{
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify(build)
|
body: JSON.stringify(build)
|
||||||
|
@ -431,17 +431,22 @@ class Guild{
|
||||||
this.localuser.loadGuild(this.id);
|
this.localuser.loadGuild(this.id);
|
||||||
}
|
}
|
||||||
updateChannel(json:channeljson){
|
updateChannel(json:channeljson){
|
||||||
SnowFlake.getSnowFlakeFromID(json.id,Channel).getObject().updateChannel(json);
|
const channel=this.channelids[json.id];
|
||||||
this.headchannels=[];
|
if(channel){
|
||||||
for(const thing of this.channels){
|
channel.updateChannel(json);
|
||||||
thing.children=[];
|
this.headchannels=[];
|
||||||
}
|
for(const thing of this.channels){
|
||||||
for(const thing of this.channels){
|
thing.children=[];
|
||||||
if(thing.resolveparent(this)){
|
|
||||||
this.headchannels.push(thing);
|
|
||||||
}
|
}
|
||||||
|
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){
|
createChannelpac(json:channeljson){
|
||||||
const thischannel=new Channel(json,this);
|
const thischannel=new Channel(json,this);
|
||||||
|
|
|
@ -426,9 +426,12 @@ class Localuser{
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
updateChannel(json:channeljson):void{
|
updateChannel(json:channeljson):void{
|
||||||
SnowFlake.getSnowFlakeFromID(json.guild_id,Guild).getObject().updateChannel(json);
|
const guild=this.guildids.get(json.guild_id);
|
||||||
if(json.guild_id===this.lookingguild?.id){
|
if(guild){
|
||||||
this.loadGuild(json.guild_id);
|
guild.updateChannel(json);
|
||||||
|
if(json.guild_id===this.lookingguild?.id){
|
||||||
|
this.loadGuild(json.guild_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createChannel(json:channeljson):void{
|
createChannel(json:channeljson):void{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue