more bug fixes

This commit is contained in:
MathMan05 2024-05-28 11:18:05 -05:00
parent 8e89e9929b
commit cbf657afeb
2 changed files with 38 additions and 21 deletions

View file

@ -429,7 +429,9 @@ function initwebsocket(){
if(temp.op==0){ if(temp.op==0){
switch(temp.t){ switch(temp.t){
case "MESSAGE_CREATE": case "MESSAGE_CREATE":
thisuser.messageCreate(temp); if(thisuser){
thisuser.messageCreate(temp);
}
break; break;
case "READY": case "READY":
thisuser=new localuser(temp); thisuser=new localuser(temp);
@ -441,37 +443,49 @@ function initwebsocket(){
document.getElementById("loading").classList.remove("loading") document.getElementById("loading").classList.remove("loading")
break; break;
case "MESSAGE_UPDATE": case "MESSAGE_UPDATE":
if(window.location.pathname.split("/")[3]==temp.d.channel_id){ if(thisuser){
const find=temp.d.id; if(window.location.pathname.split("/")[3]==temp.d.channel_id){
for(const message of messagelist){ const find=temp.d.id;
if(message.all.id===find){ for(const message of messagelist){
message.all.content=temp.d.content; if(message.all.id===find){
message.txt.innerHTML=markdown(temp.d.content).innerHTML; message.all.content=temp.d.content;
break; message.txt.innerHTML=markdown(temp.d.content).innerHTML;
break;
}
} }
} }
} }
break; break;
case "TYPING_START": case "TYPING_START":
thisuser.typeingStart(temp); if(thisuser){
thisuser.typeingStart(temp);
}
break; break;
case "USER_UPDATE": case "USER_UPDATE":
const users=user.userids[temp.d.id]; if(thisuser){
console.log(users,temp.d.id) const users=user.userids[temp.d.id];
console.log(users,temp.d.id)
if(users){ if(users){
users.userupdate(temp.d); users.userupdate(temp.d);
console.log("in here"); console.log("in here");
}
} }
break break
case "CHANNEL_UPDATE": case "CHANNEL_UPDATE":
thisuser.updateChannel(temp.d); if(thisuser){
thisuser.updateChannel(temp.d);
}
break; break;
case "CHANNEL_CREATE": case "CHANNEL_CREATE":
thisuser.createChannel(temp.d); if(thisuser){
thisuser.createChannel(temp.d);
}
break; break;
case "CHANNEL_DELETE": case "CHANNEL_DELETE":
thisuser.delChannel(temp.d); if(thisuser){
thisuser.delChannel(temp.d);
}
break; break;
} }

View file

@ -24,15 +24,18 @@ class localuser{
} }
for(const thing of ready.d.read_state.entries){ for(const thing of ready.d.read_state.entries){
console.log(thing) console.log(thing)
const guildid=this.resolveGuildidFromChannelID(thing.id).id; const guild=this.resolveGuildidFromChannelID(thing.id)
if(guild===undefined){
continue
}
const guildid=guild.id;
this.guildids[guildid].channelids[thing.channel_id].readStateInfo(thing); this.guildids[guildid].channelids[thing.channel_id].readStateInfo(thing);
} }
this.typing=[]; this.typing=[];
} }
resolveGuildidFromChannelID(ID){ resolveGuildidFromChannelID(ID){
const resolve=this.guilds.find(guild => guild.channelids[ID]) const resolve=this.guilds.find(guild => guild.channelids[ID])
resolve??={}; resolve??=undefined;
console.error("Failed to resolve "+ID);
return resolve; return resolve;
} }
updateChannel(JSON){ updateChannel(JSON){