From 10dd1f079424db98fddc1c5eba7b18eac94b6c0a Mon Sep 17 00:00:00 2001 From: Mystikfluu Date: Tue, 26 Jul 2022 11:43:46 +0200 Subject: [PATCH] enhanced reply handling --- js/posts.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/js/posts.js b/js/posts.js index dd23d9d..6e3e5b4 100644 --- a/js/posts.js +++ b/js/posts.js @@ -166,6 +166,7 @@ async function createPost(username,text,time,specialtext,postid,isbot,reply_id,a const reply_username = decodeURIComponent(reply_obj.post_user_name) const reply_username_text = document.createTextNode(reply_username) const reply_text = decodeURIComponent(reply_obj.post_text) + const reply_channel = reply_obj.post_receiver_name replyAvatar.width=10; replyAvatar.height=10; replyAvatar.classList.add("avatar") @@ -181,6 +182,18 @@ async function createPost(username,text,time,specialtext,postid,isbot,reply_id,a 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() + } + } + }) + replyDiv.appendChild(replyA) newDiv.appendChild(replyDiv) @@ -288,13 +301,20 @@ document.addEventListener("visibilitychange", function() { } }); -if(window.location.href.includes("mention=")) { +if(window.location.href.includes("mention=")) { //deprecated, use message instead document.getElementById("post-text").innerText = `@${decodeURIComponent(window.location.href.split("mention=")[1])} ` } +//TODO: remove mention + if(window.location.href.includes("message=")) { document.getElementById("post-text").innerText = `${decodeURIComponent(window.location.href.split("message=")[1])} ` } +function switchChannel(channelname) { + currentChannel = channelname + socket.send(JSON.stringify({"id":"switchChannel","data":channelname})) +} + async function loadChannels() { // @@ -309,8 +329,7 @@ async function loadChannels() { let textnode = document.createTextNode(channelname) channelp.appendChild(textnode) channelp.addEventListener("click",async function(){ - currentChannel = channelname - socket.send(JSON.stringify({"id":"switchChannel","data":channelname})) + switchChannel(channelname) main() let settings = await (await fetch("/api/settings")).json()