move reply click handling to a seperate function
This commit is contained in:
parent
10dd1f0794
commit
85b8754b85
49
js/posts.js
49
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)
|
||||
|
@ -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]) {
|
||||
|
@ -59,7 +59,7 @@
|
||||
<br>
|
||||
<span id="response_pw"></span>
|
||||
</div>
|
||||
<div>
|
||||
<div class="bg-light pd-great">
|
||||
<input type="checkbox" id="ACCR_checkbox" onchange="setAllowCCR()"> Cross-Channel Reply <br>
|
||||
<br>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user