From 85b8754b857b13eb13006b08d8d8c19bab41f85c Mon Sep 17 00:00:00 2001 From: Mystikfluu Date: Tue, 26 Jul 2022 15:56:30 +0200 Subject: [PATCH] move reply click handling to a seperate function --- js/posts.js | 49 +++++++++++++++++++++++++++++++-------------- server.js | 2 +- views/settings.html | 2 +- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/js/posts.js b/js/posts.js index 6e3e5b4..e5091dc 100644 --- a/js/posts.js +++ b/js/posts.js @@ -99,6 +99,28 @@ async function getavatar(username) { return user } +async function reply_link_clicked(reply_channel,reply_id) { + console.log("clicked link") + if(reply_channel != currentChannel) { + console.log("reply is in another channel") + switchChannel(reply_channel) + console.log("switched channel") + await main() + console.log("loaded new messages") + let replied_msg = document.getElementById(reply_id) + if(replied_msg) { + console.log("found element") + replied_msg.scrollIntoView() + } + } else { + let replied_msg = document.getElementById(reply_id) + if(replied_msg) { + console.log("found element") + replied_msg.scrollIntoView() + } + } +} + async function createPost(username,text,time,specialtext,postid,isbot,reply_id,add_on_top) { if(!specialtext)specialtext="" const newDiv = document.createElement("div"); @@ -172,8 +194,6 @@ async function createPost(username,text,time,specialtext,postid,isbot,reply_id,a replyAvatar.classList.add("avatar") replyAvatar.src = await getavatar(reply_username) - replyA.href = "#"+reply_id - replyA.appendChild(replyAvatar) replyA.appendChild(reply_username_text) replyA.appendChild(spacerTextNode()) @@ -181,23 +201,22 @@ async function createPost(username,text,time,specialtext,postid,isbot,reply_id,a replyA.appendChild(replyBr) replyA.classList.add("no-link-style") - - replyA.addEventListener("click",async function(event){ - if(reply_channel != currentChannel) { - event.preventDefault() - switchChannel(reply_channel) - await main() - let replied_msg = document.getElementById(reply_id) - if(replied_msg) { - replied_msg.scrollIntoView() - } - } - }) + // async function onclick(event) { + // event.preventDefault() + + // } + // replyDiv.onclick = function() { + // reply_link_clicked(reply_channel, reply_id) + // } replyDiv.appendChild(replyA) newDiv.appendChild(replyDiv) - } catch (ignored) {} + + replyDiv.outerHTML = replyDiv.outerHTML.replace(/\>/im,` onclick="reply_link_clicked('${reply_channel}',${reply_id})" \>`) + } catch (ignored) { + console.log(ignored) + } } newDiv.appendChild(newP) diff --git a/server.js b/server.js index b41ce14..f1dbd49 100644 --- a/server.js +++ b/server.js @@ -663,7 +663,7 @@ router.get("/api/getPostsLowerThan", async function(req,res) { router.get("/api/getPost", async function(req,res) { res.set("Access-Control-Allow-Origin","*") let arg = req.query.id - let sql = `select post_user_name,post_text,post_time,post_special_text,post_id,post_from_bot,post_reply_id from ipost.posts where post_id=?;` + let sql = `select post_user_name,post_text,post_time,post_special_text,post_id,post_from_bot,post_reply_id,post_receiver_name from ipost.posts where post_id=?;` con.query(sql, [arg], function (err, result) { if (err) throw err; if(result[0]) { diff --git a/views/settings.html b/views/settings.html index 9773394..fb61df7 100644 --- a/views/settings.html +++ b/views/settings.html @@ -59,7 +59,7 @@
-
+
Cross-Channel Reply