Bug fixes, blocking and various other changes

This commit is contained in:
MathMan05 2024-08-21 11:37:26 -05:00
parent 42a438f6dc
commit dbee2f3628
22 changed files with 679 additions and 370 deletions

View file

@ -49,7 +49,7 @@ class Message {
Message.contextmenu.addbutton("Copy raw text", function () {
navigator.clipboard.writeText(this.content.rawString);
});
Message.contextmenu.addbutton("Reply", function (div) {
Message.contextmenu.addbutton("Reply", function () {
this.channel.setReplying(this);
});
Message.contextmenu.addbutton("Copy message id", function () {
@ -65,10 +65,14 @@ class Message {
const markdown = document.getElementById("typebox")["markdown"];
markdown.txt = this.content.rawString.split('');
markdown.boxupdate(document.getElementById("typebox"));
}, null, _ => { return _.author.id === _.localuser.user.id; });
}, null, function () {
return this.author.id === this.localuser.user.id;
});
Message.contextmenu.addbutton("Delete message", function () {
this.delete();
}, null, _ => { return _.canDelete(); });
}, null, function () {
return this.canDelete();
});
}
constructor(messagejson, owner) {
this.owner = owner;
@ -169,7 +173,7 @@ class Message {
return this.owner.info;
}
messageevents(obj) {
const func = Message.contextmenu.bind(obj, this);
const func = Message.contextmenu.bindContextmenu(obj, this, undefined);
this.div = obj;
obj.classList.add("messagediv");
}
@ -245,7 +249,16 @@ class Message {
}
}
reactdiv;
generateMessage(premessage = undefined) {
blockedPropigate() {
const premessage = this.channel.idToPrev.get(this.snowflake)?.getObject();
if (premessage?.author === this.author) {
premessage.blockedPropigate();
}
else {
this.generateMessage();
}
}
generateMessage(premessage = undefined, ignoredblock = false) {
if (!this.div)
return;
if (!premessage) {
@ -257,7 +270,66 @@ class Message {
}
div.innerHTML = "";
const build = document.createElement('div');
build.classList.add("flexltr");
build.classList.add("flexltr", "message");
div.classList.remove("zeroheight");
if (this.author.relationshipType === 2) {
if (ignoredblock) {
if (premessage?.author !== this.author) {
const span = document.createElement("span");
span.textContent = `You have this user blocked, click to hide these messages.`;
div.append(span);
span.classList.add("blocked");
span.onclick = _ => {
const scroll = this.channel.infinite.scrollTop;
let next = this;
while (next?.author === this.author) {
next.generateMessage(undefined);
next = this.channel.idToNext.get(next.snowflake)?.getObject();
}
if (this.channel.infinite.scroll && scroll) {
this.channel.infinite.scroll.scrollTop = scroll;
}
};
}
}
else {
div.classList.remove("topMessage");
if (premessage?.author === this.author) {
div.classList.add("zeroheight");
premessage.blockedPropigate();
div.appendChild(build);
return div;
}
else {
build.classList.add("blocked", "topMessage");
const span = document.createElement("span");
let count = 1;
let next = this.channel.idToNext.get(this.snowflake)?.getObject();
while (next?.author === this.author) {
count++;
next = this.channel.idToNext.get(next.snowflake)?.getObject();
}
span.textContent = `You have this user blocked, click to see the ${count} blocked messages.`;
build.append(span);
span.onclick = _ => {
const scroll = this.channel.infinite.scrollTop;
const func = this.channel.infinite.snapBottom();
let next = this;
while (next?.author === this.author) {
next.generateMessage(undefined, true);
next = this.channel.idToNext.get(next.snowflake)?.getObject();
console.log("loopy");
}
if (this.channel.infinite.scroll && scroll) {
func();
this.channel.infinite.scroll.scrollTop = scroll;
}
};
div.appendChild(build);
return div;
}
}
}
if (this.message_reference) {
const replyline = document.createElement("div");
const line = document.createElement("hr");
@ -269,7 +341,6 @@ class Message {
replyline.appendChild(username);
const reply = document.createElement("div");
username.classList.add("username");
this.author.bind(username, this.guild);
reply.classList.add("replytext");
replyline.appendChild(reply);
const line2 = document.createElement("hr");
@ -278,6 +349,10 @@ class Message {
line.classList.add("startreply");
replyline.classList.add("replyflex");
this.channel.getmessage(this.message_reference.message_id).then(message => {
if (message.author.relationshipType === 2) {
username.textContent = "Blocked user";
return;
}
const author = message.author;
reply.appendChild(message.content.makeHTML({ stdsize: true }));
minipfp.src = author.getpfpsrc();
@ -290,7 +365,6 @@ class Message {
};
div.appendChild(replyline);
}
build.classList.add("message");
div.appendChild(build);
if ({ 0: true, 19: true }[this.type] || this.attachments.length !== 0) {
const pfpRow = document.createElement('div');
@ -491,21 +565,17 @@ class Message {
}
}
}
let now = new Date().toLocaleDateString();
const yesterday = new Date(now);
yesterday.setDate(new Date().getDate() - 1);
let yesterdayStr = yesterday.toLocaleDateString();
function formatTime(date) {
const now = new Date();
const sameDay = date.getDate() === now.getDate() &&
date.getMonth() === now.getMonth() &&
date.getFullYear() === now.getFullYear();
const yesterday = new Date(now);
yesterday.setDate(now.getDate() - 1);
const isYesterday = date.getDate() === yesterday.getDate() &&
date.getMonth() === yesterday.getMonth() &&
date.getFullYear() === yesterday.getFullYear();
const formatTime = date => date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
if (sameDay) {
const datestring = date.toLocaleDateString();
const formatTime = (date) => date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
if (datestring === now) {
return `Today at ${formatTime(date)}`;
}
else if (isYesterday) {
else if (datestring === yesterdayStr) {
return `Yesterday at ${formatTime(date)}`;
}
else {