main
jerl 2023-05-28 11:43:37 -07:00
parent 63252a0a86
commit 85d5297c94
3 changed files with 16 additions and 19 deletions

View File

@ -2,12 +2,8 @@
very very unfinished !! right now it can do a chatroom very very unfinished !! right now it can do a chatroom
## setup ## usage
currently uses sqlite! install sqlite for your machine then do the following `npm install`
then
```bash `node index.js`
sqlite3 vybe.db < db/1-init.sql
```
then you can `yarn install` and `node index.js`

View File

@ -29,7 +29,6 @@ async function loadKeys(keys) {
function chooseThread(thread) { function chooseThread(thread) {
window.currentThreadId = thread.id; window.currentThreadId = thread.id;
window.earliestMessage = null; window.earliestMessage = null;
document.getElementById("loadmore").classList.remove("hidden");
document.getElementById("messages").innerHTML = ""; document.getElementById("messages").innerHTML = "";
document.getElementById("threadname").innerHTML = thread.name; document.getElementById("threadname").innerHTML = thread.name;
} }
@ -50,6 +49,7 @@ function addThread(thread) {
btn.onclick = () => { btn.onclick = () => {
chooseThread(thread); chooseThread(thread);
loadMessages(); loadMessages();
document.getElementById("loadmore").classList.remove("hidden");
}; };
el.appendChild(btn); el.appendChild(btn);
document.getElementById("threadlist").appendChild(el); document.getElementById("threadlist").appendChild(el);
@ -67,10 +67,8 @@ window.onload = () => {
strong.textContent = msg.name + ': '; strong.textContent = msg.name + ': ';
el.append(strong, msg.message); el.append(strong, msg.message);
document.getElementById("messages").appendChild(el); document.getElementById("messages").appendChild(el);
if (!window.earliestMessage) window.earliestMessage = msg.id; if (!window.earliestMessage)
}); window.earliestMessage = msg.id;
window.socket.on("send_message", (msg) => {
if (!window.earliestMessage) window.earliestMessage = msg.id;
}); });
window.socket.on("get_history", (msg) => { window.socket.on("get_history", (msg) => {
if (msg.messages.length > 0) { if (msg.messages.length > 0) {
@ -84,7 +82,8 @@ window.onload = () => {
document.getElementById("messages").prepend(el); document.getElementById("messages").prepend(el);
} }
} }
if (!msg.more) document.getElementById("loadmore").classList.add("hidden"); if (!msg.more)
document.getElementById("loadmore").classList.add("hidden");
}); });
window.socket.on("authenticate", (msg) => { window.socket.on("authenticate", (msg) => {
if (msg.success) { if (msg.success) {
@ -141,10 +140,6 @@ window.onload = () => {
thread: window.currentThreadId, thread: window.currentThreadId,
}); });
document.getElementById("msg").value = ""; document.getElementById("msg").value = "";
const el = document.createElement("div");
el.classList.add("message");
el.innerHTML = `<strong>${window.name}: </strong>${msg}`;
document.getElementById("messages").appendChild(el);
}; };
document.getElementById("loadmore").onclick = e => { document.getElementById("loadmore").onclick = e => {
loadMessages(); loadMessages();

View File

@ -6,7 +6,13 @@ const create_thread = async (msg, respond, socket, io) => {
if (!msg.name) { if (!msg.name) {
return respond({ return respond({
success: false, success: false,
message: "Thread name required", message: "thread name required",
});
}
if (msg.name.length > 200) {
return respond({
success: false,
message: "thread name 200 chars max",
}); });
} }
// add to db // add to db