Adds a more proper infinate scroller

It probally does more, but I can't remember what lol
This commit is contained in:
MathMan05 2024-07-20 14:36:19 -05:00
parent d28ccb68be
commit ec6ab101c0
22 changed files with 572 additions and 430 deletions

View file

@ -3,7 +3,6 @@ import {User} from "./user.js";
import {Member} from "./member.js";
import {markdown} from "./markdown.js";
import {Embed} from "./embed.js";
import {Fullscreen} from "./fullscreen.js";
import { Channel } from "./channel.js";
import {Localuser} from "./localuser.js";
import { Role } from "./role.js";
@ -57,6 +56,10 @@ class Message{
constructor(messagejson,owner:Channel){
this.owner=owner;
this.headers=this.owner.headers;
this.giveData(messagejson);
}
giveData(messagejson){
for(const thing of Object.keys(messagejson)){
if(thing==="attachments"){
this.attachments=[];
@ -81,6 +84,9 @@ class Message{
if(this.mentionsuser(this.localuser.user)){
console.log(this);
}
if(this.div){
this.generateMessage();
}
}
canDelete(){
return this.channel.hasPermission("MANAGE_MESSAGES")||this.author.id===this.localuser.user.id;
@ -97,11 +103,12 @@ class Message{
get info(){
return this.owner.info;
}
messageevents(obj:HTMLDivElement){
messageevents(obj:HTMLDivElement,del=Message.del){
const func=Message.contextmenu.bind(obj,this);
this.div=obj;
Message.del.then(_=>{
del.then(_=>{
obj.removeEventListener("click",func);
this.div.remove();
this.div=null;
})
obj.classList.add("messagediv");
@ -140,17 +147,19 @@ class Message{
this.div.innerHTML="";
this.div=null;
}
const index=this.channel.messages.indexOf(this);
this.channel.messages.splice(this.channel.messages.indexOf(this),1);
const prev=this.channel.idToPrev[this.id];
const next=this.channel.idToNext[this.id];
this.channel.idToNext[prev]=next;
this.channel.idToPrev[next]=prev;
delete this.channel.messageids[this.id];
const regen=this.channel.messages[index-1]
const regen=this.channel.messageids[prev]
if(regen){
regen.generateMessage();
}
}
generateMessage(premessage:Message=null){
if(!premessage){
premessage=this.channel.messages[this.channel.messages.indexOf(this)+1];
premessage=this.channel.messageids[this.channel.idToNext[this.id]];
}
const div=this.div;
if(this===this.channel.replyingto){
@ -209,8 +218,6 @@ class Message{
});
div.appendChild(replyline);
}
this.messageevents(div);
build.classList.add("message");
div.appendChild(build);
if({0:true,19:true}[this.type]||this.attachments.length!==0){
@ -313,11 +320,13 @@ class Message{
div["all"]=this;
return(div)
}
buildhtml(premessage:Message){
if(this.div){console.error(`HTML for ${this} already exists, aborting`);return;}
buildhtml(premessage:Message,del:Promise<void>=Message.del){
if(this.div){console.error(`HTML for ${this.id} already exists, aborting`);return;}
//premessage??=messages.lastChild;
const div=document.createElement("div");
this.div=div;
this.messageevents(div,del);
return this.generateMessage(premessage);
}
}