Skip to content

Commit

Permalink
fix profile picture bug
Browse files Browse the repository at this point in the history
  • Loading branch information
roxwize committed Mar 5, 2024
1 parent 9dd089d commit c8920b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "imood-plusplus",
"description": "improves the imood frontend in different ways",
"version": "1.1",
"version": "1.1.1",
"scripts": {
"build": "rollup -c",
"dev": "rollup -cw"
Expand Down
18 changes: 14 additions & 4 deletions src/forum.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ class Post {

if (userdate.childNodes[1].nodeName === "A") {
this.uinfo.user = userdate.childNodes[1].textContent;
this.uinfo.ulink = userdate.childNodes[1].href;
this.uinfo.ulink = new URL(userdate.childNodes[1].href);
this.uinfo.id = this.uinfo.ulink.pathname.substring(7);
this.date = new Date(Date.parse(userdate.childNodes[3].textContent));
} else {
this.uinfo.user = "";
this.date = new Date(Date.parse(userdate.childNodes[2].textContent));
}

// add paragraphs
this.content = [];
msg.querySelectorAll("p").forEach((p) => {
this.content.push(p.outerHTML);
});

// if the top post then set title
if (msg.childNodes[1].nodeName === "H2") {
this.title = msg.childNodes[1].textContent;
} else {
Expand All @@ -44,9 +47,10 @@ class Post {
getServerUserInfo() {
return new Promise(async (resolve, reject) => {
if (!this.uinfo.user) {
resolve("Ermmmm");
resolve(`Requested user "${this.uinfo.user}" does not exist`);
return;
}
// if we're cached already then just set our data to what's in the cache and dip out
if (cachedUserInfo[this.uinfo.user]) {
resolve(cachedUserInfo[this.uinfo.user]);
this.uinfo = cachedUserInfo[this.uinfo.user];
Expand Down Expand Up @@ -74,7 +78,7 @@ class Post {
}
render(index) {
const div = document.createElement("div");
div.classList.add("im-post");
div.classList.add("im-post", `im-post-u-${this.uinfo.id}`);
div.id = "im-post-" + index.toString();
div.innerHTML = `
<div class="im-post-icon">
Expand Down Expand Up @@ -103,6 +107,10 @@ class Post {
img.onerror = null;
img.src = PLACEHOLDER;
this.uinfo.icon = img.src;
// replace all pre-existing posts by the user with the placeholder
document.querySelectorAll(`.im-post-u-${this.uinfo.id}`).forEach((e) => {
e.querySelector("img").src = PLACEHOLDER;
});
};

return div;
Expand All @@ -112,7 +120,9 @@ class Post {
class UserInfo {
constructor() {
this.user = "Deleted User";
this.ulink = "";
this.id = "";
/** @type {URL?} */
this.ulink = null;
this.mood = "Unknown mood";
this.icon = "";
}
Expand Down

0 comments on commit c8920b1

Please sign in to comment.