From fa030a32b784f9d3902be2807e3c8ce462d10c73 Mon Sep 17 00:00:00 2001 From: 3nd3r Date: Sun, 12 Apr 2026 14:41:42 -0500 Subject: [PATCH] Fix admin panel: live AI access toggle, auto-refresh after actions - Grant/Revoke AI button now notifies target user live via ai_unlock event - ai_unlock handler updated to support both grant and revoke - Admin panel auto-refreshes user/ban/mute lists after any action --- app.py | 5 +++++ static/chat.js | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 0e54a88..01d255d 100644 --- a/app.py +++ b/app.py @@ -1074,6 +1074,11 @@ def on_admin_toggle_ai(data): target_sid = username_to_sid.get(target_user.username.lower()) if target_sid and target_sid in connected_users: connected_users[target_sid]["has_ai_access"] = target_user.has_ai_access + # Notify target so their UI updates immediately + socketio.emit("ai_unlock", { + "has_ai_access": target_user.has_ai_access, + "msg": "Premium access granted! Unlimited Violet." if target_user.has_ai_access else "Premium access revoked." + }, to=target_sid) status = "granted" if target_user.has_ai_access else "revoked" emit("admin_action_ok", {"msg": f"AI access {status} for {target_user.username}"}) diff --git a/static/chat.js b/static/chat.js index 09b01e1..e4030fb 100644 --- a/static/chat.js +++ b/static/chat.js @@ -376,10 +376,10 @@ socket.on("ai_response", async (data) => { }); socket.on("ai_unlock", (data) => { - state.hasAiAccess = true; + state.hasAiAccess = data.has_ai_access !== undefined ? data.has_ai_access : true; updateVioletBadge(); paywallModal.classList.add("hidden"); - addMessage("ai-violet", { system: true, text: data.msg }); + if (data.msg) addMessage("ai-violet", { system: true, text: data.msg }); }); socket.on("ignore_status", (data) => { @@ -875,7 +875,13 @@ function adminToast(msg) { setTimeout(() => t.classList.add("hidden"), 2500); } -socket.on("admin_action_ok", (data) => adminToast(data.msg)); +socket.on("admin_action_ok", (data) => { + adminToast(data.msg); + // Refresh the admin user list so buttons update + socket.emit("admin_get_users"); + socket.emit("admin_get_bans"); + socket.emit("admin_get_mutes"); +}); // ── Users pane ───────────────────────────────────────────────────────────