diff --git a/web/src/App.css b/web/src/App.css index 073e184..ab68358 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -908,6 +908,57 @@ border-bottom: 1px solid var(--border-soft); } +.ts-whisper-lists-dialog { + width: 480px; +} + +.ts-whisper-lists-list { + list-style: none; + margin: 0.5rem 0 0; + padding: 0; + border: 1px solid var(--border-soft); + border-radius: 3px; + max-height: 260px; + overflow-y: auto; +} + +.ts-whisper-lists-item { + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.5rem; + padding: 0.4rem 0.5rem; + border-bottom: 1px solid var(--border-soft); + font-size: 12px; +} + +.ts-whisper-lists-item-info { + display: flex; + flex-direction: column; + min-width: 0; +} + +.ts-whisper-lists-item-name { + font-weight: 600; +} + +.ts-whisper-lists-item-detail { + color: var(--text-muted); + font-size: 11px; +} + +.ts-whisper-lists-item-actions { + display: flex; + gap: 0.4rem; + flex-shrink: 0; +} + +.ts-whisper-lists-empty { + padding: 1rem; + text-align: center; + color: var(--text-muted); +} + .ts-log-level-row { flex-wrap: wrap; } diff --git a/web/src/App.tsx b/web/src/App.tsx index eb3c41f..e11d879 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -173,6 +173,27 @@ interface MessagePreset { message: string; } +/** A saved whisper target selection. Channels/clients are matched by name when + * activated (rather than by id), since ids are only stable for the current + * connection - the same names are what a user would recognize across sessions. */ +interface WhisperList { + id: string; + name: string; + channelNames: string[]; + clientNames: string[]; +} + +const WHISPER_LISTS_KEY = "webspeak3:whisper-lists"; + +function loadWhisperLists(): WhisperList[] { + try { + const raw = localStorage.getItem(WHISPER_LISTS_KEY); + return raw ? (JSON.parse(raw) as WhisperList[]) : []; + } catch { + return []; + } +} + function loadAwayPresets(): MessagePreset[] { try { const raw = localStorage.getItem(AWAY_PRESETS_KEY); @@ -1129,6 +1150,83 @@ function WhisperHistoryDialog({ ); } +function WhisperListsDialog({ + lists, + hasCurrentSelection, + onSave, + onActivate, + onDelete, + onClose, +}: { + lists: WhisperList[]; + hasCurrentSelection: boolean; + onSave: (name: string) => void; + onActivate: (list: WhisperList) => void; + onDelete: (id: string) => void; + onClose: () => void; +}) { + const t = useT(); + const backdrop = useBackdropDismiss(onClose); + const [nameDraft, setNameDraft] = useState(""); + + const handleSave = () => { + const name = nameDraft.trim(); + if (!name || !hasCurrentSelection) return; + onSave(name); + setNameDraft(""); + }; + + return ( +
+
e.stopPropagation()}> +
+ {t("whisperLists.title")} + +
+
+
+ setNameDraft(e.target.value)} + /> + +
+
    + {lists.map((list) => ( +
  • +
    + {list.name} + + {t("whisperLists.itemDetail", { + channels: String(list.channelNames.length), + clients: String(list.clientNames.length), + })} + +
    +
    + + +
    +
  • + ))} + {lists.length === 0 &&
  • {t("whisperLists.empty")}
  • } +
+
+
+
+ +
+
+
+
+ ); +} + function ContactsDialog({ contacts, onlineClients, @@ -2043,6 +2141,8 @@ function AppInner() { const logIdRef = useRef(0); const [whisperLog, setWhisperLog] = useState([]); const [whisperHistoryOpen, setWhisperHistoryOpen] = useState(false); + const [whisperLists, setWhisperLists] = useState(() => loadWhisperLists()); + const [whisperListsOpen, setWhisperListsOpen] = useState(false); const [selfMenuOpen, setSelfMenuOpen] = useState(false); const selfMenuRef = useRef(null); const [changeNicknameOpen, setChangeNicknameOpen] = useState(false); @@ -2096,6 +2196,10 @@ function AppInner() { localStorage.setItem(CONTACTS_KEY, JSON.stringify(contacts)); }, [contacts]); + useEffect(() => { + localStorage.setItem(WHISPER_LISTS_KEY, JSON.stringify(whisperLists)); + }, [whisperLists]); + const isSenderIgnored = (senderName: string) => { const senderClient = clients.find((c) => c.name === senderName); if (!senderClient?.uid) return false; @@ -2991,6 +3095,26 @@ function AppInner() { setWhisperClientIds(new Set()); }; + const handleSaveWhisperList = (name: string) => { + const channelNames = channels.filter((c) => whisperChannelIds.has(c.id)).map((c) => c.name); + const clientNames = clients.filter((c) => whisperClientIds.has(c.id)).map((c) => c.name); + if (channelNames.length === 0 && clientNames.length === 0) return; + setWhisperLists((prev) => [...prev, { id: crypto.randomUUID(), name, channelNames, clientNames }]); + }; + + const handleActivateWhisperList = (list: WhisperList) => { + const nextChannelIds = new Set( + channels.filter((c) => list.channelNames.includes(c.name)).map((c) => c.id) + ); + const nextClientIds = new Set(clients.filter((c) => list.clientNames.includes(c.name)).map((c) => c.id)); + setWhisperChannelIds(nextChannelIds); + setWhisperClientIds(nextClientIds); + }; + + const handleDeleteWhisperList = (id: string) => { + setWhisperLists((prev) => prev.filter((list) => list.id !== id)); + }; + const handleClientContextMenu = ( e: React.MouseEvent, clientId: number, @@ -3272,7 +3396,13 @@ function AppInner() { {t("menu.extras.inviteFriend")}
-