add id-based replies
This commit is contained in:
parent
4a4a8416c5
commit
631eff5d1d
@ -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;
|
||||
|
23
js/posts.js
23
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())
|
||||
// |\>.</|
|
||||
newP.innerHTML += `<button onclick="reply('${username}')">Reply to this Post</button>`
|
||||
newP.innerHTML += `<button onclick="reply('${username}',${postid},'${post_text}')">Reply to this Post</button>`
|
||||
|
||||
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()
|
||||
|
14
server.js
14
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)
|
||||
|
@ -26,6 +26,7 @@
|
||||
<div id="scriptonly" style="display:none;">
|
||||
<div class="self">
|
||||
Username: <span class="Username" id="username-self"></span> <br>
|
||||
<span id="reply" style="display:none;" class="noselect">Replying to: <b id="reply_username"></b><small id="reply_text"></small> <button onclick="unreply()" style="color:red">X</button> </span>
|
||||
<textarea name="name" id="post-text" rows="8" cols="80"></textarea>
|
||||
<br>
|
||||
<button type="button" name="button" id="post-btn" onclick="postMessage()">Post</button>
|
||||
|
Loading…
x
Reference in New Issue
Block a user