fix empty message

main
jerl 2024-04-15 23:53:54 -07:00
parent dff6a281c1
commit b3ae3f8a78
3 changed files with 29 additions and 29 deletions

View File

@ -46,9 +46,9 @@ function addMember() {
async function createThread(e) {
e.preventDefault();
let name = document.getElementById('newthreadname');
if (!name.value) {
name.insertAdjacentHTML('afterend', `<p>name cannot be empty</p>`);
let name = document.getElementById('newthreadname').value;
if (!name) {
document.getElementById('nameempty').classList.remove('hidden');
return;
}
let members = window.threadmembers.map(name => ({ name }));
@ -95,7 +95,7 @@ async function createThread(e) {
window.emit(
'create_thread',
{
name: name.value,
name,
permissions,
members
},
@ -119,6 +119,7 @@ function newThread() {
<form id='createthread' class='column' onsubmit=${createThread}>
<h3>create thread</h3>
<label for='newthreadname' class='heading'>thread name</label>
<p id='nameempty' class='hidden'>name cannot be empty</p>
<input type='text' id='newthreadname' />
<p id='permissions'>thread permissions</p>
<input type='radio' id='public' name='permissions' value='public' checked />

View File

@ -1,9 +1,9 @@
import { render, html } from '/uhtml.js';
function rand() {
let str = "";
let str = '';
const lookups =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("");
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.split('');
while (str.length < 16) {
const n = Math.random() * lookups.length;
str += lookups[Math.floor(n)];
@ -13,11 +13,11 @@ function rand() {
async function auth() {
const sig = await openpgp.sign({
message: new openpgp.CleartextMessage("vybe_auth " + window.session, ""),
signingKeys: window.keys.priv,
message: new openpgp.CleartextMessage('vybe_auth ' + window.session, ''),
signingKeys: window.keys.priv
});
window.socket.emit(
"authenticate",
'authenticate',
{ name: window.name, message: sig },
msg => {
let register = document.getElementById('register');
@ -35,7 +35,7 @@ async function auth() {
}
render(document.body, html`
<div id="register" class='hidden'>
<div id='register' class='hidden'>
<h1>welcome to vybe</h1>
<h3>a communication network (beta)</h3>
<p>
@ -45,7 +45,7 @@ render(document.body, html`
</p>
<form onsubmit=${async e => {
e.preventDefault();
const name = document.getElementById("name").value;
const name = document.getElementById('name').value;
if (!name)
return;
const keys = await openpgp.generateKey({
@ -54,32 +54,30 @@ render(document.body, html`
const priv = await openpgp.readKey({ armoredKey: keys.privateKey });
const pub = await openpgp.readKey({ armoredKey: keys.publicKey });
window.emit(
"create_user",
'create_user',
{ name, pubkey: keys.publicKey },
(msg) => {
if (!msg.success) {
document.querySelector('#registerform').insertAdjacentHTML(
'afterend',
`<p>${msg.message}</p>`
);
document.querySelector('#message').innerText = msg.message;
return;
}
window.keys = { priv, pub };
localStorage.setItem("keys", JSON.stringify(keys));
localStorage.setItem("name", name);
localStorage.setItem('keys', JSON.stringify(keys));
localStorage.setItem('name', name);
window.name = name;
auth();
}
);
}} id="registerform">
<label for="name">username: </label>
<input id="name" type="text" />
<button id="submit" type="submit">generate keys & register</button>
}} id='registerform'>
<label for='name'>username: </label>
<input id='name' type='text' />
<button id='submit' type='submit'>generate keys & register</button>
</form>
<p id='message'></p>
</div>
`);
const gensession = async () => {
async function gensession() {
window.session = rand();
window.emit = (type, data, callback) =>
@ -91,16 +89,16 @@ const gensession = async () => {
},
callback
);
};
}
window.onload = async () => {
window.socket = io();
await gensession();
let keys = localStorage.getItem("keys");
let keys = localStorage.getItem('keys');
if (keys) {
window.name = localStorage.getItem("name");
window.name = localStorage.getItem('name');
keys = JSON.parse(keys);
window.keys = {
priv: await openpgp.readKey({ armoredKey: keys.privateKey }),
@ -111,9 +109,9 @@ window.onload = async () => {
else
document.getElementById('register').classList.remove('hidden');
window.socket.io.on("reconnect", async attempt => {
window.socket.io.on('reconnect', async attempt => {
await gensession();
if (localStorage.getItem("keys"))
if (localStorage.getItem('keys'))
await auth();
});
};

View File

@ -64,10 +64,11 @@
}
#register {
margin-inline: 14px;
max-width: 800px;
}
.thread:hover,
.tab:hover {
background-color: #3b3b3b;
background-color: #303030;
}
.tab.active,
.thread.active,