Reply GUI

This commit is contained in:
MathMan05 2024-06-28 19:53:48 -05:00
parent a05c74bb3c
commit e49360fba1
8 changed files with 116 additions and 22 deletions

View file

@ -404,6 +404,38 @@ class Channel {
headers: this.headers
});
}
setReplying(message) {
if (this.replyingto) {
this.replyingto.div.classList.remove("replying");
}
this.replyingto = message;
console.log(message);
this.replyingto.div.classList.add("replying");
this.makereplybox();
}
makereplybox() {
const replybox = document.getElementById("replybox");
if (this.replyingto) {
replybox.innerHTML = "";
const span = document.createElement("span");
span.textContent = "Replying to " + this.replyingto.author.username;
const X = document.createElement("button");
X.onclick = _ => {
this.replyingto.div.classList.remove("replying");
replybox.classList.add("hideReplyBox");
this.replyingto = null;
replybox.innerHTML = "";
};
replybox.classList.remove("hideReplyBox");
X.textContent = "⦻";
X.classList.add("cancelReply");
replybox.append(span);
replybox.append(X);
}
else {
replybox.classList.add("hideReplyBox");
}
}
async getmessage(id) {
if (this.messageids[id]) {
return this.messageids[id];
@ -427,6 +459,7 @@ class Channel {
const prom = Message.wipeChanel();
await this.putmessages();
await prom;
this.makereplybox();
this.buildmessages();
history.pushState(null, null, "/channels/" + this.guild_id + "/" + this.id);
document.getElementById("channelname").textContent = "#" + this.name;

View file

@ -11,14 +11,14 @@ async function waitforload() {
}
await waitforload();
function setDynamicHeight() {
var servertdHeight = document.getElementById('servertd').offsetHeight + document.getElementById('typebox').offsetHeight + document.getElementById('pasteimage').offsetHeight;
var servertdHeight = document.getElementById('servertd').offsetHeight + document.getElementById('typediv').offsetHeight + document.getElementById('pasteimage').offsetHeight;
document.documentElement.style.setProperty('--servertd-height', servertdHeight + 'px');
}
const resizeObserver = new ResizeObserver(() => {
setDynamicHeight();
});
resizeObserver.observe(document.getElementById('servertd'));
resizeObserver.observe(document.getElementById('typebox'));
resizeObserver.observe(document.getElementById('replybox'));
resizeObserver.observe(document.getElementById('pasteimage'));
setDynamicHeight();
const users = getBulkUsers();
@ -129,15 +129,16 @@ async function enter(event) {
}
else {
replyingto = thisuser.channelfocus.replyingto;
let replying = replyingto?.all;
let replying = replyingto;
if (replyingto) {
replyingto.classList.remove("replying");
replyingto.div.classList.remove("replying");
}
thisuser.channelfocus.replyingto = null;
channel.sendMessage(typebox.value, {
attachments: images,
replyingto: replying,
});
thisuser.channelfocus.makereplybox();
}
while (images.length != 0) {
images.pop();

View file

@ -36,12 +36,7 @@ class Message {
navigator.clipboard.writeText(this.content);
});
Message.contextmenu.addbutton("Reply", function (div) {
if (this.channel.replyingto) {
this.channel.replyingto.classList.remove("replying");
}
this.channel.replyingto = div;
console.log(div);
this.channel.replyingto.classList.add("replying");
this.channel.setReplying(this);
});
Message.contextmenu.addbutton("Copy message id", function () {
navigator.clipboard.writeText(this.id);
@ -163,6 +158,9 @@ class Message {
premessage = this.channel.messages[this.channel.messages.indexOf(this) + 1];
}
const div = this.div;
if (this === this.channel.replyingto) {
div.classList.add("replying");
}
div.innerHTML = "";
const build = document.createElement('table');
if (this.message_reference) {