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

@ -52,6 +52,9 @@ class Message {
constructor(messagejson, owner) {
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 = [];
@ -76,6 +79,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;
@ -92,11 +98,12 @@ class Message {
get info() {
return this.owner.info;
}
messageevents(obj) {
messageevents(obj, 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");
@ -136,17 +143,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 = 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) {
@ -203,7 +212,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) {
@ -304,14 +312,15 @@ class Message {
div["all"] = this;
return (div);
}
buildhtml(premessage) {
buildhtml(premessage, del = Message.del) {
if (this.div) {
console.error(`HTML for ${this} already exists, aborting`);
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);
}
}