move reply click handling to a seperate function

This commit is contained in:
Mystikfluu 2022-07-26 15:56:30 +02:00
parent 10dd1f0794
commit 85b8754b85
3 changed files with 36 additions and 17 deletions

View File

@ -99,6 +99,28 @@ async function getavatar(username) {
return user 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) { async function createPost(username,text,time,specialtext,postid,isbot,reply_id,add_on_top) {
if(!specialtext)specialtext="" if(!specialtext)specialtext=""
const newDiv = document.createElement("div"); 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.classList.add("avatar")
replyAvatar.src = await getavatar(reply_username) replyAvatar.src = await getavatar(reply_username)
replyA.href = "#"+reply_id
replyA.appendChild(replyAvatar) replyA.appendChild(replyAvatar)
replyA.appendChild(reply_username_text) replyA.appendChild(reply_username_text)
replyA.appendChild(spacerTextNode()) replyA.appendChild(spacerTextNode())
@ -181,23 +201,22 @@ async function createPost(username,text,time,specialtext,postid,isbot,reply_id,a
replyA.appendChild(replyBr) replyA.appendChild(replyBr)
replyA.classList.add("no-link-style") replyA.classList.add("no-link-style")
// async function onclick(event) {
replyA.addEventListener("click",async function(event){ // event.preventDefault()
if(reply_channel != currentChannel) {
event.preventDefault() // }
switchChannel(reply_channel) // replyDiv.onclick = function() {
await main() // reply_link_clicked(reply_channel, reply_id)
let replied_msg = document.getElementById(reply_id) // }
if(replied_msg) {
replied_msg.scrollIntoView()
}
}
})
replyDiv.appendChild(replyA) replyDiv.appendChild(replyA)
newDiv.appendChild(replyDiv) 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) newDiv.appendChild(newP)

View File

@ -663,7 +663,7 @@ router.get("/api/getPostsLowerThan", async function(req,res) {
router.get("/api/getPost", async function(req,res) { router.get("/api/getPost", async function(req,res) {
res.set("Access-Control-Allow-Origin","*") res.set("Access-Control-Allow-Origin","*")
let arg = req.query.id 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) { con.query(sql, [arg], function (err, result) {
if (err) throw err; if (err) throw err;
if(result[0]) { if(result[0]) {

View File

@ -59,7 +59,7 @@
<br> <br>
<span id="response_pw"></span> <span id="response_pw"></span>
</div> </div>
<div> <div class="bg-light pd-great">
<input type="checkbox" id="ACCR_checkbox" onchange="setAllowCCR()"> Cross-Channel Reply <br> <input type="checkbox" id="ACCR_checkbox" onchange="setAllowCCR()"> Cross-Channel Reply <br>
<br> <br>
</div> </div>