diff --git a/createSchema.sql b/createSchema.sql index 30f123d..fddc576 100644 --- a/createSchema.sql +++ b/createSchema.sql @@ -13,6 +13,7 @@ CREATE TABLE `users` ( `User_Bio` varchar(100) DEFAULT 'wow such empty', `User_Avatar` varchar(100) DEFAULT NULL, `User_PublicKey` varchar(830) DEFAULT NULL, + `User_PrivateKey` blob, PRIMARY KEY (`User_ID`,`User_Name`), UNIQUE KEY `User_Name_UNIQUE` (`User_Name`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; @@ -26,5 +27,6 @@ CREATE TABLE `posts` ( `post_special_text` varchar(100) DEFAULT NULL, `post_receiver_name` varchar(100) DEFAULT NULL, `post_from_bot` tinyint DEFAULT '0', + `post_reply_id` bigint unsigned DEFAULT NULL, PRIMARY KEY (`post_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; diff --git a/js/posts.js b/js/posts.js index 11ef108..dc8b7dd 100644 --- a/js/posts.js +++ b/js/posts.js @@ -5,6 +5,8 @@ const wss_server = "wss://ipost.tk" const wss_port = "443" const wss_URI = wss_server + ":" + wss_port +var reply_id = -1 + let socket = new WebSocket(wss_URI); socket.addEventListener("message", function (event) { if(wss_server == event.origin) { @@ -25,7 +27,7 @@ async function postMessage() { alert(`Error, your message cant contain more than 1000 characters! (${len})`) return } - let r = await post("/api/post",{"message":document.getElementById("post-text").value}) + let r = await post("/api/post",{"message":document.getElementById("post-text").value,"reply_id":reply_id}) if(window.location.href.split("?mention=")[1])location.replace('/posts'); document.getElementById("post-text").value="" } @@ -103,7 +105,7 @@ async function createPost(username,text,time,specialtext,postid,isbot) { } newP.appendChild(spacerTextNode()) // |\>.Reply to this Post` + newP.innerHTML += `` newDiv.appendChild(newP) newDiv.innerHTML += filterPost(text) @@ -124,8 +126,7 @@ async function main(){ document.getElementById("username-self").innerText = username } - let index = 0 - let all_posts = await (await fetch(`/api/getPosts/${index}`)).json() + let all_posts = await (await fetch(`/api/getPosts`)).json() if(!all_posts)return; document.getElementById("posts").innerHTML = "" for(i in all_posts) { @@ -162,9 +163,17 @@ async function main(){ document.getElementById("scriptonly").style = "" } -function reply(username) { - if(document.getElementById("post-text").value.length >= 5)document.getElementById("post-text").value += "\n" - document.getElementById("post-text").value += `_@_${username} ` +function reply(username,postid,posttext) { + document.getElementById("reply").style = "" + document.getElementById("reply_username").innerText = username + document.getElementById("reply_text").innerHTML = filterPost(text) + // if(document.getElementById("post-text").value.length >= 5)document.getElementById("post-text").value += "\n" + // document.getElementById("post-text").value += `_@_${username} ` +} + +function unreply() { + document.getElementById("reply").style = "display:none;" + reply_id = -1 } main() diff --git a/server.js b/server.js index f81dc94..4196a60 100644 --- a/server.js +++ b/server.js @@ -481,6 +481,12 @@ router.post("/api/post", async function(req,res) { res.json({"error":"no message to post"}) return } + let reply_id + if(!req.body.reply_id) { + reply_id = -1 + } else { + reply_id = req.body.reply_id + } req.body.message = encodeURIComponent(req.body.message.trim()) req.body.receiver = encodeURIComponent(req.body.receiver||"") if(req.body.receiver == "")req.body.receiver="everyone" @@ -490,8 +496,8 @@ router.post("/api/post", async function(req,res) { return } - let sql = `insert into zerotwohub.posts (post_user_name,post_text,post_time,post_receiver_name,post_from_bot) values (?,?,?,?,?);` - let values = [encodeURIComponent(res.locals.username),req.body.message,Date.now(),req.body.receiver,res.locals.isbot] + let sql = `insert into zerotwohub.posts (post_user_name,post_text,post_time,post_receiver_name,post_from_bot,post_reply_id) values (?,?,?,?,?,?);` + let values = [encodeURIComponent(res.locals.username),req.body.message,Date.now(),req.body.receiver,res.locals.isbot,reply_id] con.query(sql, values, function (err, result) { if (err) throw err; @@ -510,7 +516,7 @@ router.get("/api/getPosts/*", async function(req,res) { router.get("/api/getPosts", async function(req,res) { res.set("Access-Control-Allow-Origin","*") - let sql = `select post_user_name,post_text,post_time,post_special_text,post_id,post_from_bot from zerotwohub.posts where (post_receiver_name is null or post_receiver_name = 'everyone') group by post_id order by post_id desc limit 30;` + let sql = `select post_user_name,post_text,post_time,post_special_text,post_id,post_from_bot,post_reply_id from zerotwohub.posts where (post_receiver_name is null or post_receiver_name = 'everyone') group by post_id order by post_id desc limit 30;` con.query(sql, [], function (err, result) { if (err) throw err; res.json(result) @@ -519,7 +525,7 @@ router.get("/api/getPosts", async function(req,res) { router.get("/api/getPersonalPosts", async function(req,res) { res.set("Access-Control-Allow-Origin","") - let sql = `select post_user_name,post_text,post_time,post_special_text,post_id,post_from_bot from zerotwohub.posts where (post_receiver_name = ?) order by post_id desc;` + let sql = `select post_user_name,post_text,post_time,post_special_text,post_id,post_from_bot,post_reply_id from zerotwohub.posts where (post_receiver_name = ?) order by post_id desc;` con.query(sql, [encodeURIComponent(res.locals.username)], function (err, result) { if (err) throw err; res.json(result) diff --git a/views/posts.html b/views/posts.html index 07c03a0..2ddbc43 100644 --- a/views/posts.html +++ b/views/posts.html @@ -26,6 +26,7 @@