~dricottone/blog

e53e7c8e51d7a1c6f5f83ba5fd9e0c80ed154e22 — Dominic Ricottone 1 year, 8 months ago 5067427
Chat fixes

Input fields now clear on reload of the web page.

Empty messages now can't be sent. Need to create some UI indicator of
the error, but for now the error is logged to the console at least.
2 files changed, 13 insertions(+), 7 deletions(-)

M layouts/shortcodes/chat.html
M static/js/chat.js
M layouts/shortcodes/chat.html => layouts/shortcodes/chat.html +2 -2
@@ 11,7 11,7 @@
  <button onclick="togglePassword()">Password</button>
  <div id="passwd-content" class="hidden">
    <p>To enable symmetric encryption, enter a password into this text box.</p>
    <input id="passwd-input" type="text">
    <input id="passwd-input" autocomplete="off" type="text">
    <button id="passwd-button">Update Key</button>

    <p>The intended recipients of your messages need to put the same password into this text box, too.</p>


@@ 21,5 21,5 @@
</div>

<ul id="chat-room"></ul>
<input id="chat-input" type="text">
<input id="chat-input" autocomplete="off" type="text">
<button id="chat-button">Send</button>

M static/js/chat.js => static/js/chat.js +11 -5
@@ 217,12 217,18 @@ document.addEventListener("DOMContentLoaded", () => {

  chatButton.onclick = async () => {
    const msg = chatInput.value;
    if (passkey == null) {
      const signed = await justSign(msg);
      socket.send(signed);
    if (msg === "") {
      console.log("cannot send an empty message");
    } else {
      const encrypted = await encryptAndSign(msg);
      socket.send(encrypted);
      chatInput.value = "";

      if (passkey == null) {
        const signed = await justSign(msg);
        socket.send(signed);
      } else {
        const encrypted = await encryptAndSign(msg);
        socket.send(encrypted);
      }
    }
  };