add prototype emoji system
This commit is contained in:
parent
7ceb781f55
commit
90c69ef126
BIN
images/emoji/eyes.png
Normal file
BIN
images/emoji/eyes.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
images/emoji/moyai.png
Normal file
BIN
images/emoji/moyai.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 778 B |
@ -28,7 +28,12 @@ function filterMentions(text) {
|
||||
return text.replace(mentionregex,`<span><a href="/users/$1" class="mention">$1</a></span> `)
|
||||
}
|
||||
|
||||
const allregex = /(```([^```]*)```)|(\n)|(~([^~]*)~)|(\*\*([^\*]*)\*\*)|(\*([^\*]*)\*)|(@[^\s]*)/gi
|
||||
const emojiregex = /:([^:\s]*):/gi
|
||||
function emojify(text) {
|
||||
return text.replace(emojiregex,"<img class='emoji' src='/images/emoji/$1.png' alt='$1' width=20 height=20/>")
|
||||
}
|
||||
|
||||
const allregex = /(```([^```]*)```)|(\n)|(~([^~]*)~)|(\*\*([^\*]*)\*\*)|(\*([^\*]*)\*)|(@[^\s]*)|(:([^:\s]*):)/gi
|
||||
|
||||
const cdblregex = /```([^```]*)```/gi
|
||||
|
||||
@ -49,6 +54,7 @@ function filterPost(text){
|
||||
|
||||
out = newlineify(out)
|
||||
out = urlify(out)
|
||||
out = emojify(out)
|
||||
out = filterMentions(out)
|
||||
out = crossout(out)
|
||||
out = boldify(out)
|
||||
|
55
js/posts.js
55
js/posts.js
@ -20,7 +20,7 @@ socket.addEventListener("message", async function (event) {
|
||||
let message = ds.message
|
||||
let item = ds.data
|
||||
let username = decodeURIComponent(item.post_user_name)
|
||||
if(message == "new_post") {
|
||||
if(message == "new_post" && decodeURIComponent(item.post_receiver_name) == currentChannel) {
|
||||
await createPost(decodeURIComponent(item.post_user_name),decodeURIComponent(item.post_text),item.post_time,item.post_special_text,highest_id+1,item.post_from_bot,item.post_reply_id,true)
|
||||
if(user["username"]!=username)mainNoti(username)
|
||||
|
||||
@ -49,7 +49,21 @@ async function postMessage() {
|
||||
setTimeout(function(){
|
||||
cd = true
|
||||
},400)
|
||||
let r = await post("/api/post",{"message":document.getElementById("post-text").value,"reply_id":reply_id,"receiver":currentChannel,"pid": posting_id})
|
||||
let formdata = new FormData()
|
||||
|
||||
formdata.append("message",document.getElementById("post-text").value)
|
||||
formdata.append("reply_id",reply_id)
|
||||
formdata.append("receiver",currentChannel)
|
||||
formdata.append("pid",posting_id)
|
||||
for(let i in files) {
|
||||
console.log("processed file",files[i].name);
|
||||
formdata.append("file_"+i,files[i])
|
||||
}
|
||||
files = []
|
||||
|
||||
let r = await fetch("/api/post", {
|
||||
method: "POST", body: formdata
|
||||
});
|
||||
posting_id = undefined
|
||||
update_pid()
|
||||
if(window.location.href.split("?mention=")[1])location.replace('/posts');
|
||||
@ -365,6 +379,43 @@ async function loadChannels() {
|
||||
}
|
||||
}
|
||||
|
||||
var files = []
|
||||
|
||||
function addFile(file) {
|
||||
if(file.size > 100000) {
|
||||
console.log("file is too big: ", file.name, file.type, file.size);
|
||||
return;
|
||||
}
|
||||
if(files.length >= 5) {
|
||||
console.log("too many files already: ", files);
|
||||
return;
|
||||
}
|
||||
files[files.length]=file
|
||||
console.log("File added: ", file.name, file.type, file.size);
|
||||
}
|
||||
|
||||
function dropHandler(ev) {
|
||||
console.log("file dropped");
|
||||
|
||||
ev.preventDefault();
|
||||
|
||||
if (ev.dataTransfer.items) {
|
||||
// Use DataTransferItemList interface to access the file(s)
|
||||
[...ev.dataTransfer.items].forEach((item, i) => {
|
||||
// If dropped items aren't files, reject them
|
||||
if (item.kind === 'file') {
|
||||
const file = item.getAsFile();
|
||||
addFile(file)
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Use DataTransfer interface to access the file(s)
|
||||
[...ev.dataTransfer.files].forEach((file, i) => {
|
||||
addFile(file)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
setInterval(update_pid,30000)
|
||||
if(posting_id=="")update_pid()
|
||||
|
@ -43,7 +43,14 @@ export const setup = function (router, con, server) {
|
||||
else {
|
||||
reply_id = req.body.reply_id;
|
||||
}
|
||||
if ((typeof req.body.reply_id) != "number") {
|
||||
if(typeof reply_id == "string") {
|
||||
reply_id = parseInt(reply_id)
|
||||
if(isNaN(reply_id)) {
|
||||
res.json({ "error": "no valid reply id given" });
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ((typeof reply_id) != "number") {
|
||||
res.json({ "error": "no valid reply id given" });
|
||||
return;
|
||||
}
|
||||
@ -82,11 +89,8 @@ export const setup = function (router, con, server) {
|
||||
data: post_obj
|
||||
};
|
||||
let messagestr = JSON.stringify(message);
|
||||
let channel = decodeURIComponent(req.body.receiver);
|
||||
server.wss.clients.forEach(async function (ws) {
|
||||
if (ws.channel == channel) {
|
||||
ws.send(messagestr);
|
||||
}
|
||||
ws.send(messagestr);
|
||||
});
|
||||
res.json({ "success": "successfully posted message" });
|
||||
console.log(5, `posted new message by ${res.locals.username} : ${req.body.message}`);
|
||||
|
18
server.js
18
server.js
@ -433,23 +433,7 @@ settingshandlersetup(router, con, commonfunctions);
|
||||
const get_pid = postsetup(router, con, commonfunctions);
|
||||
dmsPersonalMessagessetup(router, con, commonfunctions);
|
||||
const get_dmpid = dmspostsetup(router, con, commonfunctions);
|
||||
// const toLoad = [
|
||||
// "api/options.js",
|
||||
// "api/all.js",
|
||||
// "api/settingshandler.js",
|
||||
// "api/post.js",
|
||||
// "api/dms/PersonalMessages.js",
|
||||
// "api/dms/post.js",
|
||||
// ]
|
||||
// for (let i = 0; i < toLoad.length; i++) {
|
||||
// require("./routes/"+toLoad[i]).setup(router,con,commonfunctions)
|
||||
// }
|
||||
// let options = require("./routes/api/options.js")
|
||||
// options.setup(router,con,commonfunctions)
|
||||
// let apiALL = require("./routes/api/all.js")
|
||||
// apiALL.setup(router,con,commonfunctions)
|
||||
// let settingshandler = require("./routes/api/settingshandler.js")
|
||||
// settingshandler.setup(router,con,commonfunctions)
|
||||
|
||||
router.get("/api/search", async function (req, res) {
|
||||
res.set("Access-Control-Allow-Origin", "");
|
||||
let type = req.query.type;
|
||||
|
@ -12,9 +12,7 @@
|
||||
<%- htmlescapejs %>
|
||||
<%- markdownjs %>
|
||||
<%- warnmessagejs %>
|
||||
let channels = <%- JSON.stringify(await getChannels()) %>
|
||||
let user = <%- JSON.stringify(user) %>
|
||||
var posting_id = "<%- getPID() %>"
|
||||
let channels = <%- JSON.stringify(await getChannels()) %>,user = <%- JSON.stringify(user) %>,posting_id = "<%- getPID() %>"
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
@ -30,7 +28,7 @@
|
||||
To log in, please visit <a href="/login">The login page</a> <br>
|
||||
If you are new to here, please visit <a href="/register">The register page</a> <br>
|
||||
</div>
|
||||
<div id="scriptonly" style="display:none;">
|
||||
<div id="scriptonly" style="display:none;" ondrop="dropHandler(event)">
|
||||
<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> <br>
|
||||
|
Loading…
x
Reference in New Issue
Block a user