mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 09:52:50 +08:00
Add Identitäten (identity) management dialog
Replaces the single flat identity key with a list of named identities you can add, rename, delete, and switch between (each keeps its own tsclientlib identity blob, generated lazily on first connect). The Connect dialog's identity dropdown, previously a disabled "Standard" placeholder, now reflects and can switch the active one too. Existing users' single stored identity migrates automatically into the new list. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
46ae5b120e
commit
a300daedeb
3 files changed
+235
-5
No files matched your search
@@ -959,6 +959,44 @@
|
|||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ts-identities-dialog {
|
||||||
|
width: 460px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ts-identities-list {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: 1px solid var(--border-soft);
|
||||||
|
border-radius: 3px;
|
||||||
|
max-height: 260px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ts-identities-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0.35rem 0.5rem;
|
||||||
|
border-bottom: 1px solid var(--border-soft);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ts-identities-item-active {
|
||||||
|
background: var(--accent-soft, rgba(78, 161, 247, 0.15));
|
||||||
|
}
|
||||||
|
|
||||||
|
.ts-identities-name {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ts-identities-status {
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-size: 11px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
.ts-log-level-row {
|
.ts-log-level-row {
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|||||||
+181
-5
@@ -69,6 +69,40 @@ const LAST_NICKNAME_KEY = "webspeak3:last-nickname";
|
|||||||
/** Identity persisted across sessions so the server sees the same client UID
|
/** Identity persisted across sessions so the server sees the same client UID
|
||||||
* each time, instead of a fresh one being generated per connection. */
|
* each time, instead of a fresh one being generated per connection. */
|
||||||
const IDENTITY_KEY = "webspeak3:identity";
|
const IDENTITY_KEY = "webspeak3:identity";
|
||||||
|
const IDENTITIES_KEY = "webspeak3:identities";
|
||||||
|
const ACTIVE_IDENTITY_KEY = "webspeak3:active-identity";
|
||||||
|
|
||||||
|
interface Identity {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
/** Opaque tsclientlib identity blob - null until the first successful connect generates one. */
|
||||||
|
blob: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// One-time migration from the old single flat identity key to a list of named
|
||||||
|
// identities (so users can maintain more than one persona), and to seed a
|
||||||
|
// default entry for users who never had one either. Runs once at module load.
|
||||||
|
(function ensureIdentitiesSeeded() {
|
||||||
|
if (localStorage.getItem(IDENTITIES_KEY) !== null) return;
|
||||||
|
const legacyBlob = localStorage.getItem(IDENTITY_KEY);
|
||||||
|
const id = crypto.randomUUID();
|
||||||
|
const identities: Identity[] = [{ id, name: "Standard", blob: legacyBlob }];
|
||||||
|
localStorage.setItem(IDENTITIES_KEY, JSON.stringify(identities));
|
||||||
|
localStorage.setItem(ACTIVE_IDENTITY_KEY, id);
|
||||||
|
localStorage.removeItem(IDENTITY_KEY);
|
||||||
|
})();
|
||||||
|
|
||||||
|
function loadIdentities(): Identity[] {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(IDENTITIES_KEY);
|
||||||
|
const parsed = raw ? (JSON.parse(raw) as Identity[]) : [];
|
||||||
|
if (parsed.length > 0) return parsed;
|
||||||
|
} catch {
|
||||||
|
// fall through
|
||||||
|
}
|
||||||
|
return [{ id: crypto.randomUUID(), name: "Standard", blob: null }];
|
||||||
|
}
|
||||||
|
|
||||||
const FAVORITES_KEY = "webspeak3:favorites";
|
const FAVORITES_KEY = "webspeak3:favorites";
|
||||||
const INPUT_DEVICE_KEY = "webspeak3:input-device";
|
const INPUT_DEVICE_KEY = "webspeak3:input-device";
|
||||||
const PLAYBACK_VOLUME_KEY = "webspeak3:playback-volume";
|
const PLAYBACK_VOLUME_KEY = "webspeak3:playback-volume";
|
||||||
@@ -519,11 +553,14 @@ function ConnectDialog({
|
|||||||
defaultChannel,
|
defaultChannel,
|
||||||
expanded,
|
expanded,
|
||||||
connecting,
|
connecting,
|
||||||
|
identities,
|
||||||
|
activeIdentityId,
|
||||||
onHostChange,
|
onHostChange,
|
||||||
onNicknameChange,
|
onNicknameChange,
|
||||||
onServerPasswordChange,
|
onServerPasswordChange,
|
||||||
onChannelPasswordChange,
|
onChannelPasswordChange,
|
||||||
onDefaultChannelChange,
|
onDefaultChannelChange,
|
||||||
|
onActiveIdentityChange,
|
||||||
onToggleExpanded,
|
onToggleExpanded,
|
||||||
onConnect,
|
onConnect,
|
||||||
onCancel,
|
onCancel,
|
||||||
@@ -535,11 +572,14 @@ function ConnectDialog({
|
|||||||
defaultChannel: string;
|
defaultChannel: string;
|
||||||
expanded: boolean;
|
expanded: boolean;
|
||||||
connecting: boolean;
|
connecting: boolean;
|
||||||
|
identities: Identity[];
|
||||||
|
activeIdentityId: string | null;
|
||||||
onHostChange: (v: string) => void;
|
onHostChange: (v: string) => void;
|
||||||
onNicknameChange: (v: string) => void;
|
onNicknameChange: (v: string) => void;
|
||||||
onServerPasswordChange: (v: string) => void;
|
onServerPasswordChange: (v: string) => void;
|
||||||
onChannelPasswordChange: (v: string) => void;
|
onChannelPasswordChange: (v: string) => void;
|
||||||
onDefaultChannelChange: (v: string) => void;
|
onDefaultChannelChange: (v: string) => void;
|
||||||
|
onActiveIdentityChange: (id: string) => void;
|
||||||
onToggleExpanded: () => void;
|
onToggleExpanded: () => void;
|
||||||
onConnect: () => void;
|
onConnect: () => void;
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
@@ -583,8 +623,12 @@ function ConnectDialog({
|
|||||||
</label>
|
</label>
|
||||||
<label className="ts-dialog-field">
|
<label className="ts-dialog-field">
|
||||||
{t("connect.identity")}
|
{t("connect.identity")}
|
||||||
<select disabled defaultValue="Standard">
|
<select value={activeIdentityId ?? ""} onChange={(e) => onActiveIdentityChange(e.target.value)}>
|
||||||
<option>Standard</option>
|
{identities.map((identity) => (
|
||||||
|
<option key={identity.id} value={identity.id}>
|
||||||
|
{identity.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label className="ts-dialog-field">
|
<label className="ts-dialog-field">
|
||||||
@@ -1227,6 +1271,79 @@ function WhisperListsDialog({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function IdentitiesDialog({
|
||||||
|
identities,
|
||||||
|
activeId,
|
||||||
|
onActivate,
|
||||||
|
onAdd,
|
||||||
|
onRename,
|
||||||
|
onDelete,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
identities: Identity[];
|
||||||
|
activeId: string | null;
|
||||||
|
onActivate: (id: string) => void;
|
||||||
|
onAdd: () => void;
|
||||||
|
onRename: (id: string, name: string) => void;
|
||||||
|
onDelete: (id: string) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}) {
|
||||||
|
const t = useT();
|
||||||
|
const backdrop = useBackdropDismiss(onClose);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||||
|
<div className="ts-dialog ts-identities-dialog" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<div className="ts-dialog-titlebar">
|
||||||
|
<span>{t("identities.title")}</span>
|
||||||
|
<button onClick={onClose} title={t("dialog.close")}>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="ts-dialog-body">
|
||||||
|
<ul className="ts-identities-list">
|
||||||
|
{identities.map((identity) => (
|
||||||
|
<li
|
||||||
|
key={identity.id}
|
||||||
|
className={`ts-identities-item${identity.id === activeId ? " ts-identities-item-active" : ""}`}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="active-identity"
|
||||||
|
checked={identity.id === activeId}
|
||||||
|
onChange={() => onActivate(identity.id)}
|
||||||
|
title={t("identities.activate")}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
className="ts-identities-name"
|
||||||
|
value={identity.name}
|
||||||
|
onChange={(e) => onRename(identity.id, e.target.value)}
|
||||||
|
/>
|
||||||
|
<span className="ts-identities-status">
|
||||||
|
{identity.blob ? t("identities.generated") : t("identities.pending")}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
disabled={identities.length <= 1}
|
||||||
|
onClick={() => onDelete(identity.id)}
|
||||||
|
title={t("identities.delete")}
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div className="ts-dialog-buttons">
|
||||||
|
<button onClick={onAdd}>{t("identities.add")}</button>
|
||||||
|
<div className="ts-dialog-buttons-right">
|
||||||
|
<button onClick={onClose}>{t("dialog.close")}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function ContactsDialog({
|
function ContactsDialog({
|
||||||
contacts,
|
contacts,
|
||||||
onlineClients,
|
onlineClients,
|
||||||
@@ -2143,6 +2260,11 @@ function AppInner() {
|
|||||||
const [whisperHistoryOpen, setWhisperHistoryOpen] = useState(false);
|
const [whisperHistoryOpen, setWhisperHistoryOpen] = useState(false);
|
||||||
const [whisperLists, setWhisperLists] = useState<WhisperList[]>(() => loadWhisperLists());
|
const [whisperLists, setWhisperLists] = useState<WhisperList[]>(() => loadWhisperLists());
|
||||||
const [whisperListsOpen, setWhisperListsOpen] = useState(false);
|
const [whisperListsOpen, setWhisperListsOpen] = useState(false);
|
||||||
|
const [identities, setIdentities] = useState<Identity[]>(() => loadIdentities());
|
||||||
|
const [activeIdentityId, setActiveIdentityId] = useState<string | null>(() =>
|
||||||
|
localStorage.getItem(ACTIVE_IDENTITY_KEY)
|
||||||
|
);
|
||||||
|
const [identitiesOpen, setIdentitiesOpen] = useState(false);
|
||||||
const [selfMenuOpen, setSelfMenuOpen] = useState(false);
|
const [selfMenuOpen, setSelfMenuOpen] = useState(false);
|
||||||
const selfMenuRef = useRef<HTMLDivElement | null>(null);
|
const selfMenuRef = useRef<HTMLDivElement | null>(null);
|
||||||
const [changeNicknameOpen, setChangeNicknameOpen] = useState(false);
|
const [changeNicknameOpen, setChangeNicknameOpen] = useState(false);
|
||||||
@@ -2200,6 +2322,14 @@ function AppInner() {
|
|||||||
localStorage.setItem(WHISPER_LISTS_KEY, JSON.stringify(whisperLists));
|
localStorage.setItem(WHISPER_LISTS_KEY, JSON.stringify(whisperLists));
|
||||||
}, [whisperLists]);
|
}, [whisperLists]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem(IDENTITIES_KEY, JSON.stringify(identities));
|
||||||
|
}, [identities]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (activeIdentityId) localStorage.setItem(ACTIVE_IDENTITY_KEY, activeIdentityId);
|
||||||
|
}, [activeIdentityId]);
|
||||||
|
|
||||||
const isSenderIgnored = (senderName: string) => {
|
const isSenderIgnored = (senderName: string) => {
|
||||||
const senderClient = clients.find((c) => c.name === senderName);
|
const senderClient = clients.find((c) => c.name === senderName);
|
||||||
if (!senderClient?.uid) return false;
|
if (!senderClient?.uid) return false;
|
||||||
@@ -2399,6 +2529,9 @@ function AppInner() {
|
|||||||
|
|
||||||
ensureAudioContext();
|
ensureAudioContext();
|
||||||
|
|
||||||
|
const connectIdentityId = activeIdentityId;
|
||||||
|
const connectIdentityBlob = identities.find((i) => i.id === connectIdentityId)?.blob ?? undefined;
|
||||||
|
|
||||||
const socket = DEMO_MODE ? new DemoSocket() : new WebSocket(GATEWAY_URL);
|
const socket = DEMO_MODE ? new DemoSocket() : new WebSocket(GATEWAY_URL);
|
||||||
socketRef.current = socket;
|
socketRef.current = socket;
|
||||||
|
|
||||||
@@ -2412,7 +2545,7 @@ function AppInner() {
|
|||||||
serverPassword: connectServerPassword || undefined,
|
serverPassword: connectServerPassword || undefined,
|
||||||
channelPassword: connectChannelPassword || undefined,
|
channelPassword: connectChannelPassword || undefined,
|
||||||
defaultChannel: connectDefaultChannel || undefined,
|
defaultChannel: connectDefaultChannel || undefined,
|
||||||
identity: localStorage.getItem(IDENTITY_KEY) || undefined,
|
identity: connectIdentityBlob || undefined,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -2428,7 +2561,11 @@ function AppInner() {
|
|||||||
setConnected(true);
|
setConnected(true);
|
||||||
localStorage.setItem(LAST_HOST_KEY, connectHost);
|
localStorage.setItem(LAST_HOST_KEY, connectHost);
|
||||||
localStorage.setItem(LAST_NICKNAME_KEY, connectNickname);
|
localStorage.setItem(LAST_NICKNAME_KEY, connectNickname);
|
||||||
if (data.identity) localStorage.setItem(IDENTITY_KEY, data.identity);
|
if (data.identity && connectIdentityId) {
|
||||||
|
setIdentities((prev) =>
|
||||||
|
prev.map((i) => (i.id === connectIdentityId ? { ...i, blob: data.identity } : i))
|
||||||
|
);
|
||||||
|
}
|
||||||
setServerName(data.serverName);
|
setServerName(data.serverName);
|
||||||
setServerMaxClients(data.serverMaxClients);
|
setServerMaxClients(data.serverMaxClients);
|
||||||
setServerVersion(data.serverVersion);
|
setServerVersion(data.serverVersion);
|
||||||
@@ -3115,6 +3252,24 @@ function AppInner() {
|
|||||||
setWhisperLists((prev) => prev.filter((list) => list.id !== id));
|
setWhisperLists((prev) => prev.filter((list) => list.id !== id));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleAddIdentity = () => {
|
||||||
|
const identity: Identity = { id: crypto.randomUUID(), name: t("identities.newName"), blob: null };
|
||||||
|
setIdentities((prev) => [...prev, identity]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRenameIdentity = (id: string, name: string) => {
|
||||||
|
setIdentities((prev) => prev.map((i) => (i.id === id ? { ...i, name } : i)));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteIdentity = (id: string) => {
|
||||||
|
setIdentities((prev) => {
|
||||||
|
if (prev.length <= 1) return prev;
|
||||||
|
const next = prev.filter((i) => i.id !== id);
|
||||||
|
if (activeIdentityId === id) setActiveIdentityId(next[0]?.id ?? null);
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleClientContextMenu = (
|
const handleClientContextMenu = (
|
||||||
e: React.MouseEvent,
|
e: React.MouseEvent,
|
||||||
clientId: number,
|
clientId: number,
|
||||||
@@ -3357,7 +3512,13 @@ function AppInner() {
|
|||||||
</span>
|
</span>
|
||||||
{extrasMenuOpen && (
|
{extrasMenuOpen && (
|
||||||
<div className="ts-menu">
|
<div className="ts-menu">
|
||||||
<button className="ts-menu-item" disabled>
|
<button
|
||||||
|
className="ts-menu-item"
|
||||||
|
onClick={() => {
|
||||||
|
setIdentitiesOpen(true);
|
||||||
|
setExtrasMenuOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<span className="ts-menu-item-icon">🪪</span>
|
<span className="ts-menu-item-icon">🪪</span>
|
||||||
<span className="ts-menu-item-label">{t("menu.extras.identities")}</span>
|
<span className="ts-menu-item-label">{t("menu.extras.identities")}</span>
|
||||||
<span className="ts-menu-item-shortcut">Strg+I</span>
|
<span className="ts-menu-item-shortcut">Strg+I</span>
|
||||||
@@ -3681,11 +3842,14 @@ function AppInner() {
|
|||||||
defaultChannel={defaultChannel}
|
defaultChannel={defaultChannel}
|
||||||
expanded={connectDialogExpanded}
|
expanded={connectDialogExpanded}
|
||||||
connecting={connecting}
|
connecting={connecting}
|
||||||
|
identities={identities}
|
||||||
|
activeIdentityId={activeIdentityId}
|
||||||
onHostChange={setHost}
|
onHostChange={setHost}
|
||||||
onNicknameChange={setNickname}
|
onNicknameChange={setNickname}
|
||||||
onServerPasswordChange={setServerPassword}
|
onServerPasswordChange={setServerPassword}
|
||||||
onChannelPasswordChange={setChannelPassword}
|
onChannelPasswordChange={setChannelPassword}
|
||||||
onDefaultChannelChange={setDefaultChannel}
|
onDefaultChannelChange={setDefaultChannel}
|
||||||
|
onActiveIdentityChange={setActiveIdentityId}
|
||||||
onToggleExpanded={() => setConnectDialogExpanded((v) => !v)}
|
onToggleExpanded={() => setConnectDialogExpanded((v) => !v)}
|
||||||
onConnect={handleConnect}
|
onConnect={handleConnect}
|
||||||
onCancel={() => setConnectDialogOpen(false)}
|
onCancel={() => setConnectDialogOpen(false)}
|
||||||
@@ -3741,6 +3905,18 @@ function AppInner() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{identitiesOpen && (
|
||||||
|
<IdentitiesDialog
|
||||||
|
identities={identities}
|
||||||
|
activeId={activeIdentityId}
|
||||||
|
onActivate={setActiveIdentityId}
|
||||||
|
onAdd={handleAddIdentity}
|
||||||
|
onRename={handleRenameIdentity}
|
||||||
|
onDelete={handleDeleteIdentity}
|
||||||
|
onClose={() => setIdentitiesOpen(false)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{contactsOpen && (
|
{contactsOpen && (
|
||||||
<ContactsDialog
|
<ContactsDialog
|
||||||
contacts={contacts}
|
contacts={contacts}
|
||||||
|
|||||||
@@ -120,6 +120,14 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"whisperLists.delete": "Löschen",
|
"whisperLists.delete": "Löschen",
|
||||||
"whisperLists.empty": "Keine Whisperlisten gespeichert. Wähle Whisper-Ziele aus und speichere sie hier als Liste.",
|
"whisperLists.empty": "Keine Whisperlisten gespeichert. Wähle Whisper-Ziele aus und speichere sie hier als Liste.",
|
||||||
|
|
||||||
|
"identities.title": "Identitäten",
|
||||||
|
"identities.activate": "Aktivieren",
|
||||||
|
"identities.add": "Neue Identität",
|
||||||
|
"identities.delete": "Löschen",
|
||||||
|
"identities.newName": "Neue Identität",
|
||||||
|
"identities.generated": "Erstellt",
|
||||||
|
"identities.pending": "Wird bei der nächsten Verbindung erstellt",
|
||||||
|
|
||||||
"menu.self.recordingProfile": "Aufnahmeprofil",
|
"menu.self.recordingProfile": "Aufnahmeprofil",
|
||||||
"menu.self.playbackProfile": "Wiedergabeprofil",
|
"menu.self.playbackProfile": "Wiedergabeprofil",
|
||||||
"menu.self.hotkeyProfile": "Hotkeyprofil",
|
"menu.self.hotkeyProfile": "Hotkeyprofil",
|
||||||
@@ -435,6 +443,14 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"whisperLists.delete": "Delete",
|
"whisperLists.delete": "Delete",
|
||||||
"whisperLists.empty": "No whisper lists saved yet. Select whisper targets and save them here as a list.",
|
"whisperLists.empty": "No whisper lists saved yet. Select whisper targets and save them here as a list.",
|
||||||
|
|
||||||
|
"identities.title": "Identities",
|
||||||
|
"identities.activate": "Activate",
|
||||||
|
"identities.add": "New Identity",
|
||||||
|
"identities.delete": "Delete",
|
||||||
|
"identities.newName": "New Identity",
|
||||||
|
"identities.generated": "Generated",
|
||||||
|
"identities.pending": "Will be generated on next connection",
|
||||||
|
|
||||||
"menu.self.recordingProfile": "Recording Profile",
|
"menu.self.recordingProfile": "Recording Profile",
|
||||||
"menu.self.playbackProfile": "Playback Profile",
|
"menu.self.playbackProfile": "Playback Profile",
|
||||||
"menu.self.hotkeyProfile": "Hotkey Profile",
|
"menu.self.hotkeyProfile": "Hotkey Profile",
|
||||||
|
|||||||
Reference in new issue
Block a user