From 389415f04d077d414cb9c38662d6998594b4a810 Mon Sep 17 00:00:00 2001 From: 3nd3r Date: Sun, 12 Apr 2026 13:33:46 -0500 Subject: [PATCH] Fix Violet PM: echo user message + add session restore on refresh --- app.py | 3 +++ static/chat.js | 25 +++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 82d1e36..6a02d6e 100644 --- a/app.py +++ b/app.py @@ -620,6 +620,9 @@ def on_pm_message(data): emit("pm_message", {"from": AI_BOT_NAME, "text": "ai_limit_reached", "room": room, "system": True}, to=sid) return + # Echo the user's own message back so it appears in their chat + emit("pm_message", payload, to=sid) + transit_key = data.get("transit_key", "") if not all([ciphertext, nonce_val, transit_key]): # Plaintext fallback for admins without crypto keys diff --git a/static/chat.js b/static/chat.js index 43ccd79..5547984 100644 --- a/static/chat.js +++ b/static/chat.js @@ -118,12 +118,25 @@ joinForm.addEventListener("submit", async (e) => { window.addEventListener("DOMContentLoaded", () => { const token = localStorage.getItem("sexychat_token"); if (token) { - // We have a token, notify the join screen but wait for user to click "Enter" - // to derive crypto key if they want to. Actually, for UX, if we have a token - // we can try a "restore" join which might skip password entry. - // But for encryption, we NEED that password to derive the key. - // Let's keep it simple: if you have a token, you still need to log in to - // re-derive your E2E key. + // Auto-restore session from stored JWT + joinBtn.disabled = true; + joinBtn.innerText = "Restoring session..."; + socket.connect(); + socket.emit("join", { mode: "restore" }); + + // If restore fails, reset the form so user can log in manually + const restoreTimeout = setTimeout(() => { + joinBtn.disabled = false; + joinBtn.innerText = "Enter the Room"; + }, 5000); + + const origJoined = socket.listeners("joined"); + socket.once("joined", () => clearTimeout(restoreTimeout)); + socket.once("error", () => { + clearTimeout(restoreTimeout); + joinBtn.disabled = false; + joinBtn.innerText = "Enter the Room"; + }); } });