snowflake and cleaning up classes
This commit is contained in:
@@ -7,6 +7,7 @@ import { Channel } from "./channel.js";
|
||||
import {Localuser} from "./localuser.js";
|
||||
import { Role } from "./role.js";
|
||||
import {File} from "./file.js";
|
||||
import { SnowFlake } from "./snowflake.js";
|
||||
|
||||
class Message{
|
||||
static contextmenu=new Contextmenu("message menu");
|
||||
@@ -17,7 +18,7 @@ class Message{
|
||||
mentions:User[];
|
||||
mention_roles:Role[];
|
||||
attachments:File[];//probably should be its own class tbh, should be Attachments[]
|
||||
id:string;
|
||||
id:SnowFlake<Message>;
|
||||
message_reference;
|
||||
type:number;
|
||||
timestamp:number;
|
||||
@@ -43,7 +44,7 @@ class Message{
|
||||
this.channel.setReplying(this);
|
||||
});
|
||||
Message.contextmenu.addbutton("Copy message id",function(){
|
||||
navigator.clipboard.writeText(this.id);
|
||||
navigator.clipboard.writeText(this.id.id);
|
||||
});
|
||||
Message.contextmenu.addbutton("Edit",function(){
|
||||
this.channel.editing=this;
|
||||
@@ -72,6 +73,9 @@ class Message{
|
||||
}else if(thing==="content"){
|
||||
this.content=new MarkDown(messagejson[thing],this.channel);
|
||||
continue;
|
||||
}else if(thing ==="id"){
|
||||
this.id=new SnowFlake(messagejson.id,this);
|
||||
continue;
|
||||
}
|
||||
this[thing]=messagejson[thing];
|
||||
}
|
||||
@@ -135,14 +139,14 @@ class Message{
|
||||
return build;
|
||||
}
|
||||
async edit(content){
|
||||
return await fetch(this.info.api.toString()+"/channels/"+this.channel.id+"/messages/"+this.id,{
|
||||
return await fetch(this.info.api.toString()+"/channels/"+this.channel.id+"/messages/"+this.id.id,{
|
||||
method: "PATCH",
|
||||
headers: this.headers,
|
||||
body:JSON.stringify({content:content})
|
||||
});
|
||||
}
|
||||
delete(){
|
||||
fetch(`${this.info.api.toString()}/channels/${this.channel.id}/messages/${this.id}`,{
|
||||
fetch(`${this.info.api.toString()}/channels/${this.channel.id}/messages/${this.id.id}`,{
|
||||
headers:this.headers,
|
||||
method:"DELETE",
|
||||
})
|
||||
@@ -152,19 +156,22 @@ class Message{
|
||||
this.div.innerHTML="";
|
||||
this.div=null;
|
||||
}
|
||||
const prev=this.channel.idToPrev[this.id];
|
||||
const next=this.channel.idToNext[this.id];
|
||||
const prev=this.channel.idToPrev[this.id.id];
|
||||
const next=this.channel.idToNext[this.id.id];
|
||||
this.channel.idToNext[prev]=next;
|
||||
this.channel.idToPrev[next]=prev;
|
||||
delete this.channel.messageids[this.id];
|
||||
delete this.channel.messageids[this.id.id];
|
||||
const regen=this.channel.messageids[prev]
|
||||
if(regen){
|
||||
regen.generateMessage();
|
||||
}
|
||||
if(this.channel.lastmessage===this){
|
||||
this.channel.lastmessage=this.channel.messageids[prev];
|
||||
}
|
||||
}
|
||||
generateMessage(premessage:Message=null){
|
||||
if(!premessage){
|
||||
premessage=this.channel.messageids[this.channel.idToNext[this.id]];
|
||||
premessage=this.channel.messageids[this.channel.idToNext[this.id.id]];
|
||||
}
|
||||
const div=this.div;
|
||||
if(this===this.channel.replyingto){
|
||||
|
Reference in New Issue
Block a user