From 372f12dbca9c5c56ebd85e1171c05a0ae5023ce3 Mon Sep 17 00:00:00 2001 From: Adam French Date: Mon, 26 Oct 2026 17:02:57 +0000 Subject: [PATCH] Split chat into public and private widgets, Places out of Collage, hide stamp scrollbars Chat.vue (public) and PrivateChat.vue (admins only) are now separate canvas widgets over a shared ChatPanel.vue, replacing the tabbed widget. The messages store counts connect()/disconnect() so both can share one socket, and reopens it on an admin change itself so two mounted chats reconnect once. Places is its own widget (views/home/Places.vue); Collage is just the slideshow. The stamp wall hides its scrollbars. Co-Authored-By: Claude Opus 5.5 --- vue/src/components/util/Chat.vue | 334 +----------------------- vue/src/components/util/ChatPanel.vue | 275 +++++++++++++++++++ vue/src/components/util/PrivateChat.vue | 24 ++ vue/src/stores/messages.js | 47 +++- vue/src/stores/places.js | 2 +- vue/src/views/home/Collage.vue | 109 +------- vue/src/views/home/Places.vue | 67 +++++ vue/src/views/home/PlacesTable.vue | 2 +- vue/src/views/home/Stamps.vue | 15 +- vue/src/views/home3/widgetRegistry.js | 2 + 10 files changed, 431 insertions(+), 446 deletions(-) create mode 100644 vue/src/components/util/ChatPanel.vue create mode 100644 vue/src/components/util/PrivateChat.vue create mode 100644 vue/src/views/home/Places.vue diff --git a/vue/src/components/util/Chat.vue b/vue/src/components/util/Chat.vue index 721be72..a00c723 100644 --- a/vue/src/components/util/Chat.vue +++ b/vue/src/components/util/Chat.vue @@ -1,336 +1,12 @@ - - diff --git a/vue/src/components/util/ChatPanel.vue b/vue/src/components/util/ChatPanel.vue new file mode 100644 index 0000000..0a8129e --- /dev/null +++ b/vue/src/components/util/ChatPanel.vue @@ -0,0 +1,275 @@ + + + + + diff --git a/vue/src/components/util/PrivateChat.vue b/vue/src/components/util/PrivateChat.vue new file mode 100644 index 0000000..253c556 --- /dev/null +++ b/vue/src/components/util/PrivateChat.vue @@ -0,0 +1,24 @@ + + + diff --git a/vue/src/stores/messages.js b/vue/src/stores/messages.js index 2e3f787..2c2162a 100644 --- a/vue/src/stores/messages.js +++ b/vue/src/stores/messages.js @@ -1,14 +1,20 @@ /** - * WebSocket-backed chat, used by components/util/Chat.vue. + * WebSocket-backed chat, used by components/util/ChatPanel.vue (behind both the + * public Chat and the admins-only PrivateChat widgets). * * Owns one socket at a time, auto-reconnects with exponential backoff (1s * doubling to a 30s ceiling, reset on a successful open) and refuses to reconnect - * after an intentional disconnect(). + * after an intentional close. + * + * Both chat widgets can be on screen at once and share the socket (it carries + * both channels), so connect()/disconnect() are counted: the socket opens with + * the first widget and closes with the last. */ import { defineStore } from "pinia"; -import { ref, computed } from "vue"; +import { ref, computed, watch } from "vue"; import { uploadFile } from "@/uploads"; +import { useAuthStore } from "@/stores/auth"; /** * Same-origin ws:// or wss:// URL for the chat socket, derived from the page's @@ -32,11 +38,25 @@ export const useMessagesStore = defineStore("messages", () => { let intentionalClose = false; let reconnectDelay = INITIAL_RECONNECT_DELAY_MS; let reconnectTimer = null; + // How many mounted widgets want the socket open. + let users = 0; const messagesCount = computed(() => messages.value.length); - /** Open the socket (no-op if one already exists) and arm auto-reconnect. */ + /** Register a widget that needs the socket, opening it if it is the first. */ function connect() { + users++; + open(); + } + + /** Release a connect(); the socket closes once no widget holds it. */ + function disconnect() { + users = Math.max(0, users - 1); + if (users === 0) close(); + } + + /** Open the socket (no-op if one already exists) and arm auto-reconnect. */ + function open() { if (socket.value) return; intentionalClose = false; clearTimeout(reconnectTimer); @@ -93,7 +113,7 @@ export const useMessagesStore = defineStore("messages", () => { socket.value = null; if (!intentionalClose) { reconnectTimer = setTimeout(() => { - connect(); + open(); }, reconnectDelay); reconnectDelay = Math.min(reconnectDelay * 2, MAX_RECONNECT_DELAY_MS); } @@ -103,9 +123,9 @@ export const useMessagesStore = defineStore("messages", () => { /** * Close the socket and suppress auto-reconnect. Clearing `socket.value` * *before* calling close() is what makes the onclose guard above see a stale - * socket, so a later connect() is not fought over by the dying one. + * socket, so a later open() is not fought over by the dying one. */ - function disconnect() { + function close() { intentionalClose = true; clearTimeout(reconnectTimer); if (!socket.value) return; @@ -115,6 +135,19 @@ export const useMessagesStore = defineStore("messages", () => { ws.close(); } + // Admin status is fixed when the socket connects (from the auth cookies), so + // reopen after a login/logout to pick up or drop private messages. Here + // rather than in the widgets so two mounted chats reconnect once, not twice. + const auth = useAuthStore(); + watch( + () => !!auth.user.admin, + () => { + if (users === 0) return; + close(); + open(); + }, + ); + /** Send a chat line. Silently drops it if the socket is not open. */ function sendMessage(text, isPrivate = false) { if (!socket.value || !isConnected.value) return; diff --git a/vue/src/stores/places.js b/vue/src/stores/places.js index 66dcedb..fd74b4d 100644 --- a/vue/src/stores/places.js +++ b/vue/src/stores/places.js @@ -1,5 +1,5 @@ /** - * Places-to-go list (the "Places" tab inside the Collage widget) β€” full CRUD, + * Places-to-go list (the Places widget, views/home/Places.vue) β€” full CRUD, * built on createCrudStore(). * * Not part of the homeData query because it is sign-in-only; PlacesTable.vue diff --git a/vue/src/views/home/Collage.vue b/vue/src/views/home/Collage.vue index d24d143..517e64a 100644 --- a/vue/src/views/home/Collage.vue +++ b/vue/src/views/home/Collage.vue @@ -1,125 +1,24 @@ diff --git a/vue/src/views/home/Places.vue b/vue/src/views/home/Places.vue new file mode 100644 index 0000000..7e00034 --- /dev/null +++ b/vue/src/views/home/Places.vue @@ -0,0 +1,67 @@ + + + + + diff --git a/vue/src/views/home/PlacesTable.vue b/vue/src/views/home/PlacesTable.vue index 34c5e2e..c37ee52 100644 --- a/vue/src/views/home/PlacesTable.vue +++ b/vue/src/views/home/PlacesTable.vue @@ -1,6 +1,6 @@