autoloadmessages
parent
b2b15231df
commit
63252a0a86
|
@ -19,15 +19,6 @@ async function auth() {
|
||||||
window.socket.emit("authenticate", { name: window.name, message: sig });
|
window.socket.emit("authenticate", { name: window.name, message: sig });
|
||||||
}
|
}
|
||||||
|
|
||||||
function chooseThread(thread) {
|
|
||||||
window.currentThreadId = thread.id;
|
|
||||||
window.earliestMessage = null;
|
|
||||||
document.getElementById("loadmore").classList.remove("hidden");
|
|
||||||
document.getElementById("chat").classList.remove("hidden");
|
|
||||||
document.getElementById("messages").innerHTML = "";
|
|
||||||
document.getElementById("threadname").innerHTML = thread.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadKeys(keys) {
|
async function loadKeys(keys) {
|
||||||
const priv = await openpgp.readKey({ armoredKey: keys.privateKey });
|
const priv = await openpgp.readKey({ armoredKey: keys.privateKey });
|
||||||
const pub = await openpgp.readKey({ armoredKey: keys.publicKey });
|
const pub = await openpgp.readKey({ armoredKey: keys.publicKey });
|
||||||
|
@ -35,6 +26,35 @@ async function loadKeys(keys) {
|
||||||
await auth();
|
await auth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function chooseThread(thread) {
|
||||||
|
window.currentThreadId = thread.id;
|
||||||
|
window.earliestMessage = null;
|
||||||
|
document.getElementById("loadmore").classList.remove("hidden");
|
||||||
|
document.getElementById("messages").innerHTML = "";
|
||||||
|
document.getElementById("threadname").innerHTML = thread.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadMessages() {
|
||||||
|
window.socket.emit(
|
||||||
|
"get_history",
|
||||||
|
{ before: window.earliestMessage, thread: window.currentThreadId }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addThread(thread) {
|
||||||
|
const el = document.createElement("div");
|
||||||
|
el.classList.add("thread");
|
||||||
|
el.innerHTML = thread.name;
|
||||||
|
const btn = document.createElement("button");
|
||||||
|
btn.innerHTML = "choose";
|
||||||
|
btn.onclick = () => {
|
||||||
|
chooseThread(thread);
|
||||||
|
loadMessages();
|
||||||
|
};
|
||||||
|
el.appendChild(btn);
|
||||||
|
document.getElementById("threadlist").appendChild(el);
|
||||||
|
}
|
||||||
|
|
||||||
window.onload = () => {
|
window.onload = () => {
|
||||||
window.currentThreadId = 1;
|
window.currentThreadId = 1;
|
||||||
window.socket = io();
|
window.socket = io();
|
||||||
|
@ -83,16 +103,6 @@ window.onload = () => {
|
||||||
else return emitter.call(window.socket, type);
|
else return emitter.call(window.socket, type);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
function addThread(thread) {
|
|
||||||
const el = document.createElement("div");
|
|
||||||
el.classList.add("thread");
|
|
||||||
el.innerHTML = thread.name;
|
|
||||||
const btn = document.createElement("button");
|
|
||||||
btn.innerHTML = "choose";
|
|
||||||
btn.onclick = () => chooseThread(thread);
|
|
||||||
el.appendChild(btn);
|
|
||||||
document.getElementById("threadlist").appendChild(el);
|
|
||||||
}
|
|
||||||
window.socket.on("list_threads", (msg) => {
|
window.socket.on("list_threads", (msg) => {
|
||||||
document.getElementById("threadlist").innerHTML = "";
|
document.getElementById("threadlist").innerHTML = "";
|
||||||
for (let thread of msg.threads)
|
for (let thread of msg.threads)
|
||||||
|
@ -137,10 +147,7 @@ window.onload = () => {
|
||||||
document.getElementById("messages").appendChild(el);
|
document.getElementById("messages").appendChild(el);
|
||||||
};
|
};
|
||||||
document.getElementById("loadmore").onclick = e => {
|
document.getElementById("loadmore").onclick = e => {
|
||||||
window.socket.emit(
|
loadMessages();
|
||||||
"get_history",
|
|
||||||
{ before: window.earliestMessage, thread: window.currentThreadId }
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
document.getElementById("createthread").onsubmit = e => {
|
document.getElementById("createthread").onsubmit = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
<script src="/openpgp.min.js"></script>
|
||||||
|
<script src="/socket.io.min.v4.6.1.js"></script>
|
||||||
|
<script src="/chat.js"></script>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
@ -61,20 +64,18 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="threads" class="column hidden">
|
<div id="threads" class="column hidden">
|
||||||
<h1>vybe</h1>
|
<h1>vybe</h1>
|
||||||
<h1>threads</h1>
|
<h3>threads</h3>
|
||||||
|
<div id="threadlist">loading...</div>
|
||||||
<h3>create thread</h3>
|
<h3>create thread</h3>
|
||||||
<form id="createthread">
|
<form id="createthread">
|
||||||
<label for="newthreadname">thread name</label>
|
<label for="newthreadname">thread name</label>
|
||||||
<input type="text" id="newthreadname" />
|
<input type="text" id="newthreadname" />
|
||||||
<button id="submitthread" type="submit">create</button>
|
<button id="submitthread" type="submit">create</button>
|
||||||
</form>
|
</form>
|
||||||
<h3>choose existing thread</h3>
|
|
||||||
<div id="threadlist">loading...</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="chat" class="column hidden">
|
<div id="chat" class="column hidden">
|
||||||
<h3 class="thread">
|
<h3 class="thread">
|
||||||
current thread: <strong id="threadname">meow</strong>
|
current thread: <strong id="threadname">meow</strong>
|
||||||
<button id="change">change thread</button>
|
|
||||||
</h3>
|
</h3>
|
||||||
<h3>messages will appear below as they are sent</h3>
|
<h3>messages will appear below as they are sent</h3>
|
||||||
<button id="loadmore">load more messages</button>
|
<button id="loadmore">load more messages</button>
|
||||||
|
@ -84,8 +85,5 @@
|
||||||
<button type="submit" class="hidden" id="sendmsg"></button>
|
<button type="submit" class="hidden" id="sendmsg"></button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<script src="/openpgp.min.js"></script>
|
|
||||||
<script src="/chat.js"></script>
|
|
||||||
<script src="/socket.io.min.v4.6.1.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue