remove snowflake instances

This commit is contained in:
MathMan05
2024-09-03 11:00:44 -05:00
parent 004beb4955
commit e66b6c0883
16 changed files with 97 additions and 149 deletions

View File

@@ -18,13 +18,12 @@ declare global {
image?: string|null|undefined
}
}
class Channel{
class Channel extends SnowFlake{
editing:Message|null;
type:number;
owner:Guild;
headers:Localuser["headers"];
name:string;
snowflake:SnowFlake;
parent_id?:string;
parent:Channel|null;
children:Channel[];
@@ -48,9 +47,6 @@ class Channel{
idToPrev:Map<string,string>=new Map();
idToNext:Map<string,string>=new Map();
messages:Map<string,Message>=new Map();
get id(){
return this.snowflake.id;
}
static setupcontextmenu(){
this.contextmenu.addbutton("Copy channel id",function(this:Channel){
console.log(this);
@@ -171,20 +167,19 @@ class Channel{
}
setUpInfiniteScroller(){
this.infinite=new InfiniteScroller((async (id:string,offset:number):Promise<string|undefined>=>{
const snowflake=id;
if(offset===1){
if(this.idToPrev.has(snowflake)){
return this.idToPrev.get(snowflake);
if(this.idToPrev.has(id)){
return this.idToPrev.get(id);
}else{
await this.grabBefore(id);
return this.idToPrev.get(snowflake);
return this.idToPrev.get(id);
}
}else{
if(this.idToNext.has(snowflake)){
return this.idToNext.get(snowflake);
if(this.idToNext.has(id)){
return this.idToNext.get(id);
}else if(this.lastmessage?.id!==id){
await this.grabAfter(id);
return this.idToNext.get(snowflake);
return this.idToNext.get(id);
}else{
console.log("at bottom");
}
@@ -219,7 +214,8 @@ class Channel{
this.readbottom.bind(this)
);
}
constructor(json:channeljson|-1,owner:Guild){
constructor(json:channeljson|-1,owner:Guild,id:string=json===-1?undefined:json.id){
super(id);
if(json===-1){
return;
}
@@ -228,7 +224,6 @@ class Channel{
this.owner=owner;
this.headers=this.owner.headers;
this.name=json.name;
this.snowflake=new SnowFlake(json.id);
if(json.parent_id){
this.parent_id=json.parent_id;
}
@@ -500,7 +495,7 @@ class Channel{
if(!this.hasunreads){
return;
}
fetch(this.info.api+"/channels/"+this.snowflake+"/messages/"+this.lastmessageid+"/ack",{
fetch(this.info.api+"/channels/"+this.id+"/messages/"+this.lastmessageid+"/ack",{
method: "POST",
headers: this.headers,
body: JSON.stringify({})
@@ -586,7 +581,7 @@ class Channel{
let name=this.name;
let topic=this.topic;
let nsfw=this.nsfw;
const thisid=this.snowflake;
const thisid=this.id;
const thistype=this.type;
const full=new Dialog(
["hdiv",
@@ -625,7 +620,7 @@ class Channel{
console.log(full);
}
deleteChannel(){
fetch(this.info.api+"/channels/"+this.snowflake,{
fetch(this.info.api+"/channels/"+this.id,{
method: "DELETE",
headers: this.headers
});
@@ -669,7 +664,7 @@ class Channel{
if(message){
return message;
}else{
const gety=await fetch(this.info.api+"/channels/"+this.snowflake+"/messages?limit=1&around="+id,{headers: this.headers});
const gety=await fetch(this.info.api+"/channels/"+this.id+"/messages?limit=1&around="+id,{headers: this.headers});
const json=await gety.json();
return new Message(json[0],this);
}
@@ -692,7 +687,7 @@ class Channel{
this.guild.prevchannel=this;
this.localuser.channelfocus=this;
const prom=this.infinite.delete();
history.pushState(null, "","/channels/"+this.guild_id+"/"+this.snowflake);
history.pushState(null, "","/channels/"+this.guild_id+"/"+this.id);
this.localuser.pageTitle("#"+this.name);
const channelTopic=document.getElementById("channelTopic") as HTMLSpanElement;
@@ -746,7 +741,7 @@ class Channel{
if(this.lastreadmessageid&&this.messages.has(this.lastreadmessageid)){
return;
}
const j=await fetch(this.info.api+"/channels/"+this.snowflake+"/messages?limit=100",{
const j=await fetch(this.info.api+"/channels/"+this.id+"/messages?limit=100",{
headers: this.headers,
});
@@ -856,11 +851,6 @@ class Channel{
throw new Error("please don't call this, no one has implemented it :P");
}
async buildmessages(){
/*
if(((!this.lastmessage)||(!this.lastmessage.snowflake)||(!this.goBackIds(this.lastmessage.snowflake,50,false)))&&this.lastreadmessageid){
await this.grabAfter(this.lastreadmessageid.id);
}
*/
this.infinitefocus=false;
this.tryfocusinfinate();
}
@@ -973,7 +963,7 @@ class Channel{
return;
}
this.typing=Date.now()+6000;
fetch(this.info.api+"/channels/"+this.snowflake+"/typing",{
fetch(this.info.api+"/channels/"+this.id+"/typing",{
method: "POST",
headers: this.headers
});
@@ -1015,7 +1005,7 @@ class Channel{
if(replyjson){
body.message_reference=replyjson;
}
return await fetch(this.info.api+"/channels/"+this.snowflake+"/messages",{
return await fetch(this.info.api+"/channels/"+this.id+"/messages",{
method: "POST",
headers: this.headers,
body: JSON.stringify(body)
@@ -1034,7 +1024,7 @@ class Channel{
for(const i in attachments){
formData.append("files["+i+"]",attachments[i]);
}
return await fetch(this.info.api+"/channels/"+this.snowflake+"/messages", {
return await fetch(this.info.api+"/channels/"+this.id+"/messages", {
method: "POST",
body: formData,
headers: {Authorization: this.headers.Authorization}
@@ -1125,7 +1115,7 @@ class Channel{
}
}
async addRoleToPerms(role:Role){
await fetch(this.info.api+"/channels/"+this.snowflake+"/permissions/"+role.snowflake,{
await fetch(this.info.api+"/channels/"+this.id+"/permissions/"+role.id,{
method: "PUT",
headers: this.headers,
body: JSON.stringify({
@@ -1144,7 +1134,7 @@ class Channel{
if(permission){
permission.allow=perms.allow;
permission.deny=perms.deny;
await fetch(this.info.api+"/channels/"+this.snowflake+"/permissions/"+id,{
await fetch(this.info.api+"/channels/"+this.id+"/permissions/"+id,{
method: "PUT",
headers: this.headers,
body: JSON.stringify({