Compare commits

..

7 Commits

Author SHA1 Message Date
byGalax a4c9b959a9 fix: editable decrypt + windows realtime wake (v0.7.1)
Release desktop app / build (, windows-latest) (push) Has been cancelled
Release desktop app / build (--target universal-apple-darwin --bundles app,updater, macos-14) (push) Has been cancelled
Edit message decrypt:
- handleUpdate in useConversationMessages now refetches the canonical row
  via REST after a realtime UPDATE instead of trusting the realtime
  payload's bytea encoding. Same pattern as handleInsert — base64 vs
  `\x…` hex serialisation varies across supabase/postgrest versions and
  was silently producing undecryptable ciphertext for edited messages
  on the receiver side

Windows WebView2 background throttling:
- ConversationsContext, useFriendships and useConversationMessages now
  listen for visibilitychange / focus / online events and trigger both a
  fresh REST refresh and a best-effort channel.subscribe() on wake.
  WebView2 aggressively throttles background WebSockets and was dropping
  realtime events entirely while the window was minimised, so new
  messages and friend acceptances only surfaced after a manual reload

Bump tauri version 0.7.0 -> 0.7.1
2026-04-20 22:15:49 +02:00
byGalax 37becba7e2 feat: audio devices + fullscreen + banner cleanup (v0.7.0)
Release desktop app / build (, windows-latest) (push) Has been cancelled
Release desktop app / build (--target universal-apple-darwin --bundles app,updater, macos-14) (push) Has been cancelled
Audio device selection:
- audioSettings: persisted inputDeviceId + outputDeviceId
- CallContext: uses stored input deviceId on mic enable, new
  setAudioInputDevice / setAudioOutputDevice actions that hot-swap
  without reconnect. Output swap applies HTMLMediaElement.setSinkId
  to every attached remote-audio element (LiveKit's switchActiveDevice
  only tracks elements it attached itself)
- SettingsPage: new "Mikrofon" + "Ausgabegerät" selects with
  enumerateDevices, devicechange listener, permission-probe button.
  setSinkId-unsupported fallback is messaged but non-blocking

Fullscreen:
- FullscreenCall was absolute inset-0 z-40 which trapped it inside the
  <main> pane — sidebar + chat-list stayed visible. Switched to
  fixed inset-0 z-[60] so the call overlays the whole window
  Discord-style
- ScreenShareViewer fullscreen: CSS-only toggle (native Fullscreen API
  unreliable under Tauri WKWebView), portalled to document.body when
  active so no ancestor stacking context can clip it. Esc exits

ActiveCallBanner:
- cleanup effect returned early when presence was entirely empty,
  leaving the "1 im Raum" fallback stuck after both peers left. Now
  schedules dismissLastCall as soon as othersIn.length === 0, with a
  3s grace window to absorb presence re-sync flicker

Bump tauri version 0.6.0 -> 0.7.0
2026-04-20 21:26:10 +02:00
byGalax eb8f9857ff feat: device backup/restore + quick wins + username casing
Backup / restore flow:
- deviceBackup.ts: v2 format wrapping userId + deviceId + privateKey in
  an encrypted JSON payload so restore can re-seed localStorage, vault,
  and reattach to the existing server-side device row without provisioning
  a new one (conv-key bundles stay valid, no "awaiting key" state)
- shared/auth: restoreDeviceFromServerRecord — verifies session.user.id
  matches the backup's userId, confirms the server device row still
  exists, then writes the private key into the local secret store
- BackupExportDialog — passphrase + confirm, generates portable string,
  copy + download .txt
- DeviceRestore — textarea + passphrase → seeds vault + writes
  deviceId cache, treats this install as the original device
- DevicePage now has tabs "Neu einrichten" / "Backup wiederherstellen"
- BackupPromptBanner — post-registration nudge, reads sessionStorage
  signal from fresh provisions and persists "never-ask-again" in
  localStorage so it stops nagging
- SettingsPage backup section: uses the new dialog; removes the
  dangerous in-place key import (restore now lives in the device flow)

Username casing:
- Migration 20260420000002 drops lower() from the handle_new_user trigger
  and widens the regex to [A-Za-z0-9_]. profiles.username is citext so
  uniqueness + lookups stay case-insensitive regardless of stored casing
- Shared auth: trim() only, no toLowerCase on signup/lookups/search.
  ilike handles CI anyway and citext makes client normalisation redundant
- AuthPage regex + input preserve case, FriendsPage search preserves case
- i18n (de+en): updated username_hint / username_invalid / ERR_USERNAME_INVALID
  to reflect the new rule

Quick wins:
- React Router v7 future flags (v7_startTransition + v7_relativeSplatPath)
  set on BrowserRouter — silences the upgrade warning
- appUpdates.checkForUpdate: swallow benign network/fetch/"could not
  fetch valid release JSON" cases silently instead of console spam
- osNotify: persist an "asked" marker in localStorage so the permission
  prompt only fires once per install (OS already persists the answer,
  but the plugin re-queries loudly otherwise)
2026-04-20 19:07:31 +02:00
byGalax de431386ea feat: reply + search + forward + archive/mute + error boundary
Messages:
- Reply-to: hover action, composer chip with cancel, quote bubble inside
  the replying message with tap-to-jump + amber highlight ring
- Search: header search button toggles in-conversation search bar with
  prev/next + match counter, auto-jump to active match
- Forward: multi-select conversation picker. Attachments are now carried
  over: download + decrypt source, re-encrypt under each target conv-key,
  re-upload with fresh per-attachment keys, insert new attachment rows

Conversations:
- Archive + mute per member. New migration 20260420000001 adds `archived`
  + `muted_until` on conversation_members. Shared helpers:
  setConversationArchived / setConversationMutedUntil / isConversationMuted
- ChatsPage: archive toggle in header with unread badge for archived
  bucket, split active/archived lists, muted indicator (BellOff icon,
  dimmed unread badge)
- ConversationRowMenu via createPortal (escapes sidebar overflow clip),
  forwardRef-based MenuItem so submenu positioning refs survive React 18
- ConversationsContext: suppresses notification sound + OS notif when
  target conversation is muted
- Refresh on `profiles UPDATE` realtime so peer avatar / displayName
  changes flow to conversation.members without manual refresh

Resilience:
- ErrorBoundary (Discord-style): centred spinner + escalating copy, no
  manual reload button. Backoff retry schedule [2s, 4s, 8s, 15s, 30s].
  Uses a keyed Fragment (not a div wrapper) so flex h-full chains survive
- App wrapped root + per-route RouteBoundary, conversation-level boundary
- AuthContext: flip `ready` immediately on cached session read; validate
  getUser in background so a stalled/offline Supabase doesn't freeze the
  app on the loading spinner

Crypto:
- Swap libsodium-wrappers -> libsodium-wrappers-sumo (compact build was
  missing crypto_pwhash so Argon2id vault KDF threw, falling back to
  plaintext localStorage on every launch)
- Shim d.ts for sumo types (sumo is API superset, no official types ship)
- vite optimizeDeps includes sumo with the "require" condition
- secureFileStore: exists(dir) check before mkdir; surface genuine
  permission errors instead of silent catch

Tauri:
- fs scope adds `$APPLOCALDATA` direct entry (not just /**) so the app
  data directory itself can be mkdir'd on first launch

Chat layout:
- Skip call_event messages when computing avatar run boundaries so a
  regular bubble followed by a call event from the same sender still
  shows its avatar
2026-04-20 15:42:49 +02:00
byGalax 1fab2edc57 fix(messages): peer avatar visibility in chat bubbles
- ConversationsContext: subscribe to profiles UPDATE realtime so
  conversation members[].profile picks up peer avatar / displayName changes
  without a manual refresh
- ConversationPage: skip call_event messages when computing run boundaries.
  Previously a peer bubble followed by a call event from the same sender
  was treated as mid-run -> avatar slot collapsed to a placeholder
- DM peer-profile fallback already added in previous commit covers transient
  member-lookup misses
2026-04-20 00:49:21 +02:00
byGalax 4db65993d5 feat: redesign + avatars + theme + call presence fixes (v0.6.0)
Release desktop app / build (, windows-latest) (push) Has been cancelled
Release desktop app / build (--target universal-apple-darwin --bundles app,updater, macos-14) (push) Has been cancelled
Visual:
- Light/dark theme via ThemeContext + CSS vars
- New design tokens (surface/fg/accent/line/etc.) across all pages
- Reusable Avatar component (img + letter fallback) wired into UserBar,
  ConversationHeader, ChatsPage, FriendsPage, GroupInfoPanel, IncomingCallPanel

Calls:
- Split call UI: IncomingCallPanel, InCallPanel, CallControls,
  CallParticipantTile, ScreenShareViewer
- Active speaker hook (useActiveSpeakers)
- Fix: ActiveCallBanner stayed hidden after hangup while peers in room.
  - useCallPresence: bind presence callbacks only when we own subscribe
    (Supabase forbids .on() after .subscribe() on shared dedup'd channels)
  - useCallPresence: never removeChannel — channel is shared with CallContext
    so tearing it down on ConversationHeader unmount killed live tracking
  - ActiveCallBanner: lastCallConversationId fallback so banner shows
    instantly after hangup, auto-dismiss when room confirmed empty
- Drop unused useAnyActiveCall

Bump tauri version 0.5.0 -> 0.6.0
2026-04-20 00:26:19 +02:00
byGalax 0ca29952ba feat: profile avatar upload + share_conv_keys rpc + favicon + smtp tweaks
Release desktop app / build (, windows-latest) (push) Has been cancelled
Release desktop app / build (--target universal-apple-darwin --bundles app,updater, macos-14) (push) Has been cancelled
2026-04-19 23:04:03 +02:00
98 changed files with 8436 additions and 1370 deletions
+16 -2
View File
@@ -4,9 +4,23 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>ChatApp</title> <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<title>Netralax</title>
<script>
// Apply persisted / system theme before paint to avoid FOUC.
(function () {
try {
var stored = localStorage.getItem('netralax.theme');
var dark =
stored === 'dark' ||
(stored !== 'light' &&
window.matchMedia('(prefers-color-scheme: dark)').matches);
if (dark) document.documentElement.classList.add('dark');
} catch (_) {}
})();
</script>
</head> </head>
<body class="bg-[#0b0b0f] text-white antialiased"> <body class="bg-surface text-fg antialiased">
<div id="root"></div> <div id="root"></div>
<script type="module" src="/src/main.tsx"></script> <script type="module" src="/src/main.tsx"></script>
</body> </body>
+2 -1
View File
@@ -30,7 +30,7 @@
"@tauri-apps/plugin-stronghold": "^2.0.1", "@tauri-apps/plugin-stronghold": "^2.0.1",
"@tauri-apps/plugin-updater": "^2.10.1", "@tauri-apps/plugin-updater": "^2.10.1",
"i18next": "^23.16.4", "i18next": "^23.16.4",
"libsodium-wrappers": "0.7.15", "libsodium-wrappers-sumo": "0.7.15",
"livekit-client": "^2.7.0", "livekit-client": "^2.7.0",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1", "react-dom": "^18.3.1",
@@ -41,6 +41,7 @@
"devDependencies": { "devDependencies": {
"@tauri-apps/cli": "^2.1.0", "@tauri-apps/cli": "^2.1.0",
"@types/libsodium-wrappers": "^0.7.14", "@types/libsodium-wrappers": "^0.7.14",
"@types/libsodium-wrappers-sumo": "^0.8.2",
"@types/react": "^18.3.12", "@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1", "@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3", "@vitejs/plugin-react": "^4.3.3",
+14
View File
@@ -0,0 +1,14 @@
<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
<defs>
<clipPath id="cp02">
<polygon points="32,5 57,19 57,45 32,59 7,45 7,19"/>
</clipPath>
</defs>
<polygon points="32,5 57,19 57,45 32,59 7,45 7,19" fill="#2e1065"/>
<g clip-path="url(#cp02)">
<path d="M-4 32 Q 16 18 32 32 T 68 32 L 68 64 L -4 64 Z" fill="#7c4dff"/>
<path d="M-4 32 Q 16 18 32 32 T 68 32" stroke="#a78bfa" stroke-width="2" fill="none"/>
</g>
<polygon points="32,5 57,19 57,45 32,59 7,45 7,19"
fill="none" stroke="#a78bfa" stroke-width="1.5" opacity="0.4"/>
</svg>

After

Width:  |  Height:  |  Size: 667 B

@@ -34,6 +34,7 @@
{ {
"identifier": "fs:scope", "identifier": "fs:scope",
"allow": [ "allow": [
{ "path": "$APPLOCALDATA" },
{ "path": "$APPLOCALDATA/**" } { "path": "$APPLOCALDATA/**" }
] ]
} }
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"$schema": "https://schema.tauri.app/config/2", "$schema": "https://schema.tauri.app/config/2",
"productName": "ChatApp", "productName": "ChatApp",
"version": "0.4.4", "version": "0.7.1",
"identifier": "com.meinname.chatapp", "identifier": "com.meinname.chatapp",
"build": { "build": {
"beforeDevCommand": "pnpm vite:dev", "beforeDevCommand": "pnpm vite:dev",
+82 -35
View File
@@ -1,12 +1,14 @@
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'; import { BrowserRouter, Navigate, Outlet, Route, Routes } from 'react-router-dom';
import { AppShell } from './components/AppShell'; import { AppShell } from './components/AppShell';
import { ErrorBoundary } from './components/ErrorBoundary';
import { UpdateToast } from './components/UpdateToast'; import { UpdateToast } from './components/UpdateToast';
import { RequireAdmin, RequireAuth, RequireDevice } from './components/guards'; import { RequireAdmin, RequireAuth, RequireDevice } from './components/guards';
import { AuthProvider } from './context/AuthContext'; import { AuthProvider } from './context/AuthContext';
import { CallProvider } from './context/CallContext'; import { CallProvider } from './context/CallContext';
import { ConversationsProvider } from './context/ConversationsContext'; import { ConversationsProvider } from './context/ConversationsContext';
import { FriendshipsProvider } from './context/FriendshipsContext'; import { FriendshipsProvider } from './context/FriendshipsContext';
import { ThemeProvider } from './context/ThemeContext';
import { AdminPage } from './pages/AdminPage'; import { AdminPage } from './pages/AdminPage';
import { AuthCallbackPage } from './pages/AuthCallbackPage'; import { AuthCallbackPage } from './pages/AuthCallbackPage';
import { AuthPage } from './pages/AuthPage'; import { AuthPage } from './pages/AuthPage';
@@ -16,40 +18,85 @@ import { DevicePage } from './pages/DevicePage';
import { FriendsPage } from './pages/FriendsPage'; import { FriendsPage } from './pages/FriendsPage';
import { SettingsPage } from './pages/SettingsPage'; import { SettingsPage } from './pages/SettingsPage';
export function App() { // Isolates each top-level route so a crash in one page doesn't take the whole
// shell down. The boundary auto-retries via `ErrorBoundary`'s backoff schedule.
function RouteBoundary({ scope }: { scope: string }) {
return ( return (
<AuthProvider> <ErrorBoundary scope={scope}>
<FriendshipsProvider> <Outlet />
<ConversationsProvider> </ErrorBoundary>
<CallProvider> );
<BrowserRouter> }
<Routes>
<Route path="/auth" element={<AuthPage />} /> export function App() {
<Route path="/auth/callback" element={<AuthCallbackPage />} /> return (
<Route element={<RequireAuth />}> <ErrorBoundary scope="root">
<Route path="/device" element={<DevicePage />} /> <ThemeProvider>
<Route element={<RequireDevice />}> <AuthProvider>
<Route element={<AppShell />}> <FriendshipsProvider>
<Route index element={<Navigate to="/chats" replace />} /> <ConversationsProvider>
<Route path="/chats" element={<ChatsPage />}> <CallProvider>
<Route index element={<ChatsEmptyState />} /> <BrowserRouter
<Route path=":id" element={<ConversationPage />} /> future={{
</Route> // Opt into v7 behaviour early so the upgrade is a no-op:
<Route path="/friends" element={<FriendsPage />} /> // - `v7_startTransition` wraps navigations in startTransition
<Route path="/settings" element={<SettingsPage />} /> // so Suspense / concurrent rendering deal with the new tree
<Route element={<RequireAdmin />}> // - `v7_relativeSplatPath` matches relative paths inside
<Route path="/admin" element={<AdminPage />} /> // splat routes against the parent splat segment (not the
</Route> // full matched path). Our tree has no splat routes today
</Route> // but this kills the runtime warning and future-proofs.
</Route> v7_startTransition: true,
</Route> v7_relativeSplatPath: true,
<Route path="*" element={<Navigate to="/chats" replace />} /> }}
</Routes> >
<UpdateToast /> <Routes>
</BrowserRouter> <Route element={<RouteBoundary scope="auth" />}>
</CallProvider> <Route path="/auth" element={<AuthPage />} />
</ConversationsProvider> <Route path="/auth/callback" element={<AuthCallbackPage />} />
</FriendshipsProvider> </Route>
</AuthProvider> <Route element={<RequireAuth />}>
<Route element={<RouteBoundary scope="device" />}>
<Route path="/device" element={<DevicePage />} />
</Route>
<Route element={<RequireDevice />}>
<Route element={<AppShell />}>
<Route index element={<Navigate to="/chats" replace />} />
<Route element={<RouteBoundary scope="chats" />}>
<Route path="/chats" element={<ChatsPage />}>
<Route index element={<ChatsEmptyState />} />
<Route
path=":id"
element={
<ErrorBoundary scope="conversation">
<ConversationPage />
</ErrorBoundary>
}
/>
</Route>
</Route>
<Route element={<RouteBoundary scope="friends" />}>
<Route path="/friends" element={<FriendsPage />} />
</Route>
<Route element={<RouteBoundary scope="settings" />}>
<Route path="/settings" element={<SettingsPage />} />
</Route>
<Route element={<RequireAdmin />}>
<Route element={<RouteBoundary scope="admin" />}>
<Route path="/admin" element={<AdminPage />} />
</Route>
</Route>
</Route>
</Route>
</Route>
<Route path="*" element={<Navigate to="/chats" replace />} />
</Routes>
<UpdateToast />
</BrowserRouter>
</CallProvider>
</ConversationsProvider>
</FriendshipsProvider>
</AuthProvider>
</ThemeProvider>
</ErrorBoundary>
); );
} }
+6 -4
View File
@@ -4,6 +4,7 @@ import { Outlet } from 'react-router-dom';
import { useAuth } from '../context/AuthContext'; import { useAuth } from '../context/AuthContext';
import { startConversationKeySync } from '../lib/conversationKeySync'; import { startConversationKeySync } from '../lib/conversationKeySync';
import { ensureNotificationPermission } from '../lib/osNotify'; import { ensureNotificationPermission } from '../lib/osNotify';
import { BackupPromptBanner } from './BackupPromptBanner';
import { CallUI } from './CallUI'; import { CallUI } from './CallUI';
import { Sidebar } from './Sidebar'; import { Sidebar } from './Sidebar';
@@ -21,7 +22,7 @@ export function AppShell() {
}, [session?.user.id, device?.id]); }, [session?.user.id, device?.id]);
return ( return (
<div className="relative flex min-h-screen overflow-hidden bg-ink-950 text-neutral-100"> <div className="relative flex min-h-screen overflow-hidden bg-surface text-fg">
<ShellBackground /> <ShellBackground />
<div className="relative z-10 flex min-h-screen w-full"> <div className="relative z-10 flex min-h-screen w-full">
<Sidebar /> <Sidebar />
@@ -32,15 +33,16 @@ export function AppShell() {
</main> </main>
</div> </div>
<CallUI /> <CallUI />
<BackupPromptBanner />
</div> </div>
); );
} }
// Calmer than the auth-screen background — full-bleed grid + 2 large blobs. // Subtle ambient background — only renders in dark mode where the app's
// No animation here so message lists stay readable. // visual language expects depth. Light mode stays clean and flat.
function ShellBackground() { function ShellBackground() {
return ( return (
<div aria-hidden="true" className="pointer-events-none absolute inset-0"> <div aria-hidden="true" className="pointer-events-none absolute inset-0 hidden dark:block">
<div className="bg-grid absolute inset-0 opacity-[0.18]" /> <div className="bg-grid absolute inset-0 opacity-[0.18]" />
<div className="absolute -left-32 top-1/4 h-[420px] w-[420px] rounded-full bg-brand-500/20 blur-3xl" /> <div className="absolute -left-32 top-1/4 h-[420px] w-[420px] rounded-full bg-brand-500/20 blur-3xl" />
<div className="absolute -right-32 bottom-0 h-[420px] w-[420px] rounded-full bg-fuchsia-500/10 blur-3xl" /> <div className="absolute -right-32 bottom-0 h-[420px] w-[420px] rounded-full bg-fuchsia-500/10 blur-3xl" />
+45
View File
@@ -0,0 +1,45 @@
// Reusable avatar that prefers an uploaded image and falls back to a coloured
// letter circle. Use this everywhere the app needs to render a profile.
interface Props {
url?: string | null | undefined;
displayName?: string | null | undefined;
className?: string;
// Background gradient classes used when no image is set. Defaults to a
// brand-tinted fallback; callers can override (e.g. to colour-by-id).
fallbackClass?: string;
alt?: string;
}
export function Avatar({
url,
displayName,
className = 'h-10 w-10',
fallbackClass = 'bg-accent/20 text-accent',
alt,
}: Props) {
if (url) {
return (
<img
src={url}
alt={alt ?? displayName ?? ''}
className={'shrink-0 rounded-full object-cover ' + className}
draggable={false}
/>
);
}
const letter = (displayName ?? '?').trim().charAt(0).toUpperCase() || '?';
return (
<div
aria-hidden={alt ? undefined : 'true'}
className={
'flex shrink-0 items-center justify-center rounded-full font-semibold ' +
fallbackClass +
' ' +
className
}
>
{letter}
</div>
);
}
@@ -0,0 +1,251 @@
import { useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { exportDeviceBackup } from '../lib/deviceBackup';
import { AlertIcon, CopyIcon, LockIcon, ShieldIcon, SpinnerIcon, XIcon } from './icons';
interface Props {
open: boolean;
userId: string;
deviceId: string;
privateKey: Uint8Array;
onClose: () => void;
}
// Exports the device's private key + identity into a passphrase-protected
// portable string. The user can store this string anywhere (password manager,
// printed paper, encrypted file on a USB stick). Without it, losing local
// storage on this install means losing all past conversation keys.
export function BackupExportDialog({ open, userId, deviceId, privateKey, onClose }: Props) {
const { t } = useTranslation(['app']);
const [passphrase, setPassphrase] = useState('');
const [confirm, setConfirm] = useState('');
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [backup, setBackup] = useState<string | null>(null);
const [copied, setCopied] = useState(false);
const canGenerate = useMemo(() => {
return passphrase.length >= 8 && passphrase === confirm && !busy;
}, [passphrase, confirm, busy]);
const reset = useCallback(() => {
setPassphrase('');
setConfirm('');
setBackup(null);
setError(null);
setCopied(false);
}, []);
const handleClose = useCallback(() => {
reset();
onClose();
}, [reset, onClose]);
const handleGenerate = useCallback(async () => {
if (!canGenerate) return;
setBusy(true);
setError(null);
try {
const str = await exportDeviceBackup({ userId, deviceId, privateKey, passphrase });
setBackup(str);
} catch (err: unknown) {
setError(err instanceof Error ? err.message : String(err));
} finally {
setBusy(false);
}
}, [canGenerate, userId, deviceId, privateKey, passphrase]);
const handleCopy = useCallback(async () => {
if (!backup) return;
try {
await navigator.clipboard.writeText(backup);
setCopied(true);
window.setTimeout(() => setCopied(false), 1500);
} catch {
/* fall back — user can select manually */
}
}, [backup]);
const handleDownload = useCallback(() => {
if (!backup) return;
const blob = new Blob([backup], { type: 'text/plain;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `chatapp-device-backup-${deviceId.slice(0, 8)}.txt`;
a.click();
URL.revokeObjectURL(url);
}, [backup, deviceId]);
if (!open) return null;
return (
<div
role="dialog"
aria-modal="true"
aria-label={t('app:backup.export_title', { defaultValue: 'Gerätesicherung erstellen' })}
className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4"
onClick={handleClose}
>
<div
onClick={(e) => e.stopPropagation()}
className="flex max-h-[90vh] w-full max-w-lg flex-col overflow-hidden rounded-2xl border border-line bg-surface-3 shadow-xl"
>
<header className="flex items-center justify-between border-b border-line px-5 py-3">
<div className="flex items-center gap-2">
<ShieldIcon className="h-4 w-4 text-accent" />
<h3 className="font-display text-sm font-semibold text-fg">
{t('app:backup.export_title', { defaultValue: 'Gerätesicherung erstellen' })}
</h3>
</div>
<button
type="button"
onClick={handleClose}
aria-label="Close"
className="flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg text-fg-muted transition hover:bg-surface-2 hover:text-fg"
>
<XIcon className="h-4 w-4" />
</button>
</header>
<div className="flex-1 overflow-y-auto p-5">
{!backup ? (
<>
<p className="text-sm text-fg-muted">
{t('app:backup.export_explainer', {
defaultValue:
'Verschlüssele den Geräteschlüssel mit einer Passphrase. Ohne Passphrase UND Backup-String ist keine Wiederherstellung möglich.',
})}
</p>
<div className="mt-4 space-y-3">
<div className="space-y-1">
<label className="block text-xs font-medium uppercase tracking-wide text-fg-muted">
{t('app:backup.passphrase', { defaultValue: 'Passphrase' })}
</label>
<input
type="password"
autoFocus
minLength={8}
value={passphrase}
onChange={(e) => setPassphrase(e.target.value)}
placeholder="min. 8 Zeichen"
className="w-full rounded-lg border border-line bg-surface-2 px-3 py-2.5 text-sm text-fg placeholder-fg-muted transition focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/30"
/>
</div>
<div className="space-y-1">
<label className="block text-xs font-medium uppercase tracking-wide text-fg-muted">
{t('app:backup.passphrase_confirm', { defaultValue: 'Passphrase wiederholen' })}
</label>
<input
type="password"
value={confirm}
onChange={(e) => setConfirm(e.target.value)}
className="w-full rounded-lg border border-line bg-surface-2 px-3 py-2.5 text-sm text-fg placeholder-fg-muted transition focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/30"
/>
</div>
{confirm.length > 0 && confirm !== passphrase && (
<p className="text-xs text-rose-500 dark:text-rose-300">
{t('app:backup.passphrase_mismatch', { defaultValue: 'Passphrasen stimmen nicht überein.' })}
</p>
)}
</div>
<div className="mt-4 rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-xs text-amber-700 dark:text-amber-200">
<div className="flex items-start gap-2">
<AlertIcon className="mt-0.5 h-4 w-4 shrink-0 text-amber-600 dark:text-amber-300" />
<span>
{t('app:backup.export_warning', {
defaultValue:
'Anthropic: Backup + Passphrase sicher aufbewahren. Passphrase kann nicht wiederhergestellt werden.',
})}
</span>
</div>
</div>
{error && (
<p role="alert" className="mt-3 text-sm text-rose-600 dark:text-rose-200">
{error}
</p>
)}
</>
) : (
<>
<div className="rounded-lg border border-emerald-500/30 bg-emerald-500/10 p-3 text-xs text-emerald-700 dark:text-emerald-200">
<div className="flex items-start gap-2">
<LockIcon className="mt-0.5 h-4 w-4 shrink-0" />
<span>
{t('app:backup.export_success', {
defaultValue:
'Backup erstellt. Speichere diesen String + Passphrase in einem Passwortmanager oder drucke ihn aus.',
})}
</span>
</div>
</div>
<textarea
readOnly
value={backup}
rows={8}
onFocus={(e) => e.currentTarget.select()}
className="mt-3 w-full resize-none rounded-lg border border-line bg-surface-2 p-3 font-mono text-[11px] leading-relaxed text-fg"
/>
<div className="mt-3 flex gap-2">
<button
type="button"
onClick={() => void handleCopy()}
className="inline-flex flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-lg border border-line bg-surface-2 px-3 py-2 text-sm font-medium text-fg transition hover:bg-surface-3"
>
<CopyIcon className="h-4 w-4" />
<span>
{copied
? t('app:backup.copied', { defaultValue: 'Kopiert!' })
: t('app:backup.copy', { defaultValue: 'Kopieren' })}
</span>
</button>
<button
type="button"
onClick={handleDownload}
className="inline-flex flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-lg border border-line bg-surface-2 px-3 py-2 text-sm font-medium text-fg transition hover:bg-surface-3"
>
{t('app:backup.download', { defaultValue: 'Als Datei speichern' })}
</button>
</div>
</>
)}
</div>
<footer className="flex items-center justify-end gap-2 border-t border-line bg-surface-2 px-5 py-3">
{!backup ? (
<>
<button
type="button"
onClick={handleClose}
className="cursor-pointer rounded-md border border-line bg-surface-3 px-3 py-2 text-sm text-fg transition hover:bg-surface-2"
>
{t('app:friends.action_cancel', { defaultValue: 'Abbrechen' })}
</button>
<button
type="button"
onClick={() => void handleGenerate()}
disabled={!canGenerate}
className="inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-semibold text-accent-fg transition hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-60"
>
{busy && <SpinnerIcon className="h-4 w-4" />}
<span>{t('app:backup.generate', { defaultValue: 'Backup erstellen' })}</span>
</button>
</>
) : (
<button
type="button"
onClick={handleClose}
className="cursor-pointer rounded-md bg-accent px-3 py-2 text-sm font-semibold text-accent-fg transition hover:brightness-110"
>
{t('app:backup.done', { defaultValue: 'Fertig' })}
</button>
)}
</footer>
</div>
</div>
);
}
@@ -0,0 +1,122 @@
import { loadDevicePrivateKey } from '@chat-app/shared/auth';
import { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useAuth } from '../context/AuthContext';
import { devLocalSecretStore } from '../lib/secretStore';
import { BackupExportDialog } from './BackupExportDialog';
import { ShieldIcon, XIcon } from './icons';
const DISMISS_KEY = 'chatapp.backup.prompt.dismissed';
const SESSION_KEY = 'chatapp.backup.prompt';
// Post-registration nudge: right after a fresh device provision we set
// `chatapp.backup.prompt` in sessionStorage. This component reads it and
// shows a floating "mach jetzt ein Backup" banner until the user either
// creates one or explicitly dismisses (persisted in localStorage so we stop
// nagging across reloads).
export function BackupPromptBanner() {
const { t } = useTranslation(['app']);
const { profile, device } = useAuth();
const [visible, setVisible] = useState(false);
const [dialogOpen, setDialogOpen] = useState(false);
const [privateKey, setPrivateKey] = useState<Uint8Array | null>(null);
useEffect(() => {
try {
if (window.localStorage.getItem(DISMISS_KEY) === '1') return;
if (window.sessionStorage.getItem(SESSION_KEY) !== '1') return;
setVisible(true);
} catch {
/* storage unavailable */
}
}, []);
const dismiss = useCallback((persist: boolean) => {
setVisible(false);
try {
window.sessionStorage.removeItem(SESSION_KEY);
if (persist) window.localStorage.setItem(DISMISS_KEY, '1');
} catch {
/* ignore */
}
}, []);
const openDialog = useCallback(async () => {
if (!profile?.userId || !device?.id) return;
const priv = await loadDevicePrivateKey(devLocalSecretStore, profile.userId, device.id);
if (!priv) return;
setPrivateKey(priv);
setDialogOpen(true);
}, [profile, device]);
const closeDialog = useCallback(() => {
setDialogOpen(false);
if (privateKey) {
for (let i = 0; i < privateKey.length; i++) privateKey[i] = 0;
}
setPrivateKey(null);
// After the user interacts with the dialog, drop the banner regardless
// of whether they actually completed the backup — they're aware now.
dismiss(true);
}, [privateKey, dismiss]);
if (!visible) return null;
return (
<>
<div
role="status"
className="fixed bottom-6 left-1/2 z-40 flex w-[min(92vw,520px)] -translate-x-1/2 items-start gap-3 rounded-2xl border border-amber-500/40 bg-amber-500/10 p-4 text-sm text-amber-800 shadow-xl backdrop-blur-md dark:text-amber-100"
>
<ShieldIcon className="mt-0.5 h-5 w-5 shrink-0 text-amber-600 dark:text-amber-300" />
<div className="min-w-0 flex-1">
<p className="font-semibold">
{t('app:backup.prompt_title', { defaultValue: 'Erstelle jetzt ein Geräte-Backup' })}
</p>
<p className="mt-0.5 text-xs text-amber-700/90 dark:text-amber-200/90">
{t('app:backup.prompt_body', {
defaultValue:
'Ohne Backup verlierst du Zugriff auf alte Nachrichten, wenn Browser oder Gerät ihren Speicher verlieren. Dauert 10 Sekunden.',
})}
</p>
<div className="mt-3 flex flex-wrap gap-2">
<button
type="button"
onClick={() => void openDialog()}
className="cursor-pointer rounded-md bg-amber-600 px-3 py-1.5 text-xs font-semibold text-white transition hover:bg-amber-500"
>
{t('app:backup.prompt_create', { defaultValue: 'Jetzt erstellen' })}
</button>
<button
type="button"
onClick={() => dismiss(true)}
className="cursor-pointer rounded-md border border-amber-500/40 bg-transparent px-3 py-1.5 text-xs font-semibold text-amber-700 transition hover:bg-amber-500/15 dark:text-amber-200"
>
{t('app:backup.prompt_never', { defaultValue: 'Nicht mehr fragen' })}
</button>
</div>
</div>
<button
type="button"
onClick={() => dismiss(false)}
aria-label={t('app:backup.prompt_dismiss', { defaultValue: 'Später' })}
className="cursor-pointer text-amber-600/70 transition hover:text-amber-600 dark:text-amber-200/70 dark:hover:text-amber-200"
>
<XIcon className="h-4 w-4" />
</button>
</div>
{dialogOpen && profile?.userId && device?.id && privateKey && (
<BackupExportDialog
open={dialogOpen}
userId={profile.userId}
deviceId={device.id}
privateKey={privateKey}
onClose={closeDialog}
/>
)}
</>
);
}
@@ -0,0 +1,170 @@
import { useTranslation } from 'react-i18next';
import {
MicIcon,
MicOffIcon,
MonitorShareIcon,
MonitorStopIcon,
PhoneOffIcon,
UsersIcon,
VideoIcon,
} from './icons';
interface Props {
muted: boolean;
sharing: boolean;
video: boolean;
onToggleMute: () => void;
onToggleShare: () => void;
onToggleVideo?: () => void;
onHangup: () => void;
onOpenParticipants?: () => void;
/** Compact variant used inside the docked call (36px buttons). */
compact?: boolean;
/** Glass variant used when controls float on fullscreen cinema mode. */
glass?: boolean;
/** Disable transient interactions while the call isn't fully connected. */
disabledMedia?: boolean;
}
export function CallControls({
muted,
sharing,
video,
onToggleMute,
onToggleShare,
onToggleVideo,
onHangup,
onOpenParticipants,
compact = false,
glass = false,
disabledMedia = false,
}: Props) {
const { t } = useTranslation(['app']);
const wrapBase = glass
? 'glass-pill flex items-center justify-center gap-2 rounded-[18px] p-2.5'
: 'flex items-center justify-center gap-2 border-t border-line bg-surface-3 p-3';
const btnSize = compact ? 'h-9 w-9 rounded-[10px]' : 'h-12 w-12 rounded-[14px]';
const hangupSize = compact ? 'h-9 w-[54px] rounded-[10px]' : 'h-12 w-[72px] rounded-[14px]';
return (
<div className={wrapBase}>
<CallButton
label={muted ? t('app:call.unmute') : t('app:call.mute')}
active={muted}
activeTone="danger"
onClick={onToggleMute}
disabled={disabledMedia}
glass={glass}
className={btnSize}
>
{muted ? <MicOffIcon className="h-5 w-5" /> : <MicIcon className="h-5 w-5" />}
</CallButton>
{onToggleVideo && (
<CallButton
label={t('app:call.start_video', { defaultValue: 'Video' })}
active={video}
activeTone="accent"
onClick={onToggleVideo}
disabled={disabledMedia}
glass={glass}
className={btnSize}
>
<VideoIcon className="h-5 w-5" />
</CallButton>
)}
<CallButton
label={
sharing
? t('app:call.stop_share_screen', { defaultValue: 'Screen-Share stoppen' })
: t('app:call.share_screen', { defaultValue: 'Bildschirm teilen' })
}
active={sharing}
activeTone="accent"
onClick={onToggleShare}
disabled={disabledMedia}
glass={glass}
className={btnSize}
>
{sharing ? (
<MonitorStopIcon className="h-5 w-5" />
) : (
<MonitorShareIcon className="h-5 w-5" />
)}
</CallButton>
{onOpenParticipants && (
<CallButton
label={t('app:call.participants', { defaultValue: 'Teilnehmer' })}
onClick={onOpenParticipants}
glass={glass}
className={btnSize}
>
<UsersIcon className="h-5 w-5" />
</CallButton>
)}
<CallButton
label={t('app:call.hangup')}
onClick={onHangup}
tone="danger"
glass={glass}
className={hangupSize}
>
<PhoneOffIcon className="h-5 w-5" />
</CallButton>
</div>
);
}
interface CallButtonProps {
label: string;
onClick: () => void;
disabled?: boolean;
active?: boolean;
activeTone?: 'accent' | 'danger';
tone?: 'default' | 'danger';
glass?: boolean;
className?: string;
children: React.ReactNode;
}
function CallButton({
label,
onClick,
disabled,
active,
activeTone = 'accent',
tone = 'default',
glass = false,
className = '',
children,
}: CallButtonProps) {
const base =
'inline-flex cursor-pointer items-center justify-center border transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:cursor-not-allowed disabled:opacity-50';
let toneClass: string;
if (tone === 'danger') {
toneClass = 'bg-rose-600 text-white border-rose-600 hover:bg-rose-500';
} else if (active && activeTone === 'danger') {
toneClass = 'bg-rose-600 text-white border-rose-600 hover:bg-rose-500';
} else if (active) {
toneClass = 'bg-accent text-accent-fg border-accent hover:brightness-110';
} else if (glass) {
toneClass =
'border-white/15 bg-white/10 text-white hover:bg-white/15';
} else {
toneClass = 'border-line bg-surface-2 text-fg hover:bg-surface';
}
return (
<button
type="button"
onClick={onClick}
disabled={disabled}
aria-label={label}
aria-pressed={active}
title={label}
className={`${base} ${toneClass} ${className}`}
>
{children}
</button>
);
}
@@ -0,0 +1,254 @@
import { CrownIcon, LockIcon, MicOffIcon, MonitorShareIcon } from './icons';
export type AvatarColorKey = 'violet' | 'amber' | 'rose' | 'teal';
const AVATAR_COLORS: Record<AvatarColorKey, { bg: string; fg: string }> = {
// Tailwind classes tuned per spec: violet/amber/rose/teal swatches in both
// light and dark modes. Dark pairs invert to keep contrast readable.
violet: {
bg: 'bg-violet-200 dark:bg-violet-900/60',
fg: 'text-violet-800 dark:text-violet-200',
},
amber: {
bg: 'bg-amber-200 dark:bg-amber-900/60',
fg: 'text-amber-900 dark:text-amber-200',
},
rose: {
bg: 'bg-rose-200 dark:bg-rose-900/60',
fg: 'text-rose-900 dark:text-rose-200',
},
teal: {
bg: 'bg-teal-200 dark:bg-teal-900/60',
fg: 'text-teal-900 dark:text-teal-200',
},
};
const COLOR_KEYS: AvatarColorKey[] = ['violet', 'amber', 'rose', 'teal'];
// Stable per-user color from identity string — keeps avatars visually
// consistent across re-mounts without needing a color field on the profile.
export function colorKeyFor(id: string): AvatarColorKey {
let hash = 0;
for (let i = 0; i < id.length; i++) {
hash = (hash * 31 + id.charCodeAt(i)) >>> 0;
}
return COLOR_KEYS[hash % COLOR_KEYS.length]!;
}
export interface ParticipantTileProps {
userId: string;
displayName: string;
avatarUrl: string | null;
me: boolean;
muted: boolean;
speaking: boolean;
sharing: boolean;
video: boolean;
e2ee: boolean;
size?: 'default' | 'small';
focused?: boolean;
onClick?: () => void;
onOpenScreenShare?: () => void;
}
export function CallParticipantTile(props: ParticipantTileProps) {
const {
displayName,
me,
muted,
speaking,
sharing,
video,
e2ee,
size = 'default',
focused = false,
onClick,
onOpenScreenShare,
} = props;
const small = size === 'small';
const borderClass = speaking
? 'border-emerald-500 shadow-[0_0_0_2px_rgba(22,163,74,0.25)] dark:border-emerald-400'
: focused
? 'border-accent'
: 'border-line hover:border-accent';
return (
<div
onClick={onClick}
className={
'relative flex flex-col overflow-hidden rounded-[14px] border bg-surface-3 transition ' +
(onClick ? 'cursor-pointer ' : '') +
borderClass +
(small ? ' min-w-[140px]' : '')
}
>
{sharing ? (
<ScreenshareStub
displayName={displayName}
small={small}
onOpen={onOpenScreenShare}
/>
) : video ? (
<VideoStub {...props} small={small} />
) : (
<AudioContent {...props} small={small} />
)}
<div className="pointer-events-none absolute inset-x-2 bottom-2 flex items-center justify-between gap-2 rounded-lg glass-chip px-2.5 py-1.5">
<div className="flex min-w-0 items-center gap-1.5 text-xs font-semibold">
{me && <CrownIcon className="h-3 w-3 shrink-0 text-amber-300" />}
<span className="truncate">
{displayName}
{me ? ' (du)' : ''}
</span>
{e2ee && (
<span
aria-label="E2E verschlüsselt"
title="E2E verschlüsselt"
className="flex opacity-70"
>
<LockIcon className="h-3 w-3" />
</span>
)}
</div>
<div className="flex shrink-0 items-center gap-1">
{muted && (
<span className="flex h-5 w-5 items-center justify-center rounded-md bg-rose-500/80 text-white">
<MicOffIcon className="h-3 w-3" />
</span>
)}
{sharing && (
<span className="flex h-5 w-5 items-center justify-center rounded-md bg-emerald-500/80 text-white">
<MonitorShareIcon className="h-3 w-3" />
</span>
)}
</div>
</div>
</div>
);
}
function AudioContent({
userId,
displayName,
avatarUrl,
speaking,
small,
}: ParticipantTileProps & { small: boolean }) {
const key = colorKeyFor(userId);
const colors = AVATAR_COLORS[key];
const letter = displayName.trim().charAt(0).toUpperCase() || '?';
return (
<div className="flex min-h-0 flex-1 items-center justify-center p-4">
<div
className={
'relative flex items-center justify-center rounded-full ' +
(small ? 'h-11 w-11' : 'h-[72px] w-[72px]')
}
>
{speaking && (
<span
aria-hidden="true"
className="absolute -inset-1.5 animate-audio-pulse rounded-full border-2 border-emerald-500 dark:border-emerald-400"
/>
)}
{avatarUrl ? (
<img
src={avatarUrl}
alt=""
className="relative h-full w-full rounded-full object-cover"
/>
) : (
<span
className={
'relative flex h-full w-full items-center justify-center rounded-full font-bold ' +
colors.bg + ' ' + colors.fg + ' ' +
(small ? 'text-lg' : 'text-2xl')
}
>
{letter}
</span>
)}
</div>
</div>
);
}
function VideoStub({
userId,
displayName,
avatarUrl,
small,
}: ParticipantTileProps & { small: boolean }) {
// Video capture playback is out of scope for this UI iteration — show the
// audio-avatar gradient background as a placeholder so the layout is stable
// when a participant enables video.
const key = colorKeyFor(userId);
const colors = AVATAR_COLORS[key];
const letter = displayName.trim().charAt(0).toUpperCase() || '?';
return (
<div className="flex min-h-0 flex-1 items-center justify-center bg-gradient-to-br from-accent/20 to-surface-2 p-4">
<div
className={
'flex items-center justify-center rounded-full font-bold ' +
colors.bg + ' ' + colors.fg + ' ' +
(small ? 'h-11 w-11 text-lg' : 'h-[72px] w-[72px] text-2xl')
}
>
{avatarUrl ? (
<img src={avatarUrl} alt="" className="h-full w-full rounded-full object-cover" />
) : (
letter
)}
</div>
</div>
);
}
interface ScreenshareStubProps {
displayName: string;
small: boolean;
onOpen?: (() => void) | undefined;
}
// Fake browser window placeholder — click to open the real <video> viewer.
// Matches the design spec's "screenshare-stub" look.
function ScreenshareStub({ displayName, small, onOpen }: ScreenshareStubProps) {
return (
<button
type="button"
onClick={
onOpen
? (e) => {
e.stopPropagation();
onOpen();
}
: undefined
}
aria-label={`${displayName} teilt Bildschirm`}
className="relative flex min-h-0 flex-1 cursor-pointer items-center justify-center bg-ink-900 p-3 text-left focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
>
<div className="h-[85%] w-[90%] overflow-hidden rounded-lg border border-white/10 bg-ink-700">
<div className="flex h-[20px] items-center gap-1 bg-ink-600 px-2">
<span className="h-1.5 w-1.5 rounded-full bg-ink-500" />
<span className="h-1.5 w-1.5 rounded-full bg-ink-500" />
<span className="h-1.5 w-1.5 rounded-full bg-ink-500" />
</div>
<div className={'flex flex-col gap-2 ' + (small ? 'gap-[3px] p-1.5' : 'p-3.5')}>
<div className={'w-[60%] rounded ' + (small ? 'h-[3px]' : 'h-1.5') + ' bg-ink-500'} />
<div className={'w-[80%] rounded ' + (small ? 'h-[3px]' : 'h-1.5') + ' bg-ink-500'} />
<div className={'w-[40%] rounded ' + (small ? 'h-[3px]' : 'h-1.5') + ' bg-ink-500'} />
<div className={'my-1 rounded ' + (small ? 'h-[14px]' : 'h-10') + ' bg-accent/30'} />
<div className={'w-[70%] rounded ' + (small ? 'h-[3px]' : 'h-1.5') + ' bg-ink-500'} />
</div>
</div>
{!small && (
<div className="absolute left-3 top-3 flex items-center gap-1.5 glass-chip rounded-lg px-2.5 py-1 text-[10px] font-medium">
<MonitorShareIcon className="h-3 w-3" />
<span>{displayName} teilt Bildschirm</span>
</div>
)}
</button>
);
}
+126 -252
View File
@@ -1,26 +1,20 @@
import { useEffect, useState } from 'react'; import { useEffect } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom'; import { useLocation, useNavigate } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
import { useCall } from '../context/CallContext'; import { useCall } from '../context/CallContext';
import { useConversationsContext } from '../context/ConversationsContext'; import { useConversationsContext } from '../context/ConversationsContext';
import { useFriendshipsContext } from '../context/FriendshipsContext'; import { useFriendshipsContext } from '../context/FriendshipsContext';
import { ringtone } from '../lib/ringtone'; import { ringtone } from '../lib/ringtone';
import { useAnyActiveCall } from '../lib/useAnyActiveCall'; import { AvatarColorKey, colorKeyFor } from './CallParticipantTile';
import { useCallPresence } from '../lib/useCallPresence'; import { LockIcon, MonitorShareIcon, PhoneIcon, PhoneOffIcon } from './icons';
import {
MicIcon,
MicOffIcon,
PhoneIcon,
PhoneOffIcon,
SpinnerIcon,
XIcon,
} from './icons';
// Shell-level mount. Handles ringtones + the IncomingCallToast. // Shell-level mount. Responsibilities:
// The persistent CallBar (active-call widget) is rendered inside Sidebar so // - Start/stop ringtones by call-state transition.
// users can keep browsing/typing while a call is live. // - Toast-style incoming-call banner for conversations the user isn't in
// (clicking the toast routes to the docked IncomingCallPanel).
// - PiP widget when an active call is live but the user is looking at a
// different route.
export function CallUI() { export function CallUI() {
const { state } = useCall(); const { state } = useCall();
@@ -34,19 +28,37 @@ export function CallUI() {
return () => ringtone.stop(); return () => ringtone.stop();
}, []); }, []);
return <IncomingCallToast />; return (
<>
<IncomingCallToast />
<PipCall />
</>
);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
const TOAST_AVATAR: Record<AvatarColorKey, string> = {
violet: 'bg-violet-500/90 text-white',
amber: 'bg-amber-500/90 text-white',
rose: 'bg-rose-500/90 text-white',
teal: 'bg-teal-500/90 text-white',
};
function IncomingCallToast() { function IncomingCallToast() {
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
const { state, acceptIncoming, rejectIncoming } = useCall(); const { state, acceptIncoming, rejectIncoming } = useCall();
const { friendships } = useFriendshipsContext(); const { friendships } = useFriendshipsContext();
const { conversations } = useConversationsContext(); const { conversations } = useConversationsContext();
const navigate = useNavigate();
const location = useLocation();
if (state.kind !== 'incoming') return null; if (state.kind !== 'incoming') return null;
// When the user is already looking at the target conversation, the docked
// IncomingCallPanel handles the UI; hide the toast to avoid double chrome.
if (location.pathname === '/chats/' + state.conversationId) return null;
const conv = conversations.find((c) => c.id === state.conversationId) ?? null; const conv = conversations.find((c) => c.id === state.conversationId) ?? null;
const callerName = const callerName =
conv?.members.find((m) => m.userId === state.fromUserId)?.profile?.displayName ?? conv?.members.find((m) => m.userId === state.fromUserId)?.profile?.displayName ??
@@ -54,44 +66,55 @@ function IncomingCallToast() {
'?'; '?';
const isGroup = conv?.type === 'group'; const isGroup = conv?.type === 'group';
const groupName = isGroup ? (conv?.name ?? t('app:chats.new_group')) : null; const groupName = isGroup ? (conv?.name ?? t('app:chats.new_group')) : null;
const letter = (isGroup ? groupName ?? callerName : callerName) const title = isGroup ? groupName ?? callerName : callerName;
.trim() const letter = title.trim().charAt(0).toUpperCase() || '?';
.charAt(0) const color = colorKeyFor(state.fromUserId);
.toUpperCase() || '?';
return ( return (
<div <div
role="dialog" role="dialog"
aria-modal="false" aria-modal="false"
aria-label={t('app:call.incoming_title')} aria-label={t('app:call.incoming_title')}
className="fixed bottom-6 right-6 z-50 w-80 animate-slide-up rounded-2xl border border-white/10 bg-ink-900/95 p-5 shadow-2xl backdrop-blur-xl" className="fixed bottom-6 right-6 z-50 w-80 animate-slide-up overflow-hidden rounded-2xl border border-line bg-surface-3 shadow-call-card-dark"
> >
<p className="text-xs font-medium uppercase tracking-wide text-neutral-500"> <button
{t('app:call.incoming_title')} type="button"
</p> onClick={() => navigate('/chats/' + state.conversationId)}
<div className="mt-3 flex items-center gap-3"> className="group block w-full cursor-pointer p-5 text-left transition hover:bg-surface-2 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
<div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-brand-500/30 text-base font-semibold text-white ring-1 ring-brand-400/30"> >
{letter} <p className="text-[10px] font-semibold uppercase tracking-[0.12em] text-fg-muted">
{t('app:call.incoming_title')}
</p>
<div className="mt-2 flex items-center gap-3">
<div
className={
'flex h-11 w-11 shrink-0 items-center justify-center rounded-full font-semibold ' +
TOAST_AVATAR[color]
}
>
{letter}
</div>
<div className="min-w-0 flex-1">
<p className="truncate font-display text-base font-semibold text-fg">{title}</p>
<p className="flex items-center gap-1.5 truncate text-xs text-fg-muted">
<LockIcon className="h-3 w-3" />
<span>
{isGroup
? t('app:call.incoming_group_from', {
name: callerName,
defaultValue: callerName + ' ruft Gruppe',
})
: t('app:call.incoming_from', { name: callerName })}
</span>
</p>
</div>
</div> </div>
<div className="min-w-0 flex-1"> </button>
<p className="truncate font-display text-base font-semibold text-white"> <div className="flex gap-2 px-5 pb-5">
{isGroup ? groupName : callerName}
</p>
<p className="truncate text-xs text-neutral-400">
{isGroup
? t('app:call.incoming_group_from', {
name: callerName,
defaultValue: callerName + ' ruft Gruppe',
})
: t('app:call.incoming_from', { name: callerName })}
</p>
</div>
</div>
<div className="mt-4 flex gap-2">
<button <button
type="button" type="button"
onClick={rejectIncoming} onClick={rejectIncoming}
className="inline-flex flex-1 cursor-pointer items-center justify-center gap-2 rounded-lg border border-rose-500/30 bg-rose-500/10 px-3 py-2 text-sm font-semibold text-rose-200 transition hover:bg-rose-500/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-rose-400/40" className="inline-flex flex-1 cursor-pointer items-center justify-center gap-2 rounded-lg border border-rose-500/40 bg-transparent px-3 py-2 text-sm font-semibold text-rose-600 transition hover:bg-rose-500/10 focus:outline-none focus-visible:ring-2 focus-visible:ring-rose-500/40 dark:text-rose-400"
> >
<PhoneOffIcon className="h-4 w-4" /> <PhoneOffIcon className="h-4 w-4" />
<span>{t('app:call.decline')}</span> <span>{t('app:call.decline')}</span>
@@ -99,7 +122,7 @@ function IncomingCallToast() {
<button <button
type="button" type="button"
onClick={() => void acceptIncoming()} onClick={() => void acceptIncoming()}
className="inline-flex flex-1 cursor-pointer items-center justify-center gap-2 rounded-lg bg-emerald-500/90 px-3 py-2 text-sm font-semibold text-white transition hover:bg-emerald-400 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400/40" className="inline-flex flex-1 cursor-pointer items-center justify-center gap-2 rounded-lg bg-emerald-600 px-3 py-2 text-sm font-semibold text-white transition hover:bg-emerald-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500/50"
> >
<PhoneIcon className="h-4 w-4" /> <PhoneIcon className="h-4 w-4" />
<span>{t('app:call.accept')}</span> <span>{t('app:call.accept')}</span>
@@ -110,226 +133,77 @@ function IncomingCallToast() {
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// CallBar — persistent widget inside Sidebar. Lets the user keep browsing // PiP widget — shown when the user has an active call but is browsing
// the app while a call is active / connecting / ringing. // somewhere else. Clicking expands back to the call's conversation.
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export function CallBar() { function PipCall() {
const { state, lastCallConversationId } = useCall();
const { conversations } = useConversationsContext();
const { session } = useAuth();
const myId = session?.user.id ?? null;
// Aggregate observer across every conversation the user is in so a
// "call is live, rejoin" affordance appears in the sidebar whenever ANY
// peer is in a call — not just calls I previously joined.
const convIds = conversations.map((c) => c.id);
const anyActive = useAnyActiveCall(convIds, myId);
if (state.kind === 'connected' || state.kind === 'connecting' || state.kind === 'outgoing') {
return <ActiveCallBar />;
}
// Prefer the conversation I just left, fall back to any other live call.
const rejoinId = lastCallConversationId ?? anyActive?.conversationId ?? null;
if (rejoinId) {
return <RejoinCallBar conversationId={rejoinId} />;
}
return null;
}
function ActiveCallBar() {
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
const { state, isMuted, hangup, toggleMute } = useCall(); const {
state,
remoteParticipants,
remoteScreenShares,
hangup,
} = useCall();
const navigate = useNavigate();
const location = useLocation();
const { conversations } = useConversationsContext(); const { conversations } = useConversationsContext();
const [, forceTick] = useState(0); const active =
useEffect(() => { state.kind === 'connected' ||
if (state.kind !== 'connected') return; state.kind === 'connecting' ||
const id = window.setInterval(() => forceTick((v) => v + 1), 1000); state.kind === 'outgoing';
return () => window.clearInterval(id); if (!active) return null;
}, [state.kind]);
if (state.kind !== 'connected' && state.kind !== 'connecting' && state.kind !== 'outgoing') { // Only render when the user is NOT currently viewing the call's
return null; // conversation. Inside that conversation the full dock is visible already.
} if (location.pathname === '/chats/' + state.conversationId) return null;
const conv = conversations.find((c) => c.id === state.conversationId) ?? null; const conv = conversations.find((c) => c.id === state.conversationId) ?? null;
const title = const title =
conv?.type === 'group' conv?.type === 'group'
? conv.name ?? '—' ? conv?.name ?? t('app:chats.new_group')
: conv?.peer?.displayName ?? '—'; : conv?.peer?.displayName ?? '—';
const participantCount = 1 + remoteParticipants.length;
const statusLabel = const someoneSharing = remoteScreenShares.length > 0;
state.kind === 'outgoing'
? t('app:call.outgoing_ringing')
: state.kind === 'connecting'
? t('app:call.connecting')
: t('app:call.voice_connected', { defaultValue: 'Sprachchat verbunden' });
const elapsed =
state.kind === 'connected'
? formatElapsed(Date.now() - new Date(state.startedAt).getTime())
: null;
return ( return (
<div className="mb-2 overflow-hidden rounded-xl border border-emerald-500/20 bg-ink-900/80"> <div
<Link role="dialog"
to={'/chats/' + state.conversationId} aria-label={t('app:call.active_in_conv', { defaultValue: 'Aktiver Anruf' })}
className="flex items-center gap-2.5 px-3 pt-2.5 pb-2 transition hover:bg-white/5 focus:outline-none" onClick={() => navigate('/chats/' + state.conversationId)}
aria-label={statusLabel} className="fixed bottom-5 right-5 z-40 flex w-[260px] animate-slide-in-call cursor-pointer items-center gap-2.5 rounded-[14px] border border-accent bg-surface-3 p-2.5 shadow-pip-call transition hover:-translate-y-0.5"
>
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-emerald-500/15 text-emerald-300">
{state.kind === 'connecting' ? (
<SpinnerIcon className="h-4 w-4" />
) : (
<SignalIcon className="h-4 w-4" />
)}
</div>
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-semibold text-emerald-300">{statusLabel}</p>
<p className="truncate text-xs text-neutral-400">
{title}
{elapsed && <span className="ml-1.5 font-mono text-neutral-500">{elapsed}</span>}
</p>
</div>
</Link>
<div className="grid grid-cols-2 gap-1 border-t border-white/5 bg-ink-950/40 p-1.5">
<IconTile
onClick={toggleMute}
disabled={state.kind !== 'connected'}
label={isMuted ? t('app:call.unmute') : t('app:call.mute')}
tone={isMuted ? 'amber' : 'neutral'}
>
{isMuted ? <MicOffIcon className="h-4 w-4" /> : <MicIcon className="h-4 w-4" />}
</IconTile>
<IconTile onClick={() => void hangup()} label={t('app:call.hangup')} tone="rose">
<PhoneOffIcon className="h-4 w-4" />
</IconTile>
</div>
</div>
);
}
function RejoinCallBar({ conversationId }: { conversationId: string }) {
const { t } = useTranslation(['app', 'common']);
const { joinActiveCall, dismissLastCall } = useCall();
const { conversations } = useConversationsContext();
const { session } = useAuth();
const active = useCallPresence(conversationId);
const myId = session?.user.id;
const others = active.filter((u) => u !== myId);
// Presence polling returns [] on the first tick before it syncs, so we can't
// treat an initial empty list as "room is empty". Only dismiss after we've
// actually seen peers and then watched them leave — and even then confirm
// the empty state for a grace period, since presence_diff events can
// arrive slightly out of order.
const [visible, setVisible] = useState(false);
useEffect(() => {
if (others.length > 0) {
setVisible(true);
return;
}
if (!visible) return;
const id = window.setTimeout(() => {
setVisible(false);
dismissLastCall();
}, 2500);
return () => window.clearTimeout(id);
}, [others.length, visible, dismissLastCall]);
if (!visible) return null;
const conv = conversations.find((c) => c.id === conversationId) ?? null;
const title =
conv?.type === 'group'
? conv.name ?? '—'
: conv?.peer?.displayName ?? '—';
return (
<div className="mb-2 overflow-hidden rounded-xl border border-emerald-500/20 bg-ink-900/80">
<Link
to={'/chats/' + conversationId}
className="flex items-center gap-2.5 px-3 pt-2.5 pb-2 transition hover:bg-white/5 focus:outline-none"
>
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-emerald-500/15 text-emerald-300">
<SignalIcon className="h-4 w-4" />
</div>
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-semibold text-emerald-300">
{t('app:call.still_live', { defaultValue: 'Anruf läuft noch' })}
</p>
<p className="truncate text-xs text-neutral-400">
{title} · {others.length}
</p>
</div>
</Link>
<div className="grid grid-cols-2 gap-1 border-t border-white/5 bg-ink-950/40 p-1.5">
<IconTile
onClick={() => void joinActiveCall(conversationId, 'audio')}
label={t('app:call.join')}
tone="emerald"
>
<PhoneIcon className="h-4 w-4" />
</IconTile>
<IconTile onClick={dismissLastCall} label={t('common:close', { defaultValue: 'Schließen' })} tone="neutral">
<XIcon className="h-4 w-4" />
</IconTile>
</div>
</div>
);
}
interface IconTileProps {
onClick: () => void;
label: string;
tone: 'neutral' | 'amber' | 'rose' | 'emerald';
disabled?: boolean;
children: React.ReactNode;
}
function IconTile({ onClick, label, tone, disabled, children }: IconTileProps) {
const toneClass =
tone === 'rose'
? 'bg-white/5 text-rose-300 hover:bg-rose-500/20 focus-visible:ring-rose-400/40'
: tone === 'amber'
? 'bg-amber-500/20 text-amber-200 hover:bg-amber-500/30 focus-visible:ring-amber-400/40'
: tone === 'emerald'
? 'bg-emerald-500/20 text-emerald-200 hover:bg-emerald-500/30 focus-visible:ring-emerald-400/40'
: 'bg-white/5 text-neutral-200 hover:bg-white/10 focus-visible:ring-brand-400/40';
return (
<button
type="button"
onClick={onClick}
disabled={disabled}
aria-label={label}
title={label}
className={
'inline-flex h-9 cursor-pointer items-center justify-center rounded-md transition focus:outline-none focus-visible:ring-2 disabled:cursor-not-allowed disabled:opacity-50 ' +
toneClass
}
> >
{children} <div className="flex h-11 w-11 shrink-0 items-center justify-center overflow-hidden rounded-[10px] bg-surface-2">
</button> {someoneSharing ? (
<MonitorShareIcon className="h-5 w-5 text-accent" />
) : (
<PhoneIcon className="h-5 w-5 text-accent" />
)}
</div>
<div className="min-w-0 flex-1">
<p className="truncate text-[13px] font-semibold text-fg">
{title} · {participantCount}
</p>
<p className="mt-0.5 flex items-center gap-1.5 text-[11px] text-fg-muted">
<span
aria-hidden="true"
className="h-1.5 w-1.5 rounded-full bg-rose-500 animate-live-dot"
/>
<span>Live · {t('app:call.tap_to_open', { defaultValue: 'tippe zum Öffnen' })}</span>
</p>
</div>
<button
type="button"
onClick={(e) => {
e.stopPropagation();
void hangup();
}}
aria-label={t('app:call.hangup')}
className="flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full bg-rose-600 text-white transition hover:bg-rose-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-rose-400/60"
>
<PhoneOffIcon className="h-4 w-4" />
</button>
</div>
); );
} }
function SignalIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" {...props}>
<path d="M5 12v0" />
<path d="M9 9v6" />
<path d="M13 6v12" />
<path d="M17 9v6" />
</svg>
);
}
function formatElapsed(ms: number): string {
const total = Math.max(0, Math.floor(ms / 1000));
const mm = Math.floor(total / 60).toString().padStart(2, '0');
const ss = (total % 60).toString().padStart(2, '0');
return mm + ':' + ss;
}
@@ -1,31 +1,39 @@
import type { ConversationSummary } from '@chat-app/shared/chat'; import type { ConversationSummary } from '@chat-app/shared/chat';
import type { PresenceState } from '@chat-app/shared/supabase'; import type { PresenceState } from '@chat-app/shared/supabase';
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useAuth } from '../context/AuthContext'; import { useAuth } from '../context/AuthContext';
import { useCall } from '../context/CallContext'; import { useCall } from '../context/CallContext';
import { useCallPresence } from '../lib/useCallPresence'; import { useCallPresence } from '../lib/useCallPresence';
import { InfoIcon, PhoneIcon, SpinnerIcon, UsersIcon } from './icons'; import { Avatar } from './Avatar';
import {
InfoIcon,
PhoneIcon,
SearchIcon,
SpinnerIcon,
UsersIcon,
VideoIcon,
} from './icons';
const PRESENCE_DOT: Record<PresenceState, string> = { const PRESENCE_DOT: Record<PresenceState, string> = {
online: 'bg-emerald-400', online: 'bg-emerald-500',
idle: 'bg-amber-400', idle: 'bg-amber-400',
dnd: 'bg-rose-500', dnd: 'bg-rose-500',
invisible: 'bg-neutral-500', invisible: 'bg-neutral-500',
offline: 'bg-neutral-600', offline: 'bg-neutral-400 dark:bg-neutral-600',
}; };
interface Props { interface Props {
conversation: ConversationSummary | null; conversation: ConversationSummary | null;
peerPresence: PresenceState | null; peerPresence: PresenceState | null;
onInfoClick?: () => void; onInfoClick?: () => void;
onSearchClick?: () => void;
} }
export function ConversationHeader({ conversation, peerPresence, onInfoClick }: Props) { export function ConversationHeader({ conversation, peerPresence, onInfoClick, onSearchClick }: Props) {
if (!conversation) { if (!conversation) {
return ( return <header className="h-[57px] border-b border-line px-6 py-3" aria-busy="true" />;
<header className="h-[57px] border-b border-white/5 px-6 py-3" aria-busy="true" />
);
} }
return ( return (
@@ -34,6 +42,7 @@ export function ConversationHeader({ conversation, peerPresence, onInfoClick }:
conversation={conversation} conversation={conversation}
peerPresence={peerPresence} peerPresence={peerPresence}
{...(onInfoClick ? { onInfoClick } : {})} {...(onInfoClick ? { onInfoClick } : {})}
{...(onSearchClick ? { onSearchClick } : {})}
/> />
<ActiveCallBanner conversationId={conversation.id} /> <ActiveCallBanner conversationId={conversation.id} />
</> </>
@@ -44,43 +53,52 @@ interface HeaderBarProps {
conversation: ConversationSummary; conversation: ConversationSummary;
peerPresence: PresenceState | null; peerPresence: PresenceState | null;
onInfoClick?: () => void; onInfoClick?: () => void;
onSearchClick?: () => void;
} }
function HeaderBar({ conversation, peerPresence, onInfoClick }: HeaderBarProps) { function HeaderBar({ conversation, peerPresence, onInfoClick, onSearchClick }: HeaderBarProps) {
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
const isDm = conversation.type === 'dm'; const isDm = conversation.type === 'dm';
const title = isDm ? (conversation.peer?.displayName ?? '?') : (conversation.name ?? '?'); const title = isDm ? (conversation.peer?.displayName ?? '?') : (conversation.name ?? '?');
const handle = isDm ? '@' + (conversation.peer?.username ?? '?') : ''; const handle = isDm ? '@' + (conversation.peer?.username ?? '?') : '';
const letter = title.trim().charAt(0).toUpperCase() || '?'; const peerAvatar = isDm ? (conversation.peer?.avatarUrl ?? null) : (conversation.avatarUrl ?? null);
// Hide presence when peer chose invisible — reciprocal privacy. // Hide presence when peer chose invisible — reciprocal privacy.
const showPresence = isDm && peerPresence && peerPresence !== 'invisible'; const showPresence = isDm && peerPresence && peerPresence !== 'invisible';
const presenceLabel = peerPresence ? t('app:presence.' + peerPresence) : ''; const presenceLabel = peerPresence ? t('app:presence.' + peerPresence) : '';
return ( return (
<header className="flex items-center gap-3 border-b border-white/5 px-6 py-3"> <header className="flex items-center gap-3 border-b border-line bg-surface-3 px-6 py-3">
<div className="relative flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-brand-500/30 text-base font-semibold text-white ring-1 ring-brand-400/30"> <div className="relative">
{isDm ? letter : <UsersIcon className="h-5 w-5" />} {isDm ? (
<Avatar url={peerAvatar} displayName={title} className="h-10 w-10 text-base" />
) : peerAvatar ? (
<Avatar url={peerAvatar} displayName={title} className="h-10 w-10 text-base" />
) : (
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-accent/20 text-accent">
<UsersIcon className="h-5 w-5" />
</div>
)}
{showPresence && peerPresence && ( {showPresence && peerPresence && (
<span <span
aria-hidden="true" aria-hidden="true"
className={ className={
'absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full ring-2 ring-ink-950 ' + 'absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full ring-2 ring-surface-3 ' +
PRESENCE_DOT[peerPresence] PRESENCE_DOT[peerPresence]
} }
/> />
)} )}
</div> </div>
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="truncate font-display text-base font-semibold text-white">{title}</p> <p className="truncate font-display text-base font-semibold text-fg">{title}</p>
<p className="truncate text-xs text-neutral-500"> <p className="truncate text-xs text-fg-muted">
{isDm ? ( {isDm ? (
<> <>
<span>{handle}</span> <span>{handle}</span>
{showPresence && ( {showPresence && (
<> <>
<span className="mx-1.5 text-neutral-700">·</span> <span className="mx-1.5 text-fg-muted/50">·</span>
<span>{presenceLabel}</span> <span>{presenceLabel}</span>
</> </>
)} )}
@@ -93,75 +111,133 @@ function HeaderBar({ conversation, peerPresence, onInfoClick }: HeaderBarProps)
</p> </p>
</div> </div>
<CallHeaderButton conversationId={conversation.id} /> <HeaderActionButton
label={t('app:chats.search', { defaultValue: 'Suche' })}
icon={SearchIcon}
{...(onSearchClick ? { onClick: onSearchClick } : {})}
/>
<CallHeaderButton conversationId={conversation.id} kind="audio" />
<CallHeaderButton conversationId={conversation.id} kind="video" />
{!isDm && onInfoClick && ( {!isDm && onInfoClick && (
<button <HeaderActionButton
type="button" label={t('app:group.info_title')}
icon={InfoIcon}
onClick={onInfoClick} onClick={onInfoClick}
aria-label={t('app:group.info_title')} />
title={t('app:group.info_title')}
className="flex h-9 w-9 cursor-pointer items-center justify-center rounded-lg text-neutral-400 transition hover:bg-white/10 hover:text-neutral-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40"
>
<InfoIcon className="h-4 w-4" />
</button>
)} )}
</header> </header>
); );
} }
function CallHeaderButton({ conversationId }: { conversationId: string }) { interface HeaderActionButtonProps {
const { t } = useTranslation(['app']); label: string;
const { state, startCall } = useCall(); icon: (props: React.SVGProps<SVGSVGElement>) => React.JSX.Element;
const busy = state.kind !== 'idle'; onClick?: () => void;
disabled?: boolean;
tone?: 'default' | 'accent';
}
function HeaderActionButton({
label,
icon: Icon,
onClick,
disabled,
tone = 'default',
}: HeaderActionButtonProps) {
const toneClass =
tone === 'accent'
? 'text-accent hover:bg-accent/10'
: 'text-fg-muted hover:bg-surface-2 hover:text-fg';
return ( return (
<button <button
type="button" type="button"
onClick={() => void startCall(conversationId, 'audio')} onClick={onClick}
disabled={busy} disabled={disabled}
aria-label={t('app:call.start_audio')} aria-label={label}
title={busy ? t('app:call.busy') : t('app:call.start_audio')} title={label}
className="flex h-9 w-9 cursor-pointer items-center justify-center rounded-lg text-neutral-400 transition hover:bg-white/10 hover:text-brand-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 disabled:cursor-not-allowed disabled:opacity-50" className={
'flex h-9 w-9 cursor-pointer items-center justify-center rounded-lg transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:cursor-not-allowed disabled:opacity-50 ' +
toneClass
}
> >
<PhoneIcon className="h-4 w-4" /> <Icon className="h-4 w-4" />
</button> </button>
); );
} }
function CallHeaderButton({
conversationId,
kind,
}: {
conversationId: string;
kind: 'audio' | 'video';
}) {
const { t } = useTranslation(['app']);
const { state, startCall } = useCall();
const busy = state.kind !== 'idle';
const label =
kind === 'video'
? t('app:call.start_video', { defaultValue: 'Video-Anruf' })
: t('app:call.start_audio');
const Icon = kind === 'video' ? VideoIcon : PhoneIcon;
return (
<HeaderActionButton
label={busy ? t('app:call.busy') : label}
icon={Icon}
onClick={() => void startCall(conversationId, kind)}
disabled={busy}
/>
);
}
function ActiveCallBanner({ conversationId }: { conversationId: string }) { function ActiveCallBanner({ conversationId }: { conversationId: string }) {
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
const { session } = useAuth(); const { session } = useAuth();
const { state, joinActiveCall } = useCall(); const { state, joinActiveCall, lastCallConversationId, dismissLastCall } = useCall();
const active = useCallPresence(conversationId); const active = useCallPresence(conversationId);
const myId = session?.user.id; const myId = session?.user.id;
// Source of truth for "am I in this call" is the CallContext state, not
// presence — my own presence entry can lag behind the room join, which
// would otherwise make the banner flash while I'm already connected.
const iAmIn = const iAmIn =
(state.kind === 'connected' || (state.kind === 'connected' ||
state.kind === 'connecting' || state.kind === 'connecting' ||
state.kind === 'outgoing') && state.kind === 'outgoing') &&
state.conversationId === conversationId; state.conversationId === conversationId;
// Only show banner when other people are in it and I'm not.
const othersIn = active.filter((u) => u !== myId); const othersIn = active.filter((u) => u !== myId);
if (iAmIn || othersIn.length === 0) return null; // Fallback signal: I just left this conv with peers still inside. Covers the
// brief window after hangup where presence may not have re-synced yet (the
// realtime channel can churn while ConversationHeader remounts).
const justLeft = state.kind === 'idle' && lastCallConversationId === conversationId;
// Once presence confirms the room is empty, drop the "just left" hint so the
// banner hides cleanly instead of sticking forever. Grace window handles the
// brief gap between hangup and presence re-sync so we don't flicker.
useEffect(() => {
if (!justLeft) return;
if (othersIn.length > 0) return; // still live — keep banner
const id = window.setTimeout(() => dismissLastCall(), 3000);
return () => window.clearTimeout(id);
}, [justLeft, othersIn.length, dismissLastCall]);
if (iAmIn) return null;
if (othersIn.length === 0 && !justLeft) return null;
const count = Math.max(othersIn.length, justLeft ? 1 : 0);
const busy = state.kind !== 'idle'; const busy = state.kind !== 'idle';
return ( return (
<div className="flex items-center gap-3 border-b border-emerald-500/20 bg-emerald-500/10 px-6 py-2.5 text-sm text-emerald-100"> <div className="flex items-center gap-3 border-b border-emerald-500/30 bg-emerald-500/10 px-6 py-2.5 text-sm text-emerald-700 dark:text-emerald-100">
<PhoneIcon className="h-4 w-4 text-emerald-300" /> <PhoneIcon className="h-4 w-4 text-emerald-600 dark:text-emerald-300" />
<span className="flex-1"> <span className="flex-1">
{t('app:call.active_in_conv', { {t('app:call.active_in_conv', {
defaultValue: 'Active call · {{count}} in room', defaultValue: 'Active call · {{count}} in room',
count: othersIn.length, count,
})} })}
</span> </span>
<button <button
type="button" type="button"
onClick={() => void joinActiveCall(conversationId, 'audio')} onClick={() => void joinActiveCall(conversationId, 'audio')}
disabled={busy} disabled={busy}
className="inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-emerald-500/90 px-3 py-1.5 text-xs font-semibold text-white transition hover:bg-emerald-400 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400/40 disabled:cursor-not-allowed disabled:opacity-60" className="inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-emerald-600 px-3 py-1.5 text-xs font-semibold text-white transition hover:bg-emerald-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400/40 disabled:cursor-not-allowed disabled:opacity-60"
> >
{busy ? ( {busy ? (
<SpinnerIcon className="h-3.5 w-3.5" /> <SpinnerIcon className="h-3.5 w-3.5" />
@@ -0,0 +1,264 @@
import {
muteDurationToIso,
setConversationArchived,
setConversationMutedUntil,
} from '@chat-app/shared/chat';
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { useTranslation } from 'react-i18next';
import { supabase } from '../lib/supabase';
import { ArchiveIcon, BellIcon, BellOffIcon, MoreVerticalIcon } from './icons';
interface Props {
conversationId: string;
archived: boolean;
mutedUntil: string | null;
}
interface MuteOption {
key: string;
labelKey: string;
labelDefault: string;
minutes: number | null;
}
// Muted-forever sentinel ≈ 100 years. UI treats any future timestamp as muted
// until that moment; 100y is indistinguishable from "forever" at the UX level
// without requiring a dedicated `bool muted_forever` column.
const FOREVER_MINUTES = 100 * 365 * 24 * 60;
const MUTE_OPTIONS: MuteOption[] = [
{ key: '1h', labelKey: 'app:chats.mute_1h', labelDefault: '1 Stunde', minutes: 60 },
{ key: '8h', labelKey: 'app:chats.mute_8h', labelDefault: '8 Stunden', minutes: 8 * 60 },
{ key: '24h', labelKey: 'app:chats.mute_24h', labelDefault: '24 Stunden', minutes: 24 * 60 },
{ key: '1w', labelKey: 'app:chats.mute_1w', labelDefault: '1 Woche', minutes: 7 * 24 * 60 },
{
key: 'forever',
labelKey: 'app:chats.mute_forever',
labelDefault: 'Bis auf Weiteres',
minutes: FOREVER_MINUTES,
},
];
interface MenuPos {
top: number;
left: number;
}
// Per-conversation row context-menu. Renders via portal so the submenu can
// escape the sidebar's `overflow-y-auto` clipping context. Position is
// computed from the trigger's bounding rect — menu anchors right-aligned
// under the trigger so it doesn't push off-screen on narrow windows.
export function ConversationRowMenu({ conversationId, archived, mutedUntil }: Props) {
const { t } = useTranslation(['app']);
const [open, setOpen] = useState(false);
const [submenuOpen, setSubmenuOpen] = useState<'mute' | null>(null);
const [menuPos, setMenuPos] = useState<MenuPos | null>(null);
const [submenuPos, setSubmenuPos] = useState<MenuPos | null>(null);
const triggerRef = useRef<HTMLButtonElement>(null);
const menuRef = useRef<HTMLDivElement>(null);
const muteItemRef = useRef<HTMLButtonElement>(null);
useEffect(() => {
if (!open) return;
function onDocClick(e: MouseEvent) {
const target = e.target as Node;
if (triggerRef.current?.contains(target)) return;
if (menuRef.current?.contains(target)) return;
setOpen(false);
setSubmenuOpen(null);
}
function onEsc(e: KeyboardEvent) {
if (e.key === 'Escape') {
setOpen(false);
setSubmenuOpen(null);
}
}
document.addEventListener('mousedown', onDocClick);
document.addEventListener('keydown', onEsc);
return () => {
document.removeEventListener('mousedown', onDocClick);
document.removeEventListener('keydown', onEsc);
};
}, [open]);
useEffect(() => {
if (!open) {
setMenuPos(null);
setSubmenuPos(null);
return;
}
const rect = triggerRef.current?.getBoundingClientRect();
if (!rect) return;
// Anchor: right edge aligns with trigger's right edge, menu hangs below.
const menuWidth = 208;
setMenuPos({
top: rect.bottom + 4,
left: Math.max(8, rect.right - menuWidth),
});
}, [open]);
useEffect(() => {
if (submenuOpen !== 'mute') {
setSubmenuPos(null);
return;
}
const rect = muteItemRef.current?.getBoundingClientRect();
if (!rect) return;
const submenuWidth = 192;
const viewportWidth = window.innerWidth;
// Prefer right of the item. Flip to left when it would overflow viewport.
const wantLeft = rect.right + 4;
const flip = wantLeft + submenuWidth > viewportWidth - 8;
setSubmenuPos({
top: rect.top,
left: flip ? rect.left - submenuWidth - 4 : wantLeft,
});
}, [submenuOpen]);
const isMuted =
mutedUntil !== null && new Date(mutedUntil).getTime() > Date.now();
const handleArchive = useCallback(
async (next: boolean) => {
setOpen(false);
try {
await setConversationArchived(supabase, conversationId, next);
} catch (err: unknown) {
console.error('archive toggle failed', err);
}
},
[conversationId],
);
const handleMute = useCallback(
async (minutes: number | null) => {
setOpen(false);
setSubmenuOpen(null);
try {
await setConversationMutedUntil(
supabase,
conversationId,
muteDurationToIso(minutes),
);
} catch (err: unknown) {
console.error('mute toggle failed', err);
}
},
[conversationId],
);
return (
<>
<button
ref={triggerRef}
type="button"
aria-label={t('app:chats.row_menu', { defaultValue: 'Aktionen' })}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
setOpen((v) => !v);
}}
onMouseDown={(e) => e.stopPropagation()}
className="flex h-7 w-7 cursor-pointer items-center justify-center rounded-md text-fg-muted opacity-0 transition group-hover:opacity-100 hover:bg-surface-3 hover:text-fg focus:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
>
<MoreVerticalIcon className="h-4 w-4" />
</button>
{open &&
menuPos &&
createPortal(
<div
ref={menuRef}
role="menu"
style={{ top: menuPos.top, left: menuPos.left }}
className="fixed z-50 w-52 rounded-lg border border-line bg-surface-3 p-1 shadow-xl"
>
<MenuItem
icon={<ArchiveIcon className="h-4 w-4" />}
label={
archived
? t('app:chats.unarchive', { defaultValue: 'Entarchivieren' })
: t('app:chats.archive', { defaultValue: 'Archivieren' })
}
onClick={() => void handleArchive(!archived)}
/>
<MenuItem
ref={muteItemRef}
icon={
isMuted ? (
<BellOffIcon className="h-4 w-4" />
) : (
<BellIcon className="h-4 w-4" />
)
}
label={
isMuted
? t('app:chats.unmute', { defaultValue: 'Stummschaltung aufheben' })
: t('app:chats.mute', { defaultValue: 'Stummschalten' })
}
onClick={() => {
if (isMuted) void handleMute(null);
else setSubmenuOpen((v) => (v === 'mute' ? null : 'mute'));
}}
hasSubmenu={!isMuted}
/>
</div>,
document.body,
)}
{open &&
submenuOpen === 'mute' &&
submenuPos &&
createPortal(
<div
role="menu"
style={{ top: submenuPos.top, left: submenuPos.left }}
className="fixed z-50 w-48 rounded-lg border border-line bg-surface-3 p-1 shadow-xl"
>
{MUTE_OPTIONS.map((opt) => (
<MenuItem
key={opt.key}
label={t(opt.labelKey, { defaultValue: opt.labelDefault })}
onClick={() => void handleMute(opt.minutes)}
/>
))}
</div>,
document.body,
)}
</>
);
}
interface MenuItemProps {
icon?: React.ReactNode;
label: string;
onClick: () => void;
hasSubmenu?: boolean;
}
// React 18 requires forwardRef for function components to receive refs —
// without it the `ref` prop is stripped before reaching the component and
// measurement-dependent submenus never position.
const MenuItem = forwardRef<HTMLButtonElement, MenuItemProps>(
({ icon, label, onClick, hasSubmenu }, ref) => (
<button
ref={ref}
type="button"
role="menuitem"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onClick();
}}
onMouseDown={(e) => e.stopPropagation()}
className="flex w-full cursor-pointer items-center gap-2.5 rounded-md px-2.5 py-1.5 text-left text-sm text-fg transition hover:bg-surface-2 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
>
{icon && <span className="shrink-0 text-fg-muted">{icon}</span>}
<span className="min-w-0 flex-1 truncate">{label}</span>
{hasSubmenu && <span className="shrink-0 text-xs text-fg-muted"></span>}
</button>
),
);
MenuItem.displayName = 'MenuItem';
@@ -0,0 +1,160 @@
import {
type DeviceRecord,
restoreDeviceFromServerRecord,
} from '@chat-app/shared/auth';
import { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
decodePrivateKeyFromBackup,
importDeviceBackup,
} from '../lib/deviceBackup';
import { devLocalSecretStore } from '../lib/secretStore';
import { supabase } from '../lib/supabase';
import { writeLocalDeviceId } from '../lib/device';
import { AlertIcon, ArrowRightIcon, LockIcon, ShieldIcon, SpinnerIcon } from './icons';
interface Props {
userId: string;
onRestored: (device: DeviceRecord) => void;
}
// Restores a device from a user-provided backup string. The backup embeds
// userId + deviceId + X25519 private key; we verify userId matches the current
// session, confirm the device row still exists server-side, and then re-seed
// the local vault + cached deviceId so the app treats this install as the
// original device (conv-key bundles stay valid, no "awaiting" state).
export function DeviceRestore({ userId, onRestored }: Props) {
const { t } = useTranslation(['app', 'errors']);
const [backup, setBackup] = useState('');
const [passphrase, setPassphrase] = useState('');
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const handleSubmit = useCallback(
async (e: React.FormEvent) => {
e.preventDefault();
if (!backup.trim() || passphrase.length < 1 || busy) return;
setBusy(true);
setError(null);
let privateKey: Uint8Array | null = null;
try {
const payload = await importDeviceBackup(backup.trim(), passphrase);
privateKey = decodePrivateKeyFromBackup(payload);
const device = await restoreDeviceFromServerRecord({
client: supabase,
secretStore: devLocalSecretStore,
userId: payload.userId,
deviceId: payload.deviceId,
privateKey,
});
// Cache deviceId locally so findExistingDevice picks it up on next load.
writeLocalDeviceId(userId, device.id);
onRestored(device);
} catch (err: unknown) {
setError(err instanceof Error ? err.message : String(err));
} finally {
if (privateKey) {
for (let i = 0; i < privateKey.length; i++) privateKey[i] = 0;
}
setBusy(false);
}
},
[backup, passphrase, userId, onRestored, busy],
);
return (
<form
onSubmit={handleSubmit}
className="w-full max-w-md animate-slide-up rounded-2xl border border-white/10 bg-ink-900/70 p-7 shadow-glow backdrop-blur-xl sm:p-8"
>
<div className="flex items-center gap-3">
<div className="flex h-10 w-10 items-center justify-center rounded-lg bg-emerald-500/20 ring-1 ring-emerald-400/30">
<ShieldIcon className="h-5 w-5 text-emerald-300" />
</div>
<div>
<h2 className="font-display text-lg font-semibold text-white">
{t('app:backup.restore_title', { defaultValue: 'Backup wiederherstellen' })}
</h2>
<p className="text-xs text-neutral-400">
{t('app:backup.restore_subtitle', {
defaultValue: 'Bringe einen zuvor erstellten Backup-String + Passphrase mit.',
})}
</p>
</div>
</div>
<div className="mt-6 space-y-3">
<div className="space-y-1">
<label className="block text-xs font-medium uppercase tracking-wide text-neutral-400">
{t('app:backup.backup_string', { defaultValue: 'Backup-String' })}
</label>
<textarea
required
rows={5}
value={backup}
onChange={(e) => setBackup(e.target.value)}
placeholder="chatapp-backup-v1…"
className="w-full resize-none rounded-lg border border-white/10 bg-ink-800 px-3 py-2.5 font-mono text-[11px] leading-relaxed text-white placeholder-neutral-500 transition focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-500/40"
/>
</div>
<div className="space-y-1">
<label className="block text-xs font-medium uppercase tracking-wide text-neutral-400">
{t('app:backup.passphrase', { defaultValue: 'Passphrase' })}
</label>
<input
type="password"
required
value={passphrase}
onChange={(e) => setPassphrase(e.target.value)}
className="w-full rounded-lg border border-white/10 bg-ink-800 px-3 py-2.5 text-sm text-white placeholder-neutral-500 transition focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-500/40"
/>
</div>
</div>
<div className="mt-5 rounded-lg border border-brand-500/20 bg-brand-500/10 p-3 text-xs text-brand-100">
<div className="flex items-start gap-2">
<LockIcon className="mt-0.5 h-4 w-4 shrink-0 text-brand-300" />
<span className="min-w-0 flex-1 break-words">
{t('app:backup.restore_hint', {
defaultValue:
'Nach Wiederherstellung übernimmt dieses Gerät die alte Identität — existierende Nachrichten sind wieder entschlüsselbar.',
})}
</span>
</div>
</div>
<button
type="submit"
disabled={busy || backup.trim().length === 0 || passphrase.length === 0}
aria-busy={busy}
className="group mt-6 inline-flex w-full cursor-pointer items-center justify-center gap-2 rounded-lg bg-gradient-to-br from-emerald-400 to-emerald-600 px-4 py-3 text-sm font-semibold text-white shadow-glow transition hover:from-emerald-300 hover:to-emerald-500 focus:outline-none focus:ring-2 focus:ring-emerald-400/60 focus:ring-offset-2 focus:ring-offset-ink-900 disabled:cursor-not-allowed disabled:opacity-60"
>
{busy ? (
<>
<SpinnerIcon className="h-4 w-4" />
<span>{t('app:backup.restoring', { defaultValue: 'Wiederherstellen…' })}</span>
</>
) : (
<>
<span>{t('app:backup.restore_cta', { defaultValue: 'Gerät wiederherstellen' })}</span>
<ArrowRightIcon className="h-4 w-4 transition group-hover:translate-x-0.5" />
</>
)}
</button>
{error && (
<div
role="alert"
className="mt-4 flex items-start gap-3 rounded-lg border border-rose-500/20 bg-rose-500/10 p-3 text-sm text-rose-100"
>
<AlertIcon className="mt-0.5 h-5 w-5 shrink-0 text-rose-400" />
<p className="min-w-0 flex-1 break-words">{error}</p>
</div>
)}
</form>
);
}
@@ -0,0 +1,133 @@
import { Component, type ErrorInfo, Fragment, type ReactNode } from 'react';
import { SpinnerIcon } from './icons';
interface Props {
children: ReactNode;
/**
* Optional scope label shown in logs / devtools. Defaults to `root` — set
* per boundary (e.g. `route`, `conversation`) so multiple boundaries can be
* distinguished at a glance.
*/
scope?: string;
/**
* If the retry count exceeds this, the boundary stops auto-retrying and
* shows a more helpful message (still without a button — Discord-style,
* the app keeps trying but hints the user to hold on or check network).
*/
maxAutoRetries?: number;
}
interface State {
error: Error | null;
retryKey: number;
attempt: number;
}
const RETRY_DELAYS_MS = [2000, 4000, 8000, 15000, 30000];
// Discord-style error boundary.
// - Catches render-time errors in its subtree.
// - Shows a centred spinner + status text. Never renders a manual "Reload"
// button; the boundary remounts its children on an exponential-backoff
// schedule so the UI self-heals once the underlying issue clears (typical
// causes: a realtime reconnect, a transient network blip, or a race that
// only fires once).
// - Escalates the label after each failed retry so the user sees that the
// app is trying, rather than silent infinite spinning.
export class ErrorBoundary extends Component<Props, State> {
state: State = { error: null, retryKey: 0, attempt: 0 };
private retryTimer: number | null = null;
static getDerivedStateFromError(error: Error): Partial<State> {
return { error };
}
override componentDidCatch(error: Error, info: ErrorInfo): void {
const scope = this.props.scope ?? 'root';
// We explicitly log here — the boundary itself swallows the error from
// React, so without this the failure would be invisible in production.
console.error('[ErrorBoundary:' + scope + '] caught render error', error, info);
}
override componentDidUpdate(_prev: Props, prevState: State): void {
if (this.state.error && !prevState.error) {
this.scheduleRetry();
}
}
override componentWillUnmount(): void {
if (this.retryTimer !== null) {
window.clearTimeout(this.retryTimer);
this.retryTimer = null;
}
}
private scheduleRetry(): void {
if (this.retryTimer !== null) return;
const attempt = this.state.attempt;
const delay =
RETRY_DELAYS_MS[Math.min(attempt, RETRY_DELAYS_MS.length - 1)] ??
RETRY_DELAYS_MS[RETRY_DELAYS_MS.length - 1] ??
30000;
this.retryTimer = window.setTimeout(() => {
this.retryTimer = null;
this.setState((prev) => ({
error: null,
retryKey: prev.retryKey + 1,
attempt: prev.attempt + 1,
}));
}, delay);
}
override render(): ReactNode {
if (this.state.error) {
const max = this.props.maxAutoRetries ?? RETRY_DELAYS_MS.length;
const escalated = this.state.attempt >= max;
return <RetryingScreen escalated={escalated} attempt={this.state.attempt} />;
}
// `retryKey` forces a remount of the subtree so hooks re-run cleanly after
// an error (otherwise stale state from the crashed tree can immediately
// re-throw). Use a keyed Fragment so the boundary doesn't inject an extra
// wrapper div — that would break `flex h-full` chains (e.g. AppShell →
// Outlet → page column).
return <Fragment key={this.state.retryKey}>{this.props.children}</Fragment>;
}
}
function RetryingScreen({ escalated, attempt }: { escalated: boolean; attempt: number }) {
const primary = escalated
? 'Verbindungsprobleme…'
: attempt === 0
? 'Einen Moment bitte'
: 'Versuche erneut zu laden…';
const secondary = escalated
? 'Prüfe deine Internetverbindung. Wir versuchen es weiter.'
: 'Die App lädt sich gleich selbst neu.';
return (
<div
role="status"
aria-live="polite"
className="flex min-h-screen w-full items-center justify-center bg-surface-3 px-6"
>
<div className="flex flex-col items-center gap-4 text-center">
<div className="relative flex h-16 w-16 items-center justify-center">
<span
aria-hidden="true"
className="absolute inset-0 rounded-full border-2 border-accent/20"
/>
<span
aria-hidden="true"
className="absolute inset-0 rounded-full border-2 border-accent border-r-transparent border-b-transparent animate-spin"
/>
<SpinnerIcon className="hidden" />
</div>
<div className="max-w-sm space-y-1.5">
<p className="font-display text-lg font-semibold text-fg">{primary}</p>
<p className="text-sm text-fg-muted">{secondary}</p>
</div>
</div>
</div>
);
}
@@ -0,0 +1,315 @@
import { loadDevicePrivateKey } from '@chat-app/shared/auth';
import {
type AttachmentHandle,
type DecryptedMessage,
downloadAndDecryptAttachment,
encryptAndUploadAttachment,
insertAttachmentRow,
parseMessagePayload,
sendEncryptedMessage,
} from '@chat-app/shared/chat';
import { extractErrorCode } from '@chat-app/shared/i18n';
import { bytesToPgHex } from '@chat-app/shared/supabase';
import { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useAuth } from '../context/AuthContext';
import { useConversationsContext } from '../context/ConversationsContext';
import { devLocalSecretStore } from '../lib/secretStore';
import { supabase } from '../lib/supabase';
import { Avatar } from './Avatar';
import { ForwardIcon, SpinnerIcon, UsersIcon, XIcon } from './icons';
interface Props {
open: boolean;
message: DecryptedMessage | null;
currentConversationId: string | null;
onClose: () => void;
}
// Forwards a message's plaintext to one or more conversations. Attachments are
// NOT carried over yet (would require re-uploading + re-encrypting under the
// new conversation key); only the text payload is forwarded for now and the
// preview hints at the dropped attachment.
export function ForwardDialog({ open, message, currentConversationId, onClose }: Props) {
const { t } = useTranslation(['app', 'errors']);
const { session, device } = useAuth();
const { conversations } = useConversationsContext();
const [selected, setSelected] = useState<Set<string>>(new Set());
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [done, setDone] = useState(false);
useEffect(() => {
if (!open) return;
setSelected(new Set());
setError(null);
setDone(false);
}, [open, message?.id]);
const targets = useMemo(() => {
return conversations
.filter((c) => c.id !== currentConversationId && c.acceptedByMe)
.sort((a, b) => {
const ta = a.lastMessageAt ?? a.createdAt;
const tb = b.lastMessageAt ?? b.createdAt;
return tb.localeCompare(ta);
});
}, [conversations, currentConversationId]);
const preview = useMemo(() => {
if (!message?.plaintext) return '';
const p = parseMessagePayload(message.plaintext);
if (p.kind !== 'text') return '';
return p.text.length > 140 ? p.text.slice(0, 140) + '…' : p.text;
}, [message]);
const sourceAttachments = useMemo<AttachmentHandle[]>(() => {
if (!message?.plaintext) return [];
const p = parseMessagePayload(message.plaintext);
return p.kind === 'text' ? p.attachments : [];
}, [message]);
if (!open || !message) return null;
function toggle(id: string) {
setSelected((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
}
async function handleSend() {
if (!session?.user.id || !device?.id || !message) return;
if (selected.size === 0) return;
setBusy(true);
setError(null);
try {
const priv = await loadDevicePrivateKey(devLocalSecretStore, session.user.id, device.id);
if (!priv) throw new Error('private key not loaded');
const hasAttachments = sourceAttachments.length > 0;
const text = preview || (hasAttachments ? '' : '');
if (!text && !hasAttachments) throw new Error('nothing to forward');
// Download+decrypt source attachments ONCE (same plaintext goes to every
// target). For each target conv we re-encrypt under fresh per-attachment
// keys and re-upload under the target conv's storage folder — source and
// target conv-keys differ, so the bytes must actually move.
const decryptedBlobs: { mime: string; size: number; width?: number; height?: number; blob: Blob }[] =
[];
for (const h of sourceAttachments) {
const blob = await downloadAndDecryptAttachment({ client: supabase, handle: h });
const entry: {
mime: string;
size: number;
width?: number;
height?: number;
blob: Blob;
} = { mime: h.mimeType, size: h.sizeBytes, blob };
if (h.width !== undefined) entry.width = h.width;
if (h.height !== undefined) entry.height = h.height;
decryptedBlobs.push(entry);
}
for (const convId of selected) {
const newHandles: AttachmentHandle[] = [];
const blobNonceHex = new Map<string, string>();
for (const src of decryptedBlobs) {
const res = await encryptAndUploadAttachment({
client: supabase,
conversationId: convId,
file: src.blob,
mimeType: src.mime,
sizeBytes: src.size,
...(src.width !== undefined ? { width: src.width } : {}),
...(src.height !== undefined ? { height: src.height } : {}),
});
newHandles.push(res.handle);
blobNonceHex.set(res.handle.id, bytesToPgHex(res.nonce));
}
const msg = await sendEncryptedMessage({
client: supabase,
conversationId: convId,
plaintext: text,
senderUserId: session.user.id,
senderDeviceId: device.id,
senderPrivateKey: priv,
...(newHandles.length > 0 ? { attachmentHandles: newHandles } : {}),
});
for (const h of newHandles) {
const bn = blobNonceHex.get(h.id) ?? '\\x';
await insertAttachmentRow(supabase, msg.id, h, bn);
}
}
setDone(true);
window.setTimeout(onClose, 700);
} catch (err: unknown) {
const code = extractErrorCode(err);
setError(
code
? t('errors:' + code, { defaultValue: t('errors:generic') })
: err instanceof Error
? err.message
: t('errors:generic'),
);
} finally {
setBusy(false);
}
}
return (
<div
role="dialog"
aria-modal="true"
aria-label={t('app:chats.forward', { defaultValue: 'Weiterleiten' })}
className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4"
onClick={onClose}
>
<div
onClick={(e) => e.stopPropagation()}
className="flex max-h-[80vh] w-full max-w-md flex-col overflow-hidden rounded-2xl border border-line bg-surface-3 shadow-xl"
>
<header className="flex items-center justify-between border-b border-line px-5 py-3">
<div className="flex items-center gap-2">
<ForwardIcon className="h-4 w-4 text-accent" />
<h3 className="font-display text-sm font-semibold text-fg">
{t('app:chats.forward', { defaultValue: 'Weiterleiten' })}
</h3>
</div>
<button
type="button"
onClick={onClose}
aria-label="Close"
className="flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg text-fg-muted transition hover:bg-surface-2 hover:text-fg"
>
<XIcon className="h-4 w-4" />
</button>
</header>
<div className="border-b border-line bg-surface-2 px-5 py-3">
<p className="text-[10px] font-semibold uppercase tracking-wider text-fg-muted">
{t('app:chats.forward_preview', { defaultValue: 'Vorschau' })}
</p>
<p className="mt-1 line-clamp-3 break-words text-sm text-fg">
{preview || (sourceAttachments.length > 0 ? '📎' : '…')}
</p>
{sourceAttachments.length > 0 && (
<p className="mt-1 text-[11px] text-fg-muted">
📎{' '}
{t('app:chats.forward_attachments_count', {
count: sourceAttachments.length,
defaultValue: '{{count}} Anhang wird mit weitergeleitet',
})}
</p>
)}
</div>
<div className="flex-1 overflow-y-auto p-2">
{targets.length === 0 ? (
<p className="px-4 py-6 text-center text-sm text-fg-muted">
{t('app:chats.forward_no_targets', {
defaultValue: 'Keine anderen Unterhaltungen verfügbar.',
})}
</p>
) : (
<ul className="space-y-0.5">
{targets.map((c) => {
const isGroup = c.type === 'group';
const title = isGroup ? c.name ?? '?' : c.peer?.displayName ?? '?';
const avatarUrl = isGroup ? c.avatarUrl ?? null : c.peer?.avatarUrl ?? null;
const checked = selected.has(c.id);
return (
<li key={c.id}>
<button
type="button"
onClick={() => toggle(c.id)}
className={
'flex w-full cursor-pointer items-center gap-3 rounded-lg px-3 py-2 text-left transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ' +
(checked ? 'bg-accent/15' : 'hover:bg-surface-2')
}
>
{avatarUrl ? (
<Avatar
url={avatarUrl}
displayName={title}
className="h-9 w-9 text-sm"
/>
) : isGroup ? (
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-accent/20 text-accent">
<UsersIcon className="h-4 w-4" />
</div>
) : (
<Avatar
url={null}
displayName={title}
className="h-9 w-9 text-sm"
/>
)}
<span className="min-w-0 flex-1 truncate text-sm font-medium text-fg">
{title}
</span>
<span
aria-hidden="true"
className={
'flex h-5 w-5 shrink-0 items-center justify-center rounded border ' +
(checked ? 'border-accent bg-accent text-accent-fg' : 'border-line bg-surface-2')
}
>
{checked && (
<svg viewBox="0 0 24 24" className="h-3.5 w-3.5" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
<polyline points="20 6 9 17 4 12" />
</svg>
)}
</span>
</button>
</li>
);
})}
</ul>
)}
</div>
{error && (
<p
role="alert"
className="border-t border-rose-500/30 bg-rose-500/10 px-5 py-2 text-xs text-rose-700 dark:text-rose-200"
>
{error}
</p>
)}
<footer className="flex items-center justify-end gap-2 border-t border-line bg-surface-2 px-5 py-3">
<button
type="button"
onClick={onClose}
className="cursor-pointer rounded-md border border-line bg-surface-3 px-3 py-2 text-sm text-fg transition hover:bg-surface-2"
>
{t('app:friends.action_cancel', { defaultValue: 'Abbrechen' })}
</button>
<button
type="button"
disabled={busy || selected.size === 0 || done}
onClick={() => void handleSend()}
className="inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-semibold text-accent-fg transition hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-60"
>
{busy && <SpinnerIcon className="h-4 w-4" />}
<span>
{done
? t('app:chats.forward_done', { defaultValue: 'Gesendet' })
: t('app:chats.forward_send', {
count: selected.size,
defaultValue: 'An {{count}} senden',
})}
</span>
</button>
</footer>
</div>
</div>
);
}
+25 -6
View File
@@ -123,15 +123,25 @@ export function GroupInfoPanel({ open, onClose, conversation }: Props) {
{conversation.members.map((m) => { {conversation.members.map((m) => {
const name = m.profile?.displayName ?? '?'; const name = m.profile?.displayName ?? '?';
const handle = m.profile?.username ? '@' + m.profile.username : ''; const handle = m.profile?.username ? '@' + m.profile.username : '';
const avatarUrl = m.profile?.avatarUrl ?? null;
const letter = name.trim().charAt(0).toUpperCase() || '?'; const letter = name.trim().charAt(0).toUpperCase() || '?';
return ( return (
<li <li
key={m.userId} key={m.userId}
className="flex items-center gap-3 rounded-lg px-2 py-1.5" className="flex items-center gap-3 rounded-lg px-2 py-1.5"
> >
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-brand-500/30 text-xs font-semibold text-white ring-1 ring-brand-400/30"> {avatarUrl ? (
{letter} <img
</div> src={avatarUrl}
alt=""
className="h-8 w-8 shrink-0 rounded-full object-cover"
draggable={false}
/>
) : (
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-brand-500/30 text-xs font-semibold text-white ring-1 ring-brand-400/30">
{letter}
</div>
)}
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="truncate text-sm text-white"> <p className="truncate text-sm text-white">
{name} {name}
@@ -187,9 +197,18 @@ export function GroupInfoPanel({ open, onClose, conversation }: Props) {
onClick={() => void handleAdd(f.userId)} onClick={() => void handleAdd(f.userId)}
className="flex w-full cursor-pointer items-center gap-3 rounded-lg px-2 py-1.5 text-left transition hover:bg-white/5 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 disabled:opacity-60" className="flex w-full cursor-pointer items-center gap-3 rounded-lg px-2 py-1.5 text-left transition hover:bg-white/5 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 disabled:opacity-60"
> >
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-brand-500/30 text-xs font-semibold text-white ring-1 ring-brand-400/30"> {f.avatarUrl ? (
{letter} <img
</div> src={f.avatarUrl}
alt=""
className="h-8 w-8 shrink-0 rounded-full object-cover"
draggable={false}
/>
) : (
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-brand-500/30 text-xs font-semibold text-white ring-1 ring-brand-400/30">
{letter}
</div>
)}
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="truncate text-sm text-white">{f.displayName}</p> <p className="truncate text-sm text-white">{f.displayName}</p>
<p className="truncate text-xs text-neutral-500">@{f.username}</p> <p className="truncate text-xs text-neutral-500">@{f.username}</p>
+493 -354
View File
@@ -1,46 +1,60 @@
import type { ConversationSummary } from '@chat-app/shared/chat'; import type { ConversationSummary } from '@chat-app/shared/chat';
import type { RemoteTrack } from 'livekit-client'; import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useAuth } from '../context/AuthContext'; import { useAuth } from '../context/AuthContext';
import { type RemoteScreenShare, useCall } from '../context/CallContext'; import { type CallMode, useCall } from '../context/CallContext';
import { import {
getPttSettings, getPttSettings,
type PttSettings, type PttSettings,
subscribePttSettings, subscribePttSettings,
} from '../lib/pttSettings'; } from '../lib/pttSettings';
import { import { useActiveSpeakers } from '../lib/useActiveSpeakers';
LockIcon, import { CallControls } from './CallControls';
MicIcon, import { CallParticipantTile } from './CallParticipantTile';
MicOffIcon, import { FocusIcon, GridIcon, LockIcon, MaximizeIcon, SpinnerIcon, UsersIcon } from './icons';
MonitorShareIcon, import { ScreenShareViewer } from './ScreenShareViewer';
MonitorStopIcon,
PhoneOffIcon,
SpinnerIcon,
} from './icons';
// Discord-style in-call dock rendered above the message list. Renders three
// visual modes driven by CallContext.callMode: grid, focus, fullscreen.
// The fullscreen variant absolute-positions itself over the conversation
// container so the rail+chat-list remain visible on the left.
interface Props { interface Props {
conversation: ConversationSummary; conversation: ConversationSummary;
} }
// Discord-style call widget rendered above the message list when the user is interface Tile {
// in the current conversation's call. Shows participant avatars + controls. userId: string;
displayName: string;
avatarUrl: string | null;
self: boolean;
muted: boolean;
video: boolean;
sharing: boolean;
remoteSharing: boolean;
}
export function InCallPanel({ conversation }: Props) { export function InCallPanel({ conversation }: Props) {
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
const { const {
state, state,
room,
remoteParticipants, remoteParticipants,
isMuted, isMuted,
isE2EEActive, isE2EEActive,
toggleMute,
hangup,
isScreenSharing, isScreenSharing,
remoteScreenShares, remoteScreenShares,
callMode,
focusedId,
toggleMute,
toggleScreenShare, toggleScreenShare,
hangup,
setCallMode,
setFocusedId,
} = useCall(); } = useCall();
const { session } = useAuth(); const { session } = useAuth();
const myId = session?.user.id ?? null; const myId = session?.user.id ?? null;
const activeSpeakers = useActiveSpeakers(room);
const active = const active =
(state.kind === 'connected' || (state.kind === 'connected' ||
@@ -49,33 +63,19 @@ export function InCallPanel({ conversation }: Props) {
state.conversationId === conversation.id; state.conversationId === conversation.id;
if (!active) return null; if (!active) return null;
const remoteIds = new Set<string>( const tiles = buildTiles({
remoteParticipants.map((p) => p.identity).filter((s): s is string => Boolean(s)), conversation,
); myId,
const tiles: ParticipantTileData[] = []; remoteIdentities: remoteParticipants.map((p) => p.identity),
if (myId) { isMuted,
const me = conversation.members.find((m) => m.userId === myId) ?? null; isScreenSharing,
tiles.push({ remoteSharerIds: new Set(remoteScreenShares.map((s) => s.participantId)),
userId: myId, });
displayName: me?.profile?.displayName ?? '?',
avatarUrl: me?.profile?.avatarUrl ?? null, const duration =
self: true, state.kind === 'connected'
speaking: false, ? <LiveDuration startedAt={state.startedAt} />
muted: isMuted, : null;
});
}
for (const m of conversation.members) {
if (m.userId === myId) continue;
if (!remoteIds.has(m.userId)) continue;
tiles.push({
userId: m.userId,
displayName: m.profile?.displayName ?? '?',
avatarUrl: m.profile?.avatarUrl ?? null,
self: false,
speaking: false,
muted: false,
});
}
const statusLabel = const statusLabel =
state.kind === 'outgoing' state.kind === 'outgoing'
@@ -86,268 +86,491 @@ export function InCallPanel({ conversation }: Props) {
? t('app:call.waiting_for_peers', { defaultValue: 'Warte auf andere…' }) ? t('app:call.waiting_for_peers', { defaultValue: 'Warte auf andere…' })
: t('app:call.connected'); : t('app:call.connected');
const sharingTile = tiles.find((p) => p.sharing);
const effectiveFocusedId = focusedId ?? sharingTile?.userId ?? tiles[0]?.userId ?? null;
const speaker = tiles.find((p) => p.userId === effectiveFocusedId) ?? tiles[0];
const controls = (
<CallControls
muted={isMuted}
sharing={isScreenSharing}
video={false}
onToggleMute={toggleMute}
onToggleShare={() => void toggleScreenShare()}
onHangup={() => void hangup()}
compact={callMode !== 'fullscreen'}
glass={callMode === 'fullscreen'}
disabledMedia={state.kind !== 'connected'}
/>
);
if (callMode === 'fullscreen') {
return (
<FullscreenCall
tiles={tiles}
speaker={speaker}
remoteScreenShares={remoteScreenShares}
conversationMembers={conversation.members}
activeSpeakers={activeSpeakers}
e2ee={isE2EEActive}
onExit={() => setCallMode('grid')}
onFocusTile={(id) => {
setFocusedId(id);
}}
controls={controls}
/>
);
}
const title =
conversation.type === 'group'
? conversation.name ?? t('app:chats.new_group')
: conversation.peer?.displayName ?? '—';
return ( return (
<section <section
aria-label={t('app:call.in_call', { defaultValue: 'Im Anruf' })} aria-label={t('app:call.in_call', { defaultValue: 'Im Anruf' })}
className="border-b border-white/5 bg-gradient-to-b from-ink-900/80 to-ink-950/40 px-6 py-5" className="flex min-h-[280px] max-h-[420px] shrink-0 flex-col overflow-hidden border-b border-line bg-surface-2"
style={{ height: '50%' }}
> >
<div className="mb-4 flex items-center gap-2 text-xs font-medium text-emerald-300"> <div className="flex items-center justify-between border-b border-line bg-surface-3 px-4 py-2">
{state.kind === 'connecting' ? ( <div className="flex min-w-0 flex-col gap-0.5">
<SpinnerIcon className="h-3.5 w-3.5" /> <div className="flex items-center gap-2 text-sm font-semibold text-fg">
) : ( <UsersIcon className="h-4 w-4 shrink-0 text-fg-muted" />
<span className="relative flex h-2 w-2"> <span className="truncate">{title}</span>
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400/60" /> <span className="text-fg-muted/50" aria-hidden="true">·</span>
<span className="relative inline-flex h-2 w-2 rounded-full bg-emerald-400" /> <span className="tabular-nums text-fg-muted">
</span> {duration ?? statusLabel}
)} {state.kind !== 'connected' && (
<span className="uppercase tracking-wide">{statusLabel}</span> <SpinnerIcon className="ml-1 inline h-3 w-3" />
{isE2EEActive && ( )}
<span </span>
className="ml-2 inline-flex items-center gap-1 rounded-full bg-emerald-500/15 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-emerald-200 ring-1 ring-emerald-400/30" </div>
title={t('app:call.e2ee_active_hint', { {isE2EEActive && (
defaultValue: 'Audio + Video sind Ende-zu-Ende-verschlüsselt', <div className="flex items-center gap-1 text-[11px] font-medium text-emerald-600 dark:text-emerald-400">
})} <LockIcon className="h-3 w-3" />
> <span>{t('app:call.e2ee_active', { defaultValue: 'E2E verschlüsselt' })}</span>
<LockIcon className="h-3 w-3" /> </div>
E2EE
</span>
)}
</div>
<div className="flex flex-wrap justify-center gap-4">
{tiles.map((p) => (
<ParticipantTile key={p.userId} {...p} />
))}
</div>
{remoteScreenShares.length > 0 && (
<div className="mt-4 space-y-3">
{remoteScreenShares.map((s) => {
const member = conversation.members.find((m) => m.userId === s.participantId);
return (
<ScreenShareViewer
key={s.track.sid ?? s.participantId}
share={s}
avatarUrl={member?.profile?.avatarUrl ?? null}
displayName={member?.profile?.displayName ?? s.participantName}
/>
);
})}
</div>
)}
<div className="mt-5 flex items-center justify-center gap-2">
<ControlButton
onClick={toggleMute}
disabled={state.kind !== 'connected'}
active={isMuted}
label={isMuted ? t('app:call.unmute') : t('app:call.mute')}
tone={isMuted ? 'amber' : 'neutral'}
>
{isMuted ? <MicOffIcon className="h-5 w-5" /> : <MicIcon className="h-5 w-5" />}
</ControlButton>
<ControlButton
onClick={() => void toggleScreenShare()}
disabled={state.kind !== 'connected'}
active={isScreenSharing}
label={
isScreenSharing
? t('app:call.stop_share_screen', { defaultValue: 'Screen-Share stoppen' })
: t('app:call.share_screen', { defaultValue: 'Bildschirm teilen' })
}
tone={isScreenSharing ? 'emerald' : 'neutral'}
>
{isScreenSharing ? (
<MonitorStopIcon className="h-5 w-5" />
) : (
<MonitorShareIcon className="h-5 w-5" />
)} )}
</ControlButton> </div>
<ControlButton <ModeToggles mode={callMode} onChange={setCallMode} />
onClick={() => void hangup()}
label={t('app:call.hangup')}
tone="rose"
>
<PhoneOffIcon className="h-5 w-5" />
</ControlButton>
</div> </div>
<CallStage
tiles={tiles}
speaker={speaker}
mode={callMode}
activeSpeakers={activeSpeakers}
e2ee={isE2EEActive}
remoteScreenShares={remoteScreenShares}
conversationMembers={conversation.members}
onFocusTile={(id) => {
setFocusedId(id);
if (callMode === 'grid') setCallMode('focus');
}}
compact
/>
{controls}
<PttHint /> <PttHint />
</section> </section>
); );
} }
interface ScreenShareViewerProps { // ---------------------------------------------------------------------------
share: RemoteScreenShare; // Helpers
avatarUrl: string | null; // ---------------------------------------------------------------------------
displayName: string;
interface BuildArgs {
conversation: ConversationSummary;
myId: string | null;
remoteIdentities: string[];
isMuted: boolean;
isScreenSharing: boolean;
remoteSharerIds: Set<string>;
} }
function ScreenShareViewer({ share, avatarUrl, displayName }: ScreenShareViewerProps) { function buildTiles({
const { t } = useTranslation(['app']); conversation,
const videoRef = useRef<HTMLVideoElement | null>(null); myId,
const containerRef = useRef<HTMLDivElement | null>(null); remoteIdentities,
const [watching, setWatching] = useState(false); isMuted,
const [isFullscreen, setIsFullscreen] = useState(false); isScreenSharing,
const letter = displayName.trim().charAt(0).toUpperCase() || '?'; remoteSharerIds,
}: BuildArgs): Tile[] {
const remoteSet = new Set(remoteIdentities);
const out: Tile[] = [];
if (myId) {
const me = conversation.members.find((m) => m.userId === myId) ?? null;
out.push({
userId: myId,
displayName: me?.profile?.displayName ?? '?',
avatarUrl: me?.profile?.avatarUrl ?? null,
self: true,
muted: isMuted,
video: false,
sharing: isScreenSharing,
remoteSharing: false,
});
}
for (const m of conversation.members) {
if (m.userId === myId) continue;
if (!remoteSet.has(m.userId)) continue;
const sharing = remoteSharerIds.has(m.userId);
out.push({
userId: m.userId,
displayName: m.profile?.displayName ?? '?',
avatarUrl: m.profile?.avatarUrl ?? null,
self: false,
muted: false,
video: false,
sharing,
remoteSharing: sharing,
});
}
return out;
}
function LiveDuration({ startedAt }: { startedAt: string }) {
const [, tick] = useState(0);
useEffect(() => { useEffect(() => {
if (!watching) return; const id = window.setInterval(() => tick((v) => v + 1), 1000);
const el = videoRef.current; return () => window.clearInterval(id);
if (!el) return;
const track: RemoteTrack = share.track;
track.attach(el);
return () => {
track.detach(el);
};
}, [share.track, watching]);
useEffect(() => {
const onChange = () => {
setIsFullscreen(document.fullscreenElement === containerRef.current);
};
document.addEventListener('fullscreenchange', onChange);
return () => document.removeEventListener('fullscreenchange', onChange);
}, []); }, []);
return <>{formatElapsed(Date.now() - new Date(startedAt).getTime())}</>;
}
const toggleFullscreen = () => { function formatElapsed(ms: number): string {
const el = containerRef.current; const total = Math.max(0, Math.floor(ms / 1000));
if (!el) return; const hh = Math.floor(total / 3600);
if (document.fullscreenElement === el) { const mm = Math.floor((total % 3600) / 60);
void document.exitFullscreen(); const ss = total % 60;
} else { const pad = (n: number) => n.toString().padStart(2, '0');
void el.requestFullscreen(); return `${pad(hh)}:${pad(mm)}:${pad(ss)}`;
} }
};
function ModeToggles({
mode,
onChange,
}: {
mode: CallMode;
onChange: (mode: CallMode) => void;
}) {
return ( return (
<div <div className="flex items-center gap-1">
ref={containerRef} <ModeButton active={mode === 'grid'} onClick={() => onChange('grid')} label="Grid">
<GridIcon className="h-4 w-4" />
</ModeButton>
<ModeButton active={mode === 'focus'} onClick={() => onChange('focus')} label="Fokus">
<FocusIcon className="h-4 w-4" />
</ModeButton>
<ModeButton
active={mode === 'fullscreen'}
onClick={() => onChange('fullscreen')}
label="Vollbild"
>
<MaximizeIcon className="h-4 w-4" />
</ModeButton>
</div>
);
}
function ModeButton({
active,
onClick,
label,
children,
}: {
active: boolean;
onClick: () => void;
label: string;
children: React.ReactNode;
}) {
return (
<button
type="button"
onClick={onClick}
aria-label={label}
aria-pressed={active}
title={label}
className={ className={
'overflow-hidden rounded-xl border border-emerald-500/20 bg-black ' + 'flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg border transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 ' +
(isFullscreen ? 'flex h-screen w-screen flex-col rounded-none' : '') (active
? 'border-accent bg-accent text-accent-fg'
: 'border-line bg-surface-2 text-fg-muted hover:bg-surface-3 hover:text-fg')
} }
> >
<div className="flex shrink-0 items-center gap-2 border-b border-emerald-500/10 bg-emerald-500/10 px-3 py-1.5 text-xs text-emerald-200"> {children}
<MonitorShareIcon className="h-3.5 w-3.5 shrink-0" /> </button>
<span className="truncate flex-1"> );
{t('app:call.is_sharing_screen', { }
name: displayName,
defaultValue: displayName + ' teilt den Bildschirm', interface StageProps {
})} tiles: Tile[];
</span> speaker: Tile | undefined;
{watching && ( mode: CallMode;
<> activeSpeakers: Set<string>;
<button e2ee: boolean;
type="button" remoteScreenShares: {
onClick={toggleFullscreen} track: import('livekit-client').RemoteTrack;
aria-label={t('app:call.fullscreen', { defaultValue: 'Vollbild' })} participantId: string;
title={t('app:call.fullscreen', { defaultValue: 'Vollbild' })} participantName: string;
className="inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md text-emerald-200 transition hover:bg-white/10 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400/40" }[];
> conversationMembers: ConversationSummary['members'];
<FullscreenIcon className="h-3.5 w-3.5" /> onFocusTile: (id: string) => void;
</button> compact?: boolean;
<button }
type="button"
onClick={() => { function CallStage({
if (document.fullscreenElement === containerRef.current) { tiles,
void document.exitFullscreen(); speaker,
} mode,
setWatching(false); activeSpeakers,
}} e2ee,
aria-label={t('app:call.stop_watching', { defaultValue: 'Nicht mehr anschauen' })} remoteScreenShares,
title={t('app:call.stop_watching', { defaultValue: 'Nicht mehr anschauen' })} conversationMembers,
className="inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md text-emerald-200 transition hover:bg-white/10 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400/40" onFocusTile,
> compact = false,
<span aria-hidden="true" className="text-[14px] leading-none">×</span> }: StageProps) {
</button> if (mode === 'focus' && speaker) {
</> const others = tiles.filter((p) => p.userId !== speaker.userId);
return (
<div className="flex min-h-0 flex-1 flex-col gap-2.5 p-3">
<div className="min-h-0 flex-1">
<FocusedTile
tile={speaker}
e2ee={e2ee}
speaking={activeSpeakers.has(speaker.userId)}
remoteScreenShares={remoteScreenShares}
conversationMembers={conversationMembers}
/>
</div>
{others.length > 0 && (
<div className="flex h-[110px] gap-2.5 overflow-x-auto">
{others.map((p) => (
<div key={p.userId} className="h-full min-w-[160px]">
<CallParticipantTile
userId={p.userId}
displayName={p.displayName}
avatarUrl={p.avatarUrl}
me={p.self}
muted={p.muted}
speaking={activeSpeakers.has(p.userId)}
sharing={p.sharing}
video={p.video}
e2ee={e2ee}
size="small"
onClick={() => onFocusTile(p.userId)}
/>
</div>
))}
</div>
)} )}
</div> </div>
{watching ? (
<video
ref={videoRef}
autoPlay
playsInline
muted
onDoubleClick={toggleFullscreen}
className={
'block cursor-zoom-in bg-black ' +
(isFullscreen ? 'h-full w-full flex-1 object-contain' : 'w-full')
}
/>
) : (
<button
type="button"
onClick={() => setWatching(true)}
aria-label={t('app:call.watch_screen', { defaultValue: 'Bildschirm anschauen' })}
className="group relative block w-full cursor-pointer overflow-hidden bg-ink-900 focus:outline-none"
style={{ aspectRatio: '16 / 9' }}
>
<BlurredTile avatarUrl={avatarUrl} letter={letter} />
<div className="absolute inset-0 flex items-center justify-center bg-black/30 transition group-hover:bg-black/40">
<div className="flex flex-col items-center gap-2">
<span className="flex h-14 w-14 items-center justify-center rounded-full bg-emerald-500/90 text-white shadow-lg transition group-hover:scale-105">
<PlayIcon className="ml-0.5 h-6 w-6" />
</span>
<span className="text-xs font-medium text-white/90">
{t('app:call.watch_screen', { defaultValue: 'Bildschirm anschauen' })}
</span>
</div>
</div>
</button>
)}
</div>
);
}
function BlurredTile({ avatarUrl, letter }: { avatarUrl: string | null; letter: string }) {
if (avatarUrl) {
return (
<>
<img
src={avatarUrl}
alt=""
className="absolute inset-0 h-full w-full scale-110 object-cover blur-2xl"
/>
<div className="absolute inset-0 bg-gradient-to-br from-brand-500/20 to-emerald-500/20" />
</>
); );
} }
// Grid
const gridClass = gridColsFor(tiles.length);
return ( return (
<div className="absolute inset-0 flex items-center justify-center bg-gradient-to-br from-brand-500/40 via-fuchsia-500/20 to-emerald-500/30"> <div className={'min-h-0 flex-1 p-3 ' + (compact ? '' : 'p-4')}>
<span <div className={'grid h-full gap-2 ' + gridClass}>
aria-hidden="true" {tiles.map((p) => (
className="text-[120px] font-display font-bold text-white/20 blur-[2px]" <CallParticipantTile
> key={p.userId}
{letter} userId={p.userId}
</span> displayName={p.displayName}
avatarUrl={p.avatarUrl}
me={p.self}
muted={p.muted}
speaking={activeSpeakers.has(p.userId)}
sharing={p.sharing}
video={p.video}
e2ee={e2ee}
onClick={() => onFocusTile(p.userId)}
/>
))}
</div>
</div> </div>
); );
} }
function PlayIcon(props: React.SVGProps<SVGSVGElement>) { function FocusedTile({
tile,
e2ee,
speaking,
remoteScreenShares,
conversationMembers,
}: {
tile: Tile;
e2ee: boolean;
speaking: boolean;
remoteScreenShares: StageProps['remoteScreenShares'];
conversationMembers: StageProps['conversationMembers'];
}) {
// When the focused participant is remotely sharing their screen, embed the
// real video stream rather than the fake-window placeholder.
if (tile.remoteSharing) {
const share = remoteScreenShares.find((s) => s.participantId === tile.userId);
const member = conversationMembers.find((m) => m.userId === tile.userId);
if (share) {
return (
<div className="h-full">
<ScreenShareViewer
share={share}
avatarUrl={member?.profile?.avatarUrl ?? tile.avatarUrl}
displayName={member?.profile?.displayName ?? tile.displayName}
/>
</div>
);
}
}
return ( return (
<svg viewBox="0 0 24 24" fill="currentColor" {...props}> <div className="h-full">
<path d="M8 5v14l11-7z" /> <CallParticipantTile
</svg> userId={tile.userId}
displayName={tile.displayName}
avatarUrl={tile.avatarUrl}
me={tile.self}
muted={tile.muted}
speaking={speaking}
sharing={tile.sharing}
video={tile.video}
e2ee={e2ee}
focused
/>
</div>
); );
} }
function FullscreenIcon(props: React.SVGProps<SVGSVGElement>) { function gridColsFor(n: number): string {
if (n <= 1) return 'grid-cols-1';
if (n === 2) return 'grid-cols-2';
if (n === 3) return 'grid-cols-3';
if (n === 4) return 'grid-cols-2 grid-rows-2';
return 'grid-cols-3 grid-rows-2';
}
// ---------------------------------------------------------------------------
// Fullscreen cinema mode
// ---------------------------------------------------------------------------
interface FullscreenProps {
tiles: Tile[];
speaker: Tile | undefined;
remoteScreenShares: StageProps['remoteScreenShares'];
conversationMembers: StageProps['conversationMembers'];
activeSpeakers: Set<string>;
e2ee: boolean;
onExit: () => void;
onFocusTile: (id: string) => void;
controls: React.ReactNode;
}
function FullscreenCall({
tiles,
speaker,
remoteScreenShares,
conversationMembers,
activeSpeakers,
e2ee,
onExit: _onExit,
onFocusTile,
controls,
}: FullscreenProps) {
const others = speaker ? tiles.filter((p) => p.userId !== speaker.userId) : tiles;
const [hintGone, setHintGone] = useState(false);
useEffect(() => {
const id = window.setTimeout(() => setHintGone(true), 3500);
return () => window.clearTimeout(id);
}, []);
return ( return (
<svg <div className="fixed inset-0 z-[60] flex flex-col overflow-hidden bg-surface">
viewBox="0 0 24 24" <div className="relative min-h-0 flex-1">
fill="none" {speaker && (
stroke="currentColor" <div className="absolute inset-0">
strokeWidth={2} {speaker.remoteSharing ? (
strokeLinecap="round" <FullscreenShare speaker={speaker} remoteScreenShares={remoteScreenShares} conversationMembers={conversationMembers} />
strokeLinejoin="round" ) : (
{...props} <div className="h-full w-full [&>div]:rounded-none [&>div]:border-0">
> <CallParticipantTile
<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5" /> userId={speaker.userId}
</svg> displayName={speaker.displayName}
avatarUrl={speaker.avatarUrl}
me={speaker.self}
muted={speaker.muted}
speaking={activeSpeakers.has(speaker.userId)}
sharing={speaker.sharing}
video={speaker.video}
e2ee={e2ee}
focused
/>
</div>
)}
</div>
)}
{others.length > 0 && (
<div className="absolute bottom-24 right-4 flex w-[180px] flex-col gap-2">
{others.slice(0, 4).map((p) => (
<div key={p.userId} className="h-[100px] backdrop-blur-xl">
<CallParticipantTile
userId={p.userId}
displayName={p.displayName}
avatarUrl={p.avatarUrl}
me={p.self}
muted={p.muted}
speaking={activeSpeakers.has(p.userId)}
sharing={p.sharing}
video={p.video}
e2ee={e2ee}
size="small"
onClick={() => onFocusTile(p.userId)}
/>
</div>
))}
</div>
)}
{!hintGone && (
<div
aria-hidden="true"
className="pointer-events-none absolute left-1/2 top-5 z-10 animate-fs-hint rounded-lg border border-white/10 bg-black/60 px-3.5 py-1.5 text-[11px] font-medium tracking-wide text-white/70 backdrop-blur-md"
>
Esc zum Verlassen
</div>
)}
<div className="pointer-events-auto absolute bottom-4 left-1/2 -translate-x-1/2">
{controls}
</div>
</div>
</div>
);
}
function FullscreenShare({
speaker,
remoteScreenShares,
conversationMembers,
}: {
speaker: Tile;
remoteScreenShares: StageProps['remoteScreenShares'];
conversationMembers: StageProps['conversationMembers'];
}) {
const share = remoteScreenShares.find((s) => s.participantId === speaker.userId);
const member = conversationMembers.find((m) => m.userId === speaker.userId);
if (!share) return null;
return (
<div className="h-full w-full">
<ScreenShareViewer
share={share}
avatarUrl={member?.profile?.avatarUrl ?? speaker.avatarUrl}
displayName={member?.profile?.displayName ?? speaker.displayName}
/>
</div>
); );
} }
@@ -356,95 +579,11 @@ function PttHint() {
useEffect(() => subscribePttSettings(setPtt), []); useEffect(() => subscribePttSettings(setPtt), []);
if (!ptt.enabled) return null; if (!ptt.enabled) return null;
return ( return (
<p className="mt-3 text-center text-[11px] text-neutral-500"> <p className="border-t border-line bg-surface-3 py-2 text-center text-[11px] text-fg-muted">
Push-to-Talk:&nbsp; Push-to-Talk:&nbsp;
<kbd className="rounded border border-white/10 bg-white/5 px-1.5 py-0.5 font-mono text-[10px] text-neutral-300"> <kbd className="rounded border border-line bg-surface-2 px-1.5 py-0.5 font-mono text-[10px] text-fg">
{ptt.keyLabel} {ptt.keyLabel}
</kbd> </kbd>
</p> </p>
); );
} }
interface ParticipantTileData {
userId: string;
displayName: string;
avatarUrl: string | null;
self: boolean;
speaking: boolean;
muted: boolean;
}
function ParticipantTile(p: ParticipantTileData) {
const letter = p.displayName.trim().charAt(0).toUpperCase() || '?';
return (
<div className="flex w-28 flex-col items-center gap-2">
<div
className={
'relative flex h-20 w-20 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500/40 to-brand-700/40 text-2xl font-semibold text-white ring-2 transition ' +
(p.speaking
? 'ring-emerald-400 shadow-[0_0_24px_rgba(52,211,153,0.35)]'
: 'ring-white/10')
}
>
{p.avatarUrl ? (
<img
src={p.avatarUrl}
alt=""
className="h-full w-full rounded-2xl object-cover"
/>
) : (
<span aria-hidden="true">{letter}</span>
)}
{p.muted && (
<span
aria-hidden="true"
className="absolute -bottom-1 -right-1 flex h-6 w-6 items-center justify-center rounded-full bg-amber-500 ring-2 ring-ink-950"
>
<MicOffIcon className="h-3 w-3 text-ink-950" />
</span>
)}
</div>
<p className="max-w-full truncate text-xs font-medium text-neutral-200">
{p.displayName}
{p.self && (
<span className="ml-1 text-neutral-500">·&nbsp;Du</span>
)}
</p>
</div>
);
}
interface ControlButtonProps {
onClick: () => void;
label: string;
tone: 'neutral' | 'amber' | 'rose' | 'emerald';
active?: boolean;
disabled?: boolean;
children: React.ReactNode;
}
function ControlButton({ onClick, label, tone, disabled, children }: ControlButtonProps) {
const toneClass =
tone === 'rose'
? 'bg-rose-500 text-white hover:bg-rose-400 focus-visible:ring-rose-400/50'
: tone === 'amber'
? 'bg-amber-500/90 text-ink-950 hover:bg-amber-400 focus-visible:ring-amber-400/50'
: tone === 'emerald'
? 'bg-emerald-500/85 text-white hover:bg-emerald-400 focus-visible:ring-emerald-400/50'
: 'bg-white/10 text-neutral-100 hover:bg-white/20 focus-visible:ring-brand-400/40';
return (
<button
type="button"
onClick={onClick}
disabled={disabled}
aria-label={label}
title={label}
className={
'inline-flex h-11 w-11 cursor-pointer items-center justify-center rounded-full transition focus:outline-none focus-visible:ring-2 disabled:cursor-not-allowed disabled:opacity-50 ' +
toneClass
}
>
{children}
</button>
);
}
@@ -0,0 +1,123 @@
import type { ConversationSummary } from '@chat-app/shared/chat';
import { useTranslation } from 'react-i18next';
import { useCall } from '../context/CallContext';
import { useFriendshipsContext } from '../context/FriendshipsContext';
import { AvatarColorKey, colorKeyFor } from './CallParticipantTile';
import { LockIcon, PhoneIcon, PhoneOffIcon } from './icons';
interface Props {
conversation: ConversationSummary;
}
const PULSE_BG: Record<AvatarColorKey, string> = {
violet: 'bg-violet-200 text-violet-800 dark:bg-violet-900/60 dark:text-violet-200',
amber: 'bg-amber-200 text-amber-900 dark:bg-amber-900/60 dark:text-amber-200',
rose: 'bg-rose-200 text-rose-900 dark:bg-rose-900/60 dark:text-rose-200',
teal: 'bg-teal-200 text-teal-900 dark:bg-teal-900/60 dark:text-teal-200',
};
// Docked incoming-call panel: replaces the chat header, chat + composer stay
// visible and usable below (per user decision). Full-bleed overlay lives in
// the shell-level toast for cross-conversation ring notifications.
export function IncomingCallPanel({ conversation }: Props) {
const { t } = useTranslation(['app']);
const { state, acceptIncoming, rejectIncoming } = useCall();
const { friendships } = useFriendshipsContext();
if (state.kind !== 'incoming' || state.conversationId !== conversation.id) return null;
const isGroup = conversation.type === 'group';
const callerProfile = conversation.members.find((m) => m.userId === state.fromUserId)?.profile ?? null;
const callerName =
callerProfile?.displayName ??
friendships.find((f) => f.peer.userId === state.fromUserId)?.peer.displayName ??
'?';
const groupName = isGroup ? (conversation.name ?? t('app:chats.new_group')) : null;
const title = isGroup ? groupName ?? callerName : callerName;
const letter = title.trim().charAt(0).toUpperCase() || '?';
const avatarUrl = isGroup
? (conversation.avatarUrl ?? callerProfile?.avatarUrl ?? null)
: callerProfile?.avatarUrl ?? null;
const colorKey = colorKeyFor(state.fromUserId);
const avatarTone = PULSE_BG[colorKey];
const mediaLabel =
state.mediaKind === 'video' ? 'Video Call' : 'Voice Call';
return (
<section
role="region"
aria-label={t('app:call.incoming_title')}
className="relative overflow-hidden border-b border-line bg-surface-3"
>
<div className="absolute inset-0 bg-[radial-gradient(circle_at_30%_20%,rgba(79,70,229,0.10),transparent_60%),radial-gradient(circle_at_70%_80%,rgba(109,115,255,0.08),transparent_55%)]" />
<div className="relative mx-auto flex max-w-[480px] flex-col items-center px-6 py-8 text-center">
<p className="text-[12px] font-semibold uppercase tracking-[0.12em] text-fg-muted">
{t('app:call.incoming_title')}
</p>
<div className="relative my-4 flex h-[112px] w-[112px] items-center justify-center">
<span
aria-hidden="true"
className="pointer-events-none absolute inset-0 rounded-full border-2 border-accent animate-pulse-ring"
/>
<span
aria-hidden="true"
className="pointer-events-none absolute inset-0 rounded-full border-2 border-accent animate-pulse-ring"
style={{ animationDelay: '1s' }}
/>
{avatarUrl ? (
<img
src={avatarUrl}
alt={title}
className="h-24 w-24 rounded-full border-[3px] border-surface-3 object-cover"
draggable={false}
/>
) : (
<div
className={
'flex h-24 w-24 items-center justify-center rounded-full border-[3px] border-surface-3 font-display text-4xl font-bold ' +
avatarTone
}
>
{letter}
</div>
)}
</div>
<p className="font-display text-2xl font-bold tracking-tight text-fg">{title}</p>
<p className="mt-1.5 flex items-center gap-1.5 text-xs text-fg-muted">
<LockIcon className="h-3.5 w-3.5" />
<span>E2E verschlüsselt · {mediaLabel}</span>
{isGroup && (
<>
<span className="text-fg-muted/50" aria-hidden="true">·</span>
<span>
{t('app:call.incoming_group_from', {
name: callerName,
defaultValue: callerName + ' ruft an',
})}
</span>
</>
)}
</p>
<div className="mt-5 flex w-full max-w-[360px] gap-3">
<button
type="button"
onClick={rejectIncoming}
className="inline-flex flex-1 cursor-pointer items-center justify-center gap-2 rounded-[14px] border border-rose-500/40 bg-transparent px-5 py-3.5 text-sm font-semibold text-rose-600 transition hover:bg-rose-500/10 focus:outline-none focus-visible:ring-2 focus-visible:ring-rose-500/40 dark:text-rose-400"
>
<PhoneOffIcon className="h-4 w-4" />
<span>{t('app:call.decline')}</span>
</button>
<button
type="button"
onClick={() => void acceptIncoming()}
className="inline-flex flex-1 cursor-pointer items-center justify-center gap-2 rounded-[14px] bg-emerald-600 px-5 py-3.5 text-sm font-semibold text-white shadow-accept-btn transition hover:bg-emerald-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500/50"
>
<PhoneIcon className="h-4 w-4" />
<span>{t('app:call.accept')}</span>
</button>
</div>
</div>
</section>
);
}
+137 -28
View File
@@ -14,29 +14,60 @@ import { devLocalSecretStore } from '../lib/secretStore';
import { supabase } from '../lib/supabase'; import { supabase } from '../lib/supabase';
import type { AggregatedReaction } from '../lib/useMessageReactions'; import type { AggregatedReaction } from '../lib/useMessageReactions';
import { AttachmentImage } from './AttachmentImage'; import { AttachmentImage } from './AttachmentImage';
import { PencilIcon, PhoneIcon, PhoneOffIcon, SmileIcon, SpinnerIcon, TrashIcon, XIcon } from './icons'; import { Avatar } from './Avatar';
import { ForwardIcon, PencilIcon, PhoneIcon, PhoneOffIcon, ReplyIcon, SmileIcon, SpinnerIcon, TrashIcon, XIcon } from './icons';
const EMOJI_CHOICES = ['👍', '❤️', '😂', '🎉', '🔥', '😮', '😢', '🙏']; const EMOJI_CHOICES = ['👍', '❤️', '😂', '🎉', '🔥', '😮', '😢', '🙏'];
const EDIT_WINDOW_MS = 24 * 60 * 60 * 1000; const EDIT_WINDOW_MS = 24 * 60 * 60 * 1000;
export interface QuotedRef {
id: string;
senderName: string;
snippet: string;
isAttachment: boolean;
deleted: boolean;
}
interface Props { interface Props {
message: DecryptedMessage; message: DecryptedMessage;
mine: boolean; mine: boolean;
groupedWithPrev: boolean; groupedWithPrev: boolean;
/** Last message of a run from this sender — anchor avatar on this row. */
isLastOfRun?: boolean;
senderDisplayName?: string | null | undefined;
senderAvatarUrl?: string | null | undefined;
conversationId: string; conversationId: string;
reactions: AggregatedReaction[]; reactions: AggregatedReaction[];
onToggleReaction: (emoji: string) => Promise<void>; onToggleReaction: (emoji: string) => Promise<void>;
showSeen?: boolean; showSeen?: boolean;
/** Resolved quoted message info (parent does the lookup). */
quoted?: QuotedRef | null;
/** Tap-to-jump on quote bubble. Receives the quoted message's id. */
onJumpToMessage?: (id: string) => void;
/** Hover action: parent receives current message to start a reply. */
onReply?: (m: DecryptedMessage) => void;
/** Hover action: parent opens forward dialog for current message. */
onForward?: (m: DecryptedMessage) => void;
/** Highlighted state — set briefly after a jump. */
highlighted?: boolean;
} }
export function MessageBubble({ export function MessageBubble({
message, message,
mine, mine,
groupedWithPrev, groupedWithPrev,
isLastOfRun = false,
senderDisplayName,
senderAvatarUrl,
conversationId, conversationId,
reactions, reactions,
onToggleReaction, onToggleReaction,
showSeen = false, showSeen = false,
quoted = null,
onJumpToMessage,
onReply,
onForward,
highlighted = false,
}: Props) { }: Props) {
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
const { session, device } = useAuth(); const { session, device } = useAuth();
@@ -143,8 +174,13 @@ export function MessageBubble({
if (message.deletedAt) { if (message.deletedAt) {
return ( return (
<div className={'flex ' + (mine ? 'justify-end' : 'justify-start')}> <div className={'flex items-end gap-2 ' + (mine ? 'flex-row-reverse' : '')}>
<div className="max-w-[70%] rounded-2xl border border-white/5 bg-white/5 px-3.5 py-1.5 text-xs italic text-neutral-500"> <AvatarSlot
show={isLastOfRun}
url={senderAvatarUrl ?? null}
displayName={senderDisplayName ?? null}
/>
<div className="max-w-[calc(70%-2.5rem)] rounded-2xl border border-line bg-surface-2 px-3.5 py-1.5 text-xs italic text-fg-muted">
{t('app:chats.deleted')} {t('app:chats.deleted')}
</div> </div>
</div> </div>
@@ -156,14 +192,19 @@ export function MessageBubble({
} }
return ( return (
<div className={'flex ' + (mine ? 'justify-end' : 'justify-start')}> <div className={'flex items-end gap-2 ' + (mine ? 'flex-row-reverse' : '')}>
<AvatarSlot
show={isLastOfRun}
url={senderAvatarUrl ?? null}
displayName={senderDisplayName ?? null}
/>
<div <div
className={ className={
'group relative max-w-[70%] ' + (groupedWithPrev ? 'mt-0.5' : 'mt-2') 'group relative max-w-[calc(70%-2.5rem)] ' + (groupedWithPrev ? 'mt-0.5' : 'mt-2')
} }
> >
{editing ? ( {editing ? (
<div className="rounded-2xl border border-brand-400/40 bg-ink-900/80 p-2 backdrop-blur-xl"> <div className="rounded-2xl border border-accent/40 bg-surface-2 p-2 shadow-sm">
<textarea <textarea
value={editText} value={editText}
onChange={(e) => setEditText(e.target.value)} onChange={(e) => setEditText(e.target.value)}
@@ -179,10 +220,10 @@ export function MessageBubble({
}} }}
rows={2} rows={2}
autoFocus autoFocus
className="w-full resize-none rounded-md bg-ink-800 px-3 py-2 text-sm text-white outline-none focus:ring-2 focus:ring-brand-400/60" className="w-full resize-none rounded-md border border-line bg-surface-3 px-3 py-2 text-sm text-fg outline-none focus:ring-2 focus:ring-accent/50"
/> />
{editError && ( {editError && (
<p className="mt-1.5 break-words rounded-md border border-rose-500/20 bg-rose-500/10 px-2 py-1 text-[11px] text-rose-200"> <p className="mt-1.5 break-words rounded-md border border-rose-500/30 bg-rose-500/10 px-2 py-1 text-[11px] text-rose-600 dark:text-rose-200">
{editError} {editError}
</p> </p>
)} )}
@@ -193,7 +234,7 @@ export function MessageBubble({
setEditing(false); setEditing(false);
setEditError(null); setEditError(null);
}} }}
className="cursor-pointer rounded-md border border-white/10 bg-white/5 px-3 py-1 text-xs text-neutral-200 hover:bg-white/10" className="cursor-pointer rounded-md border border-line bg-surface-3 px-3 py-1 text-xs text-fg hover:bg-surface-2"
> >
{t('app:friends.action_cancel')} {t('app:friends.action_cancel')}
</button> </button>
@@ -201,7 +242,7 @@ export function MessageBubble({
type="button" type="button"
disabled={busy} disabled={busy}
onClick={() => void handleEditSave()} onClick={() => void handleEditSave()}
className="inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-brand-500/90 px-3 py-1 text-xs font-semibold text-white hover:bg-brand-400 disabled:opacity-60" className="inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-accent px-3 py-1 text-xs font-semibold text-accent-fg hover:brightness-110 disabled:opacity-60"
> >
{busy && <SpinnerIcon className="h-3.5 w-3.5" />} {busy && <SpinnerIcon className="h-3.5 w-3.5" />}
<span>{t('common:save', { defaultValue: 'Save' })}</span> <span>{t('common:save', { defaultValue: 'Save' })}</span>
@@ -210,15 +251,48 @@ export function MessageBubble({
</div> </div>
) : ( ) : (
<div <div
data-message-id={message.id}
className={ className={
'break-words rounded-2xl px-3.5 py-2 text-sm ' + 'break-words px-3.5 py-2 text-sm transition ' +
(highlighted ? 'ring-2 ring-amber-400 ring-offset-2 ring-offset-surface-3 ' : '') +
(mine (mine
? 'bg-brand-500/85 text-white' ? 'rounded-[18px_18px_4px_18px] bg-accent text-accent-fg'
: 'border border-white/5 bg-ink-900/70 text-neutral-100') : 'rounded-[18px_18px_18px_4px] border border-line text-fg')
} }
> >
{quoted && (
<button
type="button"
onClick={() => onJumpToMessage?.(quoted.id)}
className={
'mb-1.5 flex w-full cursor-pointer items-stretch gap-2 rounded-md px-2 py-1.5 text-left text-xs transition hover:opacity-90 ' +
(mine
? 'bg-white/15 text-accent-fg/90'
: 'bg-surface-2 text-fg-muted')
}
>
<span
aria-hidden="true"
className={
'w-0.5 shrink-0 rounded-full ' + (mine ? 'bg-white/50' : 'bg-accent')
}
/>
<span className="min-w-0 flex-1">
<span className={'block truncate font-semibold ' + (mine ? '' : 'text-fg')}>
{quoted.senderName}
</span>
<span className="block truncate italic opacity-90">
{quoted.deleted
? t('app:chats.deleted')
: quoted.isAttachment && !quoted.snippet
? '📎 ' + t('app:chats.attachment', { defaultValue: 'Anhang' })
: quoted.snippet}
</span>
</span>
</button>
)}
{message.plaintext === null ? ( {message.plaintext === null ? (
<span className="italic text-neutral-400">cannot decrypt</span> <span className="italic opacity-70">cannot decrypt</span>
) : ( ) : (
<> <>
{bodyText.length > 0 && <div>{bodyText}</div>} {bodyText.length > 0 && <div>{bodyText}</div>}
@@ -230,7 +304,7 @@ export function MessageBubble({
<div <div
className={ className={
'mt-1 flex items-center gap-1.5 text-[10px] ' + 'mt-1 flex items-center gap-1.5 text-[10px] ' +
(mine ? 'text-brand-100/70' : 'text-neutral-500') (mine ? 'text-accent-fg/75' : 'text-fg-muted')
} }
> >
<span>{time}</span> <span>{time}</span>
@@ -242,7 +316,7 @@ export function MessageBubble({
)} )}
{showSeen && mine && !editing && !message.deletedAt && ( {showSeen && mine && !editing && !message.deletedAt && (
<p className="mt-0.5 text-right text-[10px] text-neutral-500"> <p className="mt-0.5 text-right text-[10px] text-fg-muted">
{t('app:chats.seen')} {t('app:chats.seen')}
</p> </p>
)} )}
@@ -255,10 +329,10 @@ export function MessageBubble({
type="button" type="button"
onClick={() => void onToggleReaction(r.emoji)} onClick={() => void onToggleReaction(r.emoji)}
className={ className={
'inline-flex cursor-pointer items-center gap-1 rounded-full border px-2 py-0.5 text-xs transition focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 ' + 'inline-flex cursor-pointer items-center gap-1 rounded-full border px-2 py-0.5 text-xs transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ' +
(r.mine (r.mine
? 'border-brand-400/40 bg-brand-500/20 text-brand-100' ? 'border-accent/40 bg-accent/20 text-accent'
: 'border-white/10 bg-white/5 text-neutral-200 hover:bg-white/10') : 'border-line bg-surface-2 text-fg hover:bg-surface-3')
} }
> >
<span>{r.emoji}</span> <span>{r.emoji}</span>
@@ -275,12 +349,26 @@ export function MessageBubble({
(mine ? 'right-full pr-2' : 'left-full pl-2') (mine ? 'right-full pr-2' : 'left-full pl-2')
} }
> >
<div className="flex items-center gap-0.5 rounded-lg border border-white/10 bg-ink-900/90 p-1 shadow-lg backdrop-blur-xl"> <div className="flex items-center gap-0.5 rounded-lg border border-line bg-surface-3 p-1 shadow-lg">
<ActionButton <ActionButton
label={t('app:friends.action_accept', { defaultValue: 'React' })} label={t('app:friends.action_accept', { defaultValue: 'React' })}
onClick={() => setPickerOpen((v) => !v)} onClick={() => setPickerOpen((v) => !v)}
icon={<SmileIcon className="h-4 w-4" />} icon={<SmileIcon className="h-4 w-4" />}
/> />
{onReply && !message.deletedAt && (
<ActionButton
label={t('app:chats.reply', { defaultValue: 'Antworten' })}
onClick={() => onReply(message)}
icon={<ReplyIcon className="h-4 w-4" />}
/>
)}
{onForward && !message.deletedAt && (
<ActionButton
label={t('app:chats.forward', { defaultValue: 'Weiterleiten' })}
onClick={() => onForward(message)}
icon={<ForwardIcon className="h-4 w-4" />}
/>
)}
{canEdit && ( {canEdit && (
<ActionButton <ActionButton
label="Edit" label="Edit"
@@ -306,7 +394,7 @@ export function MessageBubble({
ref={pickerRef} ref={pickerRef}
role="menu" role="menu"
className={ className={
'absolute z-30 mt-1 flex gap-1 rounded-lg border border-white/10 bg-ink-900/95 p-1.5 shadow-xl backdrop-blur-xl ' + 'absolute z-30 mt-1 flex gap-1 rounded-lg border border-line bg-surface-3 p-1.5 shadow-xl ' +
(mine ? 'right-0' : 'left-0') (mine ? 'right-0' : 'left-0')
} }
> >
@@ -315,7 +403,7 @@ export function MessageBubble({
key={e} key={e}
type="button" type="button"
onClick={() => void handlePickEmoji(e)} onClick={() => void handlePickEmoji(e)}
className="cursor-pointer rounded-md px-2 py-1 text-lg transition hover:bg-white/10 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40" className="cursor-pointer rounded-md px-2 py-1 text-lg transition hover:bg-surface-2 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
> >
{e} {e}
</button> </button>
@@ -323,7 +411,7 @@ export function MessageBubble({
<button <button
type="button" type="button"
onClick={() => setPickerOpen(false)} onClick={() => setPickerOpen(false)}
className="cursor-pointer rounded-md px-1.5 py-1 text-neutral-500 transition hover:bg-white/10" className="cursor-pointer rounded-md px-1.5 py-1 text-fg-muted transition hover:bg-surface-2"
> >
<XIcon className="h-4 w-4" /> <XIcon className="h-4 w-4" />
</button> </button>
@@ -336,6 +424,27 @@ export function MessageBubble({
); );
} }
function AvatarSlot({
show,
url,
displayName,
}: {
show: boolean;
url: string | null;
displayName: string | null;
}) {
if (!show) {
return <div aria-hidden="true" className="h-8 w-8 shrink-0" />;
}
return (
<Avatar
url={url}
displayName={displayName ?? ''}
className="h-8 w-8 text-xs"
/>
);
}
function CallEventRow({ function CallEventRow({
parsed, parsed,
mine, mine,
@@ -351,8 +460,8 @@ function CallEventRow({
const Icon = isMissed ? PhoneOffIcon : PhoneIcon; const Icon = isMissed ? PhoneOffIcon : PhoneIcon;
const tone = isMissed const tone = isMissed
? 'border-rose-500/20 bg-rose-500/10 text-rose-200' ? 'border-rose-500/30 bg-rose-500/10 text-rose-700 dark:text-rose-200'
: 'border-emerald-500/20 bg-emerald-500/10 text-emerald-200'; : 'border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-200';
const label = const label =
status === 'ended' status === 'ended'
@@ -408,10 +517,10 @@ function ActionButton({
title={label} title={label}
onClick={onClick} onClick={onClick}
className={ className={
'flex h-7 w-7 cursor-pointer items-center justify-center rounded-md transition focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 ' + 'flex h-7 w-7 cursor-pointer items-center justify-center rounded-md transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ' +
(tone === 'danger' (tone === 'danger'
? 'text-neutral-400 hover:bg-rose-500/20 hover:text-rose-200' ? 'text-fg-muted hover:bg-rose-500/20 hover:text-rose-500 dark:hover:text-rose-200'
: 'text-neutral-400 hover:bg-white/10 hover:text-neutral-100') : 'text-fg-muted hover:bg-surface-2 hover:text-fg')
} }
> >
{icon} {icon}
+5 -5
View File
@@ -35,22 +35,22 @@ export function Modal({ open, title, onClose, children, size = 'md' }: Props) {
aria-modal="true" aria-modal="true"
aria-label={title} aria-label={title}
onClick={onClose} onClick={onClose}
className="fixed inset-0 z-50 flex items-center justify-center bg-ink-950/80 p-6 backdrop-blur-sm animate-fade-in" className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-6 backdrop-blur-sm animate-fade-in"
> >
<div <div
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
className={ className={
'relative w-full animate-slide-up rounded-2xl border border-white/10 bg-ink-900/95 shadow-xl backdrop-blur-xl ' + 'relative w-full animate-slide-up rounded-2xl border border-line bg-surface-3 shadow-xl ' +
width width
} }
> >
<header className="flex items-center justify-between border-b border-white/5 px-6 py-4"> <header className="flex items-center justify-between border-b border-line px-6 py-4">
<h2 className="font-display text-lg font-semibold text-white">{title}</h2> <h2 className="font-display text-lg font-semibold text-fg">{title}</h2>
<button <button
type="button" type="button"
onClick={onClose} onClick={onClose}
aria-label="Close" aria-label="Close"
className="flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg text-neutral-400 transition hover:bg-white/10 hover:text-neutral-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40" className="flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg text-fg-muted transition hover:bg-surface-2 hover:text-fg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
> >
<XIcon className="h-4 w-4" /> <XIcon className="h-4 w-4" />
</button> </button>
@@ -0,0 +1,192 @@
import type { RemoteTrack } from 'livekit-client';
import { useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { useTranslation } from 'react-i18next';
import type { RemoteScreenShare } from '../context/CallContext';
import { MonitorShareIcon } from './icons';
interface ScreenShareViewerProps {
share: RemoteScreenShare;
avatarUrl: string | null;
displayName: string;
}
// Click-to-watch gate, live <video> attach/detach, native fullscreen toggle.
// Lifted out of the old InCallPanel so the new CallDock stays lean.
export function ScreenShareViewer({ share, avatarUrl, displayName }: ScreenShareViewerProps) {
const { t } = useTranslation(['app']);
const videoRef = useRef<HTMLVideoElement | null>(null);
const containerRef = useRef<HTMLDivElement | null>(null);
const [watching, setWatching] = useState(false);
const [isFullscreen, setIsFullscreen] = useState(false);
const letter = displayName.trim().charAt(0).toUpperCase() || '?';
useEffect(() => {
if (!watching) return;
const el = videoRef.current;
if (!el) return;
const track: RemoteTrack = share.track;
track.attach(el);
return () => {
track.detach(el);
};
}, [share.track, watching]);
// Esc exits CSS fullscreen.
useEffect(() => {
if (!isFullscreen) return;
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') setIsFullscreen(false);
};
window.addEventListener('keydown', onKey);
return () => window.removeEventListener('keydown', onKey);
}, [isFullscreen]);
// CSS-only "app fullscreen" — Discord-style: overlay the whole window
// including the left sidebar + chat list. Native Fullscreen API is
// unreliable in Tauri's WKWebView and doesn't add useful chrome-hiding
// beyond what `fixed inset-0 z-[60]` already gives us.
const toggleFullscreen = () => {
setIsFullscreen((v) => !v);
};
const viewerNode = (
<div
ref={containerRef}
className={
isFullscreen
? 'fixed inset-0 z-[60] flex h-screen w-screen flex-col overflow-hidden border-0 bg-black'
: 'overflow-hidden rounded-xl border border-emerald-500/30 bg-black'
}
>
<div className="flex shrink-0 items-center gap-2 border-b border-emerald-500/20 bg-emerald-500/15 px-3 py-1.5 text-xs text-emerald-700 dark:text-emerald-200">
<MonitorShareIcon className="h-3.5 w-3.5 shrink-0" />
<span className="flex-1 truncate">
{t('app:call.is_sharing_screen', {
name: displayName,
defaultValue: displayName + ' teilt den Bildschirm',
})}
</span>
{watching && (
<>
<button
type="button"
onClick={toggleFullscreen}
aria-label={t('app:call.fullscreen', { defaultValue: 'Vollbild' })}
title={t('app:call.fullscreen', { defaultValue: 'Vollbild' })}
className="inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md text-emerald-200 transition hover:bg-white/10 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400/40"
>
<FullscreenIcon className="h-3.5 w-3.5" />
</button>
<button
type="button"
onClick={() => {
if (document.fullscreenElement === containerRef.current) {
void document.exitFullscreen();
}
setWatching(false);
}}
aria-label={t('app:call.stop_watching', { defaultValue: 'Nicht mehr anschauen' })}
title={t('app:call.stop_watching', { defaultValue: 'Nicht mehr anschauen' })}
className="inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md text-emerald-200 transition hover:bg-white/10 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400/40"
>
<span aria-hidden="true" className="text-[14px] leading-none">×</span>
</button>
</>
)}
</div>
{watching ? (
<video
ref={videoRef}
autoPlay
playsInline
muted
onDoubleClick={toggleFullscreen}
className={
'block cursor-zoom-in bg-black ' +
(isFullscreen ? 'h-full w-full flex-1 object-contain' : 'w-full')
}
/>
) : (
<button
type="button"
onClick={() => setWatching(true)}
aria-label={t('app:call.watch_screen', { defaultValue: 'Bildschirm anschauen' })}
className="group relative block w-full cursor-pointer overflow-hidden bg-ink-900 focus:outline-none"
style={{ aspectRatio: '16 / 9' }}
>
<BlurredTile avatarUrl={avatarUrl} letter={letter} />
<div className="absolute inset-0 flex items-center justify-center bg-black/30 transition group-hover:bg-black/40">
<div className="flex flex-col items-center gap-2">
<span className="flex h-14 w-14 items-center justify-center rounded-full bg-emerald-500 text-white shadow-lg transition group-hover:scale-105">
<PlayIcon className="ml-0.5 h-6 w-6" />
</span>
<span className="text-xs font-medium text-white/90">
{t('app:call.watch_screen', { defaultValue: 'Bildschirm anschauen' })}
</span>
</div>
</div>
</button>
)}
</div>
);
// When in fullscreen, portal out of the call-panel subtree into <body> so
// no ancestor can clip or stack below us. Sidebar/chat-list are siblings of
// AppShell's root — portalled node sits above them via z-[60].
if (isFullscreen) {
return createPortal(viewerNode, document.body);
}
return viewerNode;
}
function BlurredTile({ avatarUrl, letter }: { avatarUrl: string | null; letter: string }) {
if (avatarUrl) {
return (
<>
<img
src={avatarUrl}
alt=""
className="absolute inset-0 h-full w-full scale-110 object-cover blur-2xl"
/>
<div className="absolute inset-0 bg-gradient-to-br from-accent/20 to-emerald-500/20" />
</>
);
}
return (
<div className="absolute inset-0 flex items-center justify-center bg-gradient-to-br from-accent/40 via-fuchsia-500/20 to-emerald-500/30">
<span
aria-hidden="true"
className="text-[120px] font-display font-bold text-white/20 blur-[2px]"
>
{letter}
</span>
</div>
);
}
function PlayIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg viewBox="0 0 24 24" fill="currentColor" {...props}>
<path d="M8 5v14l11-7z" />
</svg>
);
}
function FullscreenIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth={2}
strokeLinecap="round"
strokeLinejoin="round"
{...props}
>
<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5" />
</svg>
);
}
+114 -45
View File
@@ -4,107 +4,176 @@ import { NavLink } from 'react-router-dom';
import { useAuth } from '../context/AuthContext'; import { useAuth } from '../context/AuthContext';
import { useConversationsContext } from '../context/ConversationsContext'; import { useConversationsContext } from '../context/ConversationsContext';
import { useFriendshipsContext } from '../context/FriendshipsContext'; import { useFriendshipsContext } from '../context/FriendshipsContext';
import { CallBar } from './CallUI'; import { useTheme } from '../context/ThemeContext';
import { import {
ChatBubbleIcon, ChatBubbleIcon,
GearIcon, GearIcon,
LogoLockup, LogoMark,
MoonIcon,
ShieldIcon, ShieldIcon,
SignOutIcon, SignOutIcon,
SunIcon,
UsersIcon, UsersIcon,
} from './icons'; } from './icons';
import { UserBar } from './UserBar';
interface NavItem { interface NavItem {
to: string; to: string;
labelKey: string; labelKey: string;
icon: (props: React.SVGProps<SVGSVGElement>) => React.JSX.Element; icon: (props: React.SVGProps<SVGSVGElement>) => React.JSX.Element;
badge?: 'friends' | 'chats';
} }
const BASE_NAV_ITEMS: NavItem[] = [ const PRIMARY_NAV: NavItem[] = [
{ to: '/chats', labelKey: 'app:nav.chats', icon: ChatBubbleIcon }, { to: '/chats', labelKey: 'app:nav.chats', icon: ChatBubbleIcon, badge: 'chats' },
{ to: '/friends', labelKey: 'app:nav.friends', icon: UsersIcon }, { to: '/friends', labelKey: 'app:nav.friends', icon: UsersIcon, badge: 'friends' },
{ to: '/settings', labelKey: 'app:nav.settings', icon: GearIcon },
]; ];
const ADMIN_NAV_ITEM: NavItem = { const ADMIN_NAV: NavItem = {
to: '/admin', to: '/admin',
labelKey: 'app:nav.admin', labelKey: 'app:nav.admin',
icon: ShieldIcon, icon: ShieldIcon,
}; };
// Clean-Rail 72px icon rail. Brand logo top → primary tabs → spacer →
// settings + theme toggle + sign-out at bottom. Active tab shows a pill
// indicator anchored to the left edge of the rail.
export function Sidebar() { export function Sidebar() {
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
const { signOut, profile } = useAuth(); const { signOut, profile } = useAuth();
const { incomingCount } = useFriendshipsContext(); const { incomingCount } = useFriendshipsContext();
const { totalUnread } = useConversationsContext(); const { totalUnread } = useConversationsContext();
const { theme, toggle } = useTheme();
const navItems = profile?.isAdmin ? [...BASE_NAV_ITEMS, ADMIN_NAV_ITEM] : BASE_NAV_ITEMS; const navItems: NavItem[] = profile?.isAdmin ? [...PRIMARY_NAV, ADMIN_NAV] : PRIMARY_NAV;
return ( return (
<aside <aside
aria-label="Primary navigation" aria-label="Primary navigation"
className="flex h-screen w-72 shrink-0 flex-col border-r border-white/5 bg-ink-900/70 backdrop-blur-xl" className="flex h-screen w-[72px] shrink-0 flex-col items-center border-r border-line bg-surface-2/80 py-4 backdrop-blur-xl"
> >
<div className="flex items-center px-5 pb-3 pt-5"> <div className="flex h-10 w-10 items-center justify-center" title="Netralax">
<LogoLockup tone="dark" className="h-8 w-auto" aria-label="Netralax" /> <LogoMark className="h-8 w-8" />
</div> </div>
<nav className="mt-2 flex flex-col gap-0.5 px-3"> <div className="my-3 h-px w-8 bg-line" aria-hidden="true" />
<nav className="flex flex-col items-center gap-2">
{navItems.map((item) => { {navItems.map((item) => {
const badge = const badgeCount =
item.to === '/friends' item.badge === 'friends'
? incomingCount ? incomingCount
: item.to === '/chats' : item.badge === 'chats'
? totalUnread ? totalUnread
: 0; : 0;
const ariaLabel = badge > 0 ? `${t(item.labelKey)} (${badge})` : undefined;
return ( return (
<NavLink <RailNavLink
key={item.to} key={item.to}
to={item.to} to={item.to}
aria-label={ariaLabel} label={t(item.labelKey)}
className={({ isActive }) => icon={item.icon}
[ badge={badgeCount}
'group flex cursor-pointer items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition', />
'focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/50',
isActive
? 'bg-brand-500/15 text-white ring-1 ring-brand-400/30'
: 'text-neutral-400 hover:bg-white/5 hover:text-neutral-100',
].join(' ')
}
>
<item.icon style={{ width: '18px', height: '18px' }} className="transition" />
<span className="flex-1">{t(item.labelKey)}</span>
{badge > 0 && <NavBadge count={badge} />}
</NavLink>
); );
})} })}
</nav> </nav>
<div className="flex-1" /> <div className="flex-1" />
<div className="border-t border-white/5 p-3"> <div className="flex flex-col items-center gap-2">
<CallBar /> <RailNavLink
<UserBar /> to="/settings"
<button label={t('app:nav.settings')}
type="button" icon={GearIcon}
/>
<RailIconButton
label={theme === 'dark' ? t('app:theme.light', { defaultValue: 'Light mode' }) : t('app:theme.dark', { defaultValue: 'Dark mode' })}
onClick={toggle}
icon={theme === 'dark' ? SunIcon : MoonIcon}
/>
<RailIconButton
label={t('app:sidebar.sign_out')}
onClick={() => void signOut()} onClick={() => void signOut()}
className="mt-2 flex w-full cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-xs font-medium text-neutral-400 transition hover:bg-rose-500/10 hover:text-rose-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-rose-400/40" icon={SignOutIcon}
> tone="danger"
<SignOutIcon className="h-4 w-4" /> />
<span>{t('app:sidebar.sign_out')}</span>
</button>
</div> </div>
</aside> </aside>
); );
} }
function NavBadge({ count }: { count: number }) { interface RailNavLinkProps {
to: string;
label: string;
icon: (props: React.SVGProps<SVGSVGElement>) => React.JSX.Element;
badge?: number;
}
function RailNavLink({ to, label, icon: Icon, badge = 0 }: RailNavLinkProps) {
const ariaLabel = badge > 0 ? `${label} (${badge})` : label;
return (
<NavLink
to={to}
aria-label={ariaLabel}
title={label}
className={({ isActive }) =>
[
'group relative flex h-11 w-11 cursor-pointer items-center justify-center rounded-xl transition',
'focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/50',
isActive
? 'bg-accent/15 text-accent'
: 'text-fg-muted hover:bg-surface-3/60 hover:text-fg',
].join(' ')
}
>
{({ isActive }) => (
<>
{isActive && (
<span
aria-hidden="true"
className="absolute -left-4 h-6 w-1 rounded-r-full bg-accent"
/>
)}
<Icon style={{ width: '20px', height: '20px' }} />
{badge > 0 && <RailBadge count={badge} />}
</>
)}
</NavLink>
);
}
interface RailIconButtonProps {
label: string;
onClick: () => void;
icon: (props: React.SVGProps<SVGSVGElement>) => React.JSX.Element;
tone?: 'default' | 'danger';
}
function RailIconButton({ label, onClick, icon: Icon, tone = 'default' }: RailIconButtonProps) {
const toneClass =
tone === 'danger'
? 'text-fg-muted hover:bg-rose-500/10 hover:text-rose-400 focus-visible:ring-rose-400/40'
: 'text-fg-muted hover:bg-surface-3/60 hover:text-fg focus-visible:ring-accent/50';
return (
<button
type="button"
aria-label={label}
title={label}
onClick={onClick}
className={
'flex h-11 w-11 cursor-pointer items-center justify-center rounded-xl transition focus:outline-none focus-visible:ring-2 ' +
toneClass
}
>
<Icon style={{ width: '20px', height: '20px' }} />
</button>
);
}
function RailBadge({ count }: { count: number }) {
const display = count > 99 ? '99+' : String(count); const display = count > 99 ? '99+' : String(count);
return ( return (
<span <span
aria-hidden="true" aria-hidden="true"
className="inline-flex min-w-[20px] items-center justify-center rounded-full bg-rose-500 px-1.5 text-[10px] font-bold leading-tight text-white shadow-[0_0_0_2px_rgba(15,15,24,1)]" className="absolute -right-1 -top-1 inline-flex min-w-[18px] items-center justify-center rounded-full bg-rose-500 px-1 text-[10px] font-bold leading-tight text-white ring-2 ring-surface-2"
> >
{display} {display}
</span> </span>
@@ -20,7 +20,7 @@ export function TypingIndicator({ typingUserIds, members }: Props) {
: t('app:chats.typing_many', { count: typingUserIds.length }); : t('app:chats.typing_many', { count: typingUserIds.length });
return ( return (
<div className="px-6 pb-1 pt-0 text-xs text-neutral-400"> <div className="bg-surface-3 px-6 pb-1 pt-0 text-xs text-fg-muted">
<span className="inline-flex items-center gap-2"> <span className="inline-flex items-center gap-2">
<TypingDots /> <TypingDots />
<span>{text}</span> <span>{text}</span>
@@ -32,9 +32,9 @@ export function TypingIndicator({ typingUserIds, members }: Props) {
function TypingDots() { function TypingDots() {
return ( return (
<span aria-hidden="true" className="inline-flex items-center gap-0.5"> <span aria-hidden="true" className="inline-flex items-center gap-0.5">
<span className="h-1 w-1 rounded-full bg-neutral-500 [animation:pulse_1.2s_ease-in-out_infinite]" /> <span className="h-1 w-1 rounded-full bg-fg-muted [animation:pulse_1.2s_ease-in-out_infinite]" />
<span className="h-1 w-1 rounded-full bg-neutral-500 [animation:pulse_1.2s_ease-in-out_infinite] [animation-delay:0.15s]" /> <span className="h-1 w-1 rounded-full bg-fg-muted [animation:pulse_1.2s_ease-in-out_infinite] [animation-delay:0.15s]" />
<span className="h-1 w-1 rounded-full bg-neutral-500 [animation:pulse_1.2s_ease-in-out_infinite] [animation-delay:0.3s]" /> <span className="h-1 w-1 rounded-full bg-fg-muted [animation:pulse_1.2s_ease-in-out_infinite] [animation-delay:0.3s]" />
</span> </span>
); );
} }
+7 -7
View File
@@ -57,22 +57,22 @@ export function UpdateToast() {
<div <div
role="status" role="status"
aria-live="polite" aria-live="polite"
className="fixed bottom-6 left-6 z-50 w-80 overflow-hidden rounded-2xl border border-white/10 bg-ink-900/95 p-4 shadow-2xl backdrop-blur-xl" className="fixed bottom-6 left-6 z-50 w-80 overflow-hidden rounded-2xl border border-line bg-surface-3 p-4 shadow-2xl"
> >
<div className="flex items-start gap-3"> <div className="flex items-start gap-3">
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-brand-500/25 text-brand-200 ring-1 ring-brand-400/30"> <div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-accent/20 text-accent">
<SparklesIcon className="h-4 w-4" /> <SparklesIcon className="h-4 w-4" />
</div> </div>
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="text-sm font-semibold text-white"> <p className="text-sm font-semibold text-fg">
{t('app:update.available', { defaultValue: 'Update verfügbar' })} {t('app:update.available', { defaultValue: 'Update verfügbar' })}
{state.version ? ' · v' + state.version : ''} {state.version ? ' · v' + state.version : ''}
</p> </p>
{state.notes && ( {state.notes && (
<p className="mt-0.5 line-clamp-3 text-xs text-neutral-400">{state.notes}</p> <p className="mt-0.5 line-clamp-3 text-xs text-fg-muted">{state.notes}</p>
)} )}
{state.error && ( {state.error && (
<p className="mt-1 text-xs text-rose-300">{state.error}</p> <p className="mt-1 text-xs text-rose-500 dark:text-rose-300">{state.error}</p>
)} )}
</div> </div>
{!installing && ( {!installing && (
@@ -80,7 +80,7 @@ export function UpdateToast() {
type="button" type="button"
onClick={() => setDismissed(true)} onClick={() => setDismissed(true)}
aria-label={t('common:close', { defaultValue: 'Schließen' })} aria-label={t('common:close', { defaultValue: 'Schließen' })}
className="inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md text-neutral-400 transition hover:bg-white/10 hover:text-neutral-100" className="inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md text-fg-muted transition hover:bg-surface-2 hover:text-fg"
> >
<XIcon className="h-3.5 w-3.5" /> <XIcon className="h-3.5 w-3.5" />
</button> </button>
@@ -90,7 +90,7 @@ export function UpdateToast() {
type="button" type="button"
onClick={() => void handleInstall()} onClick={() => void handleInstall()}
disabled={installing} disabled={installing}
className="mt-3 inline-flex w-full cursor-pointer items-center justify-center gap-2 rounded-lg bg-gradient-to-br from-brand-400 to-brand-600 px-3 py-2 text-sm font-semibold text-white transition hover:from-brand-300 hover:to-brand-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/60 disabled:cursor-not-allowed disabled:opacity-60" className="mt-3 inline-flex w-full cursor-pointer items-center justify-center gap-2 rounded-lg bg-accent px-3 py-2 text-sm font-semibold text-accent-fg transition hover:brightness-110 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/60 disabled:cursor-not-allowed disabled:opacity-60"
> >
{installing ? ( {installing ? (
<> <>
+18 -17
View File
@@ -5,22 +5,19 @@ import { useTranslation } from 'react-i18next';
import { useAuth } from '../context/AuthContext'; import { useAuth } from '../context/AuthContext';
import { supabase } from '../lib/supabase'; import { supabase } from '../lib/supabase';
import { Avatar } from './Avatar';
import { ChevronDownIcon } from './icons'; import { ChevronDownIcon } from './icons';
const PRESENCE_OPTIONS: PresenceState[] = ['online', 'idle', 'dnd', 'invisible', 'offline']; const PRESENCE_OPTIONS: PresenceState[] = ['online', 'idle', 'dnd', 'invisible', 'offline'];
const PRESENCE_DOT: Record<PresenceState, string> = { const PRESENCE_DOT: Record<PresenceState, string> = {
online: 'bg-emerald-400', online: 'bg-emerald-500',
idle: 'bg-amber-400', idle: 'bg-amber-400',
dnd: 'bg-rose-500', dnd: 'bg-rose-500',
invisible: 'bg-neutral-500', invisible: 'bg-neutral-500',
offline: 'bg-neutral-600', offline: 'bg-neutral-400 dark:bg-neutral-600',
}; };
function avatarLetter(input: string | undefined): string {
return (input ?? '?').trim().charAt(0).toUpperCase() || '?';
}
export function UserBar() { export function UserBar() {
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
const { profile, refreshProfile } = useAuth(); const { profile, refreshProfile } = useAuth();
@@ -53,34 +50,38 @@ export function UserBar() {
onClick={() => setOpen((v) => !v)} onClick={() => setOpen((v) => !v)}
aria-haspopup="menu" aria-haspopup="menu"
aria-expanded={open} aria-expanded={open}
className="flex w-full cursor-pointer items-center gap-3 rounded-lg px-2 py-2 text-left transition hover:bg-white/5 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40" className="flex w-full cursor-pointer items-center gap-3 rounded-lg px-2 py-2 text-left transition hover:bg-surface-3 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
> >
<div className="relative flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-brand-500/30 text-sm font-semibold text-white ring-1 ring-brand-400/30"> <div className="relative">
{avatarLetter(profile?.displayName ?? profile?.username)} <Avatar
url={profile?.avatarUrl ?? null}
displayName={profile?.displayName ?? profile?.username}
className="h-9 w-9 text-sm"
/>
<span <span
className={ className={
'absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full ring-2 ring-ink-900 ' + 'absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full ring-2 ring-surface-2 ' +
PRESENCE_DOT[presence] PRESENCE_DOT[presence]
} }
/> />
</div> </div>
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="truncate text-sm font-medium text-white"> <p className="truncate text-sm font-medium text-fg">
{profile?.displayName ?? '—'} {profile?.displayName ?? '—'}
</p> </p>
<p className="truncate text-xs text-neutral-400"> <p className="truncate text-xs text-fg-muted">
{profile?.username ? '@' + profile.username : '—'} {t('app:presence.' + presence)}
</p> </p>
</div> </div>
<ChevronDownIcon <ChevronDownIcon
className={'h-4 w-4 text-neutral-500 transition ' + (open ? 'rotate-180' : '')} className={'h-4 w-4 text-fg-muted transition ' + (open ? 'rotate-180' : '')}
/> />
</button> </button>
{open && ( {open && (
<div <div
role="menu" role="menu"
className="absolute bottom-full left-0 right-0 mb-2 overflow-hidden rounded-lg border border-white/10 bg-ink-900/95 shadow-xl backdrop-blur-xl" className="absolute bottom-full left-0 right-0 mb-2 overflow-hidden rounded-lg border border-line bg-surface-3 shadow-xl"
> >
{PRESENCE_OPTIONS.map((opt) => ( {PRESENCE_OPTIONS.map((opt) => (
<button <button
@@ -90,12 +91,12 @@ export function UserBar() {
aria-checked={opt === presence} aria-checked={opt === presence}
onClick={() => void changePresence(opt)} onClick={() => void changePresence(opt)}
disabled={busy} disabled={busy}
className="flex w-full cursor-pointer items-center gap-3 px-3 py-2 text-left text-sm text-neutral-200 transition hover:bg-white/5 disabled:opacity-50" className="flex w-full cursor-pointer items-center gap-3 px-3 py-2 text-left text-sm text-fg transition hover:bg-surface-2 disabled:opacity-50"
> >
<span className={'h-2.5 w-2.5 rounded-full ' + PRESENCE_DOT[opt]} /> <span className={'h-2.5 w-2.5 rounded-full ' + PRESENCE_DOT[opt]} />
<span className="flex-1">{t('app:presence.' + opt)}</span> <span className="flex-1">{t('app:presence.' + opt)}</span>
{opt === presence && ( {opt === presence && (
<span className="text-xs text-brand-300"></span> <span className="text-xs text-accent"></span>
)} )}
</button> </button>
))} ))}
+151
View File
@@ -336,6 +336,157 @@ export function MonitorStopIcon(props: IconProps) {
); );
} }
export function SunIcon(props: IconProps) {
return (
<Base {...props}>
<circle cx="12" cy="12" r="4" />
<path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41" />
</Base>
);
}
export function MoonIcon(props: IconProps) {
return (
<Base {...props}>
<path d="M21 12.79A9 9 0 1 1 11.21 3a7 7 0 0 0 9.79 9.79Z" />
</Base>
);
}
export function GridIcon(props: IconProps) {
return (
<Base {...props}>
<rect x="3" y="3" width="7" height="7" rx="1.5" />
<rect x="14" y="3" width="7" height="7" rx="1.5" />
<rect x="3" y="14" width="7" height="7" rx="1.5" />
<rect x="14" y="14" width="7" height="7" rx="1.5" />
</Base>
);
}
export function FocusIcon(props: IconProps) {
return (
<Base {...props}>
<rect x="3" y="3" width="18" height="18" rx="2" />
<rect x="8" y="8" width="8" height="8" rx="1" />
</Base>
);
}
export function MaximizeIcon(props: IconProps) {
return (
<Base {...props}>
<path d="M4 9V5a1 1 0 0 1 1-1h4" />
<path d="M20 9V5a1 1 0 0 0-1-1h-4" />
<path d="M4 15v4a1 1 0 0 0 1 1h4" />
<path d="M20 15v4a1 1 0 0 1-1 1h-4" />
</Base>
);
}
export function VideoIcon(props: IconProps) {
return (
<Base {...props}>
<rect x="2" y="6" width="15" height="12" rx="2" />
<path d="m22 8-5 4 5 4V8Z" />
</Base>
);
}
export function CrownIcon(props: IconProps) {
return (
<Base {...props}>
<path d="m3 7 4 4 5-6 5 6 4-4v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z" />
</Base>
);
}
export function SendIcon(props: IconProps) {
return (
<Base {...props}>
<path d="m3 11 18-8-8 18-2-8-8-2Z" />
</Base>
);
}
export function ArchiveIcon(props: IconProps) {
return (
<Base {...props}>
<rect x="3" y="4" width="18" height="5" rx="1" />
<path d="M5 9v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9" />
<path d="M10 13h4" />
</Base>
);
}
export function BellIcon(props: IconProps) {
return (
<Base {...props}>
<path d="M6 8a6 6 0 1 1 12 0c0 4 1.5 5 2 6H4c.5-1 2-2 2-6Z" />
<path d="M9.5 18a2.5 2.5 0 0 0 5 0" />
</Base>
);
}
export function BellOffIcon(props: IconProps) {
return (
<Base {...props}>
<path d="M9.5 18a2.5 2.5 0 0 0 5 0" />
<path d="M13.73 4A2 2 0 0 0 10 4" />
<path d="M18 8c0 1-.1 1.9-.2 2.7" />
<path d="M4 4 20 20" />
<path d="M6 8a6 6 0 0 1 .2-1.7" />
<path d="M4 18h13.5L18 17.4c.5-1 2-2 2-6" />
</Base>
);
}
export function MoreVerticalIcon(props: IconProps) {
return (
<Base {...props}>
<circle cx="12" cy="5" r="1.5" />
<circle cx="12" cy="12" r="1.5" />
<circle cx="12" cy="19" r="1.5" />
</Base>
);
}
export function ReplyIcon(props: IconProps) {
return (
<Base {...props}>
<polyline points="9 17 4 12 9 7" />
<path d="M20 18v-2a4 4 0 0 0-4-4H4" />
</Base>
);
}
export function ForwardIcon(props: IconProps) {
return (
<Base {...props}>
<polyline points="15 17 20 12 15 7" />
<path d="M4 18v-2a4 4 0 0 1 4-4h12" />
</Base>
);
}
export function ChevronUpIcon(props: IconProps) {
return (
<Base {...props}>
<polyline points="18 15 12 9 6 15" />
</Base>
);
}
export function AddUserIcon(props: IconProps) {
return (
<Base {...props}>
<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" />
<circle cx="9" cy="7" r="4" />
<path d="M19 8v6M22 11h-6" />
</Base>
);
}
export function LogoMark(props: IconProps) { export function LogoMark(props: IconProps) {
return ( return (
<svg <svg
+27 -23
View File
@@ -54,30 +54,34 @@ export function AuthProvider({ children }: { children: ReactNode }) {
(async () => { (async () => {
const { data: sessionRes } = await supabase.auth.getSession(); const { data: sessionRes } = await supabase.auth.getSession();
if (cancelled) return; if (cancelled) return;
if (sessionRes.session) { // Flip `ready` immediately on cached session read so the UI unblocks even
const { error } = await supabase.auth.getUser(); // if the network is slow/down. Validate the token in the background and
if (cancelled) return; // only wipe on an unambiguous 401/403 — a stalled getUser (Tauri WebView
if (error) { // with no network, server unreachable) must not keep the app on the
const status = (error as { status?: number }).status; // loading spinner forever.
if (status === 401 || status === 403) { setSession(sessionRes.session ?? null);
// Token genuinely invalid — wipe.
await supabase.auth.signOut({ scope: 'local' }).catch(() => {
/* ignore */
});
setSession(null);
} else {
// Network / server unreachable — keep cached session, let reads
// fail gracefully and recover when the stack is back.
console.warn('auth.getUser failed, keeping cached session:', error);
setSession(sessionRes.session);
}
} else {
setSession(sessionRes.session);
}
} else {
setSession(null);
}
setReady(true); setReady(true);
if (sessionRes.session) {
supabase.auth
.getUser()
.then(({ error }) => {
if (cancelled || !error) return;
const status = (error as { status?: number }).status;
if (status === 401 || status === 403) {
void supabase.auth.signOut({ scope: 'local' }).catch(() => {
/* ignore */
});
setSession(null);
} else {
// Network / server unreachable — keep cached session.
console.warn('auth.getUser failed, keeping cached session:', error);
}
})
.catch((err: unknown) => {
console.warn('auth.getUser rejected, keeping cached session:', err);
});
}
})(); })();
const { data: sub } = supabase.auth.onAuthStateChange((_event, s) => { const { data: sub } = supabase.auth.onAuthStateChange((_event, s) => {
setSession(s); setSession(s);
+113
View File
@@ -40,6 +40,7 @@ import { getPttSettings, subscribePttSettings } from '../lib/pttSettings';
import { import {
getAudioQualityParams, getAudioQualityParams,
getAudioSettings, getAudioSettings,
updateAudioSettings,
} from '../lib/audioSettings'; } from '../lib/audioSettings';
import { import {
createCallE2EE, createCallE2EE,
@@ -90,6 +91,10 @@ export interface RemoteScreenShare {
participantName: string; participantName: string;
} }
// Visual call modes (Discord-style): grid shows all tiles equally, focus pins
// one speaker with others in a strip, fullscreen is cinema mode.
export type CallMode = 'grid' | 'focus' | 'fullscreen';
interface CallContextValue { interface CallContextValue {
state: CallState; state: CallState;
room: Room | null; room: Room | null;
@@ -102,6 +107,9 @@ interface CallContextValue {
// Remembers the conversation of the last call we left so a sidebar widget // Remembers the conversation of the last call we left so a sidebar widget
// can show "still live — rejoin" while peers stay in the room. // can show "still live — rejoin" while peers stay in the room.
lastCallConversationId: string | null; lastCallConversationId: string | null;
// Clean-Rail UI state — display mode + focused participant id.
callMode: CallMode;
focusedId: string | null;
// Actions: // Actions:
startCall: (conversationId: string, mediaKind?: CallKind) => Promise<void>; startCall: (conversationId: string, mediaKind?: CallKind) => Promise<void>;
joinActiveCall: (conversationId: string, mediaKind?: CallKind) => Promise<void>; joinActiveCall: (conversationId: string, mediaKind?: CallKind) => Promise<void>;
@@ -111,6 +119,14 @@ interface CallContextValue {
toggleMute: () => void; toggleMute: () => void;
toggleScreenShare: () => Promise<void>; toggleScreenShare: () => Promise<void>;
dismissLastCall: () => void; dismissLastCall: () => void;
setCallMode: (mode: CallMode) => void;
setFocusedId: (id: string | null) => void;
// Runtime mic switch. Persists choice so subsequent calls reuse it, and
// hot-swaps the input on an active call without a reconnect.
setAudioInputDevice: (deviceId: string | null) => Promise<void>;
// Runtime speaker/headphone switch. Persists + applies setSinkId to all
// currently-attached remote-audio elements.
setAudioOutputDevice: (deviceId: string | null) => Promise<void>;
} }
const CallContext = createContext<CallContextValue | null>(null); const CallContext = createContext<CallContextValue | null>(null);
@@ -135,6 +151,8 @@ export function CallProvider({ children }: { children: ReactNode }) {
const [isScreenSharing, setIsScreenSharing] = useState(false); const [isScreenSharing, setIsScreenSharing] = useState(false);
const [remoteScreenShares, setRemoteScreenShares] = useState<RemoteScreenShare[]>([]); const [remoteScreenShares, setRemoteScreenShares] = useState<RemoteScreenShare[]>([]);
const [lastCallConversationId, setLastCallConversationId] = useState<string | null>(null); const [lastCallConversationId, setLastCallConversationId] = useState<string | null>(null);
const [callMode, setCallModeState] = useState<CallMode>('grid');
const [focusedId, setFocusedIdState] = useState<string | null>(null);
const signalChannelRef = useRef<RealtimeChannel | null>(null); const signalChannelRef = useRef<RealtimeChannel | null>(null);
const presenceChannelRef = useRef<RealtimeChannel | null>(null); const presenceChannelRef = useRef<RealtimeChannel | null>(null);
@@ -471,12 +489,16 @@ export function CallProvider({ children }: { children: ReactNode }) {
setIsE2EEActive(false); setIsE2EEActive(false);
} }
try { try {
const inputId = getAudioSettings().inputDeviceId;
await r.localParticipant.setMicrophoneEnabled(true, { await r.localParticipant.setMicrophoneEnabled(true, {
echoCancellation: aParams.echoCancellation, echoCancellation: aParams.echoCancellation,
noiseSuppression: aParams.noiseSuppression, noiseSuppression: aParams.noiseSuppression,
autoGainControl: aParams.autoGainControl, autoGainControl: aParams.autoGainControl,
channelCount: aParams.stereo ? 2 : 1, channelCount: aParams.stereo ? 2 : 1,
sampleRate: aParams.sampleRateHz, sampleRate: aParams.sampleRateHz,
// Plain string maps to `ideal` — if the device is gone we fall back
// to OS default instead of throwing NotFoundError.
...(inputId ? { deviceId: inputId } : {}),
}); });
} catch (micErr: unknown) { } catch (micErr: unknown) {
console.error('setMicrophoneEnabled failed', micErr); console.error('setMicrophoneEnabled failed', micErr);
@@ -954,6 +976,76 @@ export function CallProvider({ children }: { children: ReactNode }) {
} }
}, [myId, clearRingTimer, clearSoloTimer, disconnectRoom, sendSignal, emitCallEvent]); }, [myId, clearRingTimer, clearSoloTimer, disconnectRoom, sendSignal, emitCallEvent]);
const setCallMode = useCallback((mode: CallMode) => {
setCallModeState(mode);
}, []);
const setFocusedId = useCallback((id: string | null) => {
setFocusedIdState(id);
}, []);
const setAudioInputDevice = useCallback(async (deviceId: string | null) => {
updateAudioSettings({ inputDeviceId: deviceId });
const r = roomRef.current;
if (!r) return;
try {
// LiveKit API: `switchActiveDevice(kind, deviceId)` hot-swaps without a
// reconnect. Pass empty string or `default` to revert to OS default.
await r.switchActiveDevice('audioinput', deviceId ?? 'default');
} catch (err: unknown) {
console.error('switchActiveDevice(audioinput) failed', err);
}
}, []);
const setAudioOutputDevice = useCallback(async (deviceId: string | null) => {
updateAudioSettings({ outputDeviceId: deviceId });
const sinkId = deviceId ?? '';
// Apply to every <audio> element we've attached to the body. LiveKit's
// switchActiveDevice only tracks elements it attached itself; our custom
// appendChild path bypasses that, so we iterate and setSinkId manually.
const els = document.querySelectorAll<HTMLAudioElement>(
'audio[data-livekit-track]',
);
for (const el of Array.from(els)) {
if (typeof el.setSinkId !== 'function') continue;
try {
await el.setSinkId(sinkId);
} catch (err: unknown) {
console.warn('setSinkId on audio element failed', err);
}
}
const r = roomRef.current;
if (r) {
try {
await r.switchActiveDevice('audiooutput', sinkId || 'default');
} catch (err: unknown) {
console.warn('switchActiveDevice(audiooutput) failed', err);
}
}
}, []);
// Reset UI call-mode state when the call leaves any active phase so the next
// call starts fresh at grid/unfocused.
useEffect(() => {
if (state.kind === 'idle' || state.kind === 'error') {
setCallModeState('grid');
setFocusedIdState(null);
}
}, [state.kind]);
// Global Esc: drop out of fullscreen cinema back to grid while in an active
// call. Doesn't hangup and doesn't fire when other dialogs would consume it.
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key !== 'Escape') return;
if (callMode !== 'fullscreen') return;
if (state.kind !== 'connected' && state.kind !== 'connecting') return;
setCallModeState('grid');
};
window.addEventListener('keydown', onKey);
return () => window.removeEventListener('keydown', onKey);
}, [callMode, state.kind]);
const value = useMemo<CallContextValue>( const value = useMemo<CallContextValue>(
() => ({ () => ({
state, state,
@@ -964,6 +1056,8 @@ export function CallProvider({ children }: { children: ReactNode }) {
isScreenSharing, isScreenSharing,
remoteScreenShares, remoteScreenShares,
lastCallConversationId, lastCallConversationId,
callMode,
focusedId,
startCall, startCall,
joinActiveCall, joinActiveCall,
acceptIncoming, acceptIncoming,
@@ -972,6 +1066,10 @@ export function CallProvider({ children }: { children: ReactNode }) {
toggleMute, toggleMute,
toggleScreenShare, toggleScreenShare,
dismissLastCall, dismissLastCall,
setCallMode,
setFocusedId,
setAudioInputDevice,
setAudioOutputDevice,
}), }),
[ [
state, state,
@@ -982,6 +1080,8 @@ export function CallProvider({ children }: { children: ReactNode }) {
isScreenSharing, isScreenSharing,
remoteScreenShares, remoteScreenShares,
lastCallConversationId, lastCallConversationId,
callMode,
focusedId,
startCall, startCall,
joinActiveCall, joinActiveCall,
acceptIncoming, acceptIncoming,
@@ -990,6 +1090,10 @@ export function CallProvider({ children }: { children: ReactNode }) {
toggleMute, toggleMute,
toggleScreenShare, toggleScreenShare,
dismissLastCall, dismissLastCall,
setCallMode,
setFocusedId,
setAudioInputDevice,
setAudioOutputDevice,
], ],
); );
@@ -1014,6 +1118,15 @@ function attachTrack(
audio.setAttribute('playsinline', 'true'); audio.setAttribute('playsinline', 'true');
audio.setAttribute('data-livekit-track', track.sid ?? ''); audio.setAttribute('data-livekit-track', track.sid ?? '');
document.body.appendChild(audio); document.body.appendChild(audio);
// Apply persisted sinkId so the element routes to the user's chosen
// speaker/headphone from the start (LiveKit's own `switchActiveDevice`
// doesn't track custom-appended elements).
const sinkId = getAudioSettings().outputDeviceId;
if (sinkId && typeof audio.setSinkId === 'function') {
void audio.setSinkId(sinkId).catch((err: unknown) => {
console.warn('setSinkId on attach failed', err);
});
}
} }
} }
// Video is handled later in M2.6/M3 by a dedicated <video> element. // Video is handled later in M2.6/M3 by a dedicated <video> element.
@@ -1,4 +1,8 @@
import { type ConversationSummary, listConversations } from '@chat-app/shared/chat'; import {
type ConversationSummary,
isConversationMuted,
listConversations,
} from '@chat-app/shared/chat';
import { import {
createContext, createContext,
type ReactNode, type ReactNode,
@@ -151,6 +155,15 @@ export function ConversationsProvider({ children }: { children: ReactNode }) {
.on('postgres_changes', { event: '*', schema: 'public', table: 'conversations' }, () => { .on('postgres_changes', { event: '*', schema: 'public', table: 'conversations' }, () => {
void refresh(); void refresh();
}) })
.on(
'postgres_changes',
{ event: 'UPDATE', schema: 'public', table: 'profiles' },
() => {
// Peer updated their profile (e.g. uploaded avatar / changed name).
// Re-pull conversations so members[].profile picks up the new data.
void refresh();
},
)
.on( .on(
'postgres_changes', 'postgres_changes',
{ event: 'INSERT', schema: 'public', table: 'messages' }, { event: 'INSERT', schema: 'public', table: 'messages' },
@@ -168,10 +181,15 @@ export function ConversationsProvider({ children }: { children: ReactNode }) {
...prev, ...prev,
[row.conversation_id]: (prev[row.conversation_id] ?? 0) + 1, [row.conversation_id]: (prev[row.conversation_id] ?? 0) + 1,
})); }));
// Notification sound + OS notification — respect DND. Body stays // Notification sound + OS notification — respect DND and
// empty because message content is E2E-encrypted and only // per-conversation mute. Body stays empty because message
// decryptable in the conversation view (not at this hook level). // content is E2E-encrypted and only decryptable in the
if (presenceRef.current !== 'dnd') { // conversation view (not at this hook level).
const convForMute = conversationsRef.current.find(
(c) => c.id === row.conversation_id,
);
const muted = isConversationMuted(convForMute?.mutedUntil ?? null);
if (presenceRef.current !== 'dnd' && !muted) {
playNotificationTone(); playNotificationTone();
const conv = conversationsRef.current.find( const conv = conversationsRef.current.find(
(c) => c.id === row.conversation_id, (c) => c.id === row.conversation_id,
@@ -195,7 +213,31 @@ export function ConversationsProvider({ children }: { children: ReactNode }) {
) )
.subscribe(); .subscribe();
// Windows WebView2 aggressively throttles background WebSockets and
// sometimes drops events entirely while the window is minimised. Force a
// refresh + realtime reconnect on visibility/focus regain so we never
// leave stale conversation lists on a Windows client after the user
// returns to the app.
const onAwake = () => {
if (document.visibilityState !== 'visible') return;
void refresh();
try {
// If the socket got wedged during background throttle, a no-op
// unsubscribe+resubscribe brings it back. `subscribe()` on an already
// joined channel is a no-op so this is safe.
channel.subscribe();
} catch {
/* ignore — already live */
}
};
document.addEventListener('visibilitychange', onAwake);
window.addEventListener('focus', onAwake);
window.addEventListener('online', onAwake);
return () => { return () => {
document.removeEventListener('visibilitychange', onAwake);
window.removeEventListener('focus', onAwake);
window.removeEventListener('online', onAwake);
void supabase.removeChannel(channel); void supabase.removeChannel(channel);
}; };
}, [myId, refresh, markRead]); }, [myId, refresh, markRead]);
+53
View File
@@ -0,0 +1,53 @@
import {
createContext,
type ReactNode,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from 'react';
import { applyTheme, getInitialTheme, setThemePersisted, type Theme } from '../lib/theme';
interface ThemeContextValue {
theme: Theme;
toggle: () => void;
setTheme: (t: Theme) => void;
}
const ThemeContext = createContext<ThemeContextValue | null>(null);
export function ThemeProvider({ children }: { children: ReactNode }) {
const [theme, setThemeState] = useState<Theme>(() => getInitialTheme());
useEffect(() => {
applyTheme(theme);
}, [theme]);
const setTheme = useCallback((next: Theme) => {
setThemePersisted(next);
setThemeState(next);
}, []);
const toggle = useCallback(() => {
setThemeState((prev) => {
const next: Theme = prev === 'dark' ? 'light' : 'dark';
setThemePersisted(next);
return next;
});
}, []);
const value = useMemo<ThemeContextValue>(
() => ({ theme, toggle, setTheme }),
[theme, toggle, setTheme],
);
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
}
export function useTheme(): ThemeContextValue {
const ctx = useContext(ThemeContext);
if (!ctx) throw new Error('useTheme must be used within ThemeProvider');
return ctx;
}
+14 -2
View File
@@ -44,10 +44,22 @@ export async function checkForUpdate(): Promise<UpdateState> {
error: null, error: null,
}; };
} catch (err: unknown) { } catch (err: unknown) {
console.warn('checkForUpdate failed', err); // Swallow "no release on GitHub yet" / network-unreachable cases silently.
// The updater endpoint serves `latest.json` from GitHub releases; a fresh
// repo or offline machine produces a generic "Could not fetch a valid
// release JSON" error that has no actionable information for the user —
// logging it on every launch just pollutes the console.
const msg = err instanceof Error ? err.message : String(err);
const benign =
/could not fetch a valid release json|network|timed? out|failed to fetch|connection/i.test(
msg,
);
if (!benign) {
console.warn('checkForUpdate failed', err);
}
return { return {
...IDLE_UPDATE_STATE, ...IDLE_UPDATE_STATE,
error: err instanceof Error ? err.message : 'update check failed', error: benign ? null : msg,
}; };
} }
} }
+17
View File
@@ -9,10 +9,19 @@ export type AudioQuality = 'voice' | 'hifi';
export interface AudioSettings { export interface AudioSettings {
quality: AudioQuality; quality: AudioQuality;
// Preferred input deviceId from enumerateDevices. null = use browser default
// (whatever the OS points at). Persisted across sessions, so "grandma's
// mic is default" stays even after browser picks the wrong device.
inputDeviceId: string | null;
// Preferred output (speaker/headphone) deviceId. null = system default.
// Applied to every <audio> element we attach via HTMLMediaElement.setSinkId.
outputDeviceId: string | null;
} }
const DEFAULTS: AudioSettings = { const DEFAULTS: AudioSettings = {
quality: 'voice', quality: 'voice',
inputDeviceId: null,
outputDeviceId: null,
}; };
export interface AudioQualityParams { export interface AudioQualityParams {
@@ -73,6 +82,14 @@ function read(): AudioSettings {
const parsed = JSON.parse(raw) as Partial<AudioSettings>; const parsed = JSON.parse(raw) as Partial<AudioSettings>;
cached = { cached = {
quality: isQuality(parsed.quality) ? parsed.quality : DEFAULTS.quality, quality: isQuality(parsed.quality) ? parsed.quality : DEFAULTS.quality,
inputDeviceId:
typeof parsed.inputDeviceId === 'string' && parsed.inputDeviceId.length > 0
? parsed.inputDeviceId
: DEFAULTS.inputDeviceId,
outputDeviceId:
typeof parsed.outputDeviceId === 'string' && parsed.outputDeviceId.length > 0
? parsed.outputDeviceId
: DEFAULTS.outputDeviceId,
}; };
return cached; return cached;
} catch { } catch {
+77
View File
@@ -0,0 +1,77 @@
import { supabase } from './supabase';
const BUCKET = 'profile-avatars';
const MAX_DIM = 512;
const QUALITY = 0.85;
// Resizes the source image to a centred-cropped square ≤ MAX_DIM and
// re-encodes as WebP. Falls back to JPEG if WebP isn't supported (rare).
async function resizeToSquare(file: File): Promise<Blob> {
const url = URL.createObjectURL(file);
try {
const img = await new Promise<HTMLImageElement>((resolve, reject) => {
const i = new Image();
i.onload = () => resolve(i);
i.onerror = () => reject(new Error('image load failed'));
i.src = url;
});
const minSide = Math.min(img.naturalWidth, img.naturalHeight);
const sx = (img.naturalWidth - minSide) / 2;
const sy = (img.naturalHeight - minSide) / 2;
const target = Math.min(MAX_DIM, minSide);
const canvas = document.createElement('canvas');
canvas.width = target;
canvas.height = target;
const ctx = canvas.getContext('2d');
if (!ctx) throw new Error('canvas context unavailable');
ctx.drawImage(img, sx, sy, minSide, minSide, 0, 0, target, target);
const blob = await new Promise<Blob | null>((resolve) =>
canvas.toBlob(resolve, 'image/webp', QUALITY),
);
if (blob) return blob;
const jpeg = await new Promise<Blob | null>((resolve) =>
canvas.toBlob(resolve, 'image/jpeg', QUALITY),
);
if (!jpeg) throw new Error('canvas toBlob returned null');
return jpeg;
} finally {
URL.revokeObjectURL(url);
}
}
export async function uploadAvatar(userId: string, file: File): Promise<string> {
if (!file.type.startsWith('image/')) {
throw new Error('only image files are accepted');
}
const blob = await resizeToSquare(file);
const ext = blob.type === 'image/webp' ? 'webp' : 'jpg';
// Random filename so old uploads don't get overwritten before we update
// the profile row — Supabase Storage CDN caches by URL, so a fresh path
// also forces clients to fetch the new image.
const name =
userId + '/' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 8) + '.' + ext;
const { error: upErr } = await supabase.storage.from(BUCKET).upload(name, blob, {
contentType: blob.type,
cacheControl: '604800',
upsert: false,
});
if (upErr) throw upErr;
const { data: pub } = supabase.storage.from(BUCKET).getPublicUrl(name);
return pub.publicUrl;
}
export async function deleteAvatarObject(publicUrl: string): Promise<void> {
// Public URLs look like
// https://<host>/storage/v1/object/public/profile-avatars/<path>
// Extract <path> and remove.
const marker = '/object/public/' + BUCKET + '/';
const idx = publicUrl.indexOf(marker);
if (idx === -1) return;
const path = publicUrl.slice(idx + marker.length);
const { error } = await supabase.storage.from(BUCKET).remove([path]);
if (error) throw error;
}
+7 -2
View File
@@ -24,19 +24,24 @@ function rawFrom(table: string) {
return (supabase as unknown as { from: (t: string) => any }).from(table); return (supabase as unknown as { from: (t: string) => any }).from(table);
} }
// Module-level flag — gap-fill runs once per (user, device) combo per
// process lifetime. Page reloads / route changes don't re-trigger it.
const backfilledKey = new Set<string>();
export function startConversationKeySync( export function startConversationKeySync(
ownUserId: string, ownUserId: string,
ownDeviceId: string, ownDeviceId: string,
): () => void { ): () => void {
let cancelled = false; let cancelled = false;
let priv: Uint8Array | null = null; let priv: Uint8Array | null = null;
const dedupeKey = ownUserId + ':' + ownDeviceId;
void loadDevicePrivateKey(devLocalSecretStore, ownUserId, ownDeviceId).then(async (pk) => { void loadDevicePrivateKey(devLocalSecretStore, ownUserId, ownDeviceId).then(async (pk) => {
if (cancelled) return; if (cancelled) return;
priv = pk; priv = pk;
if (!priv) return; if (!priv) return;
// Run a full backfill once we have the private key — covers devices that if (backfilledKey.has(dedupeKey)) return;
// registered while we were offline. backfilledKey.add(dedupeKey);
await syncAllExistingGaps({ myUserId: ownUserId, myDeviceId: ownDeviceId, priv }); await syncAllExistingGaps({ myUserId: ownUserId, myDeviceId: ownDeviceId, priv });
}); });
+1 -1
View File
@@ -1,5 +1,5 @@
import type { CryptoBackend } from '@chat-app/shared/crypto'; import type { CryptoBackend } from '@chat-app/shared/crypto';
import _sodium from 'libsodium-wrappers'; import _sodium from 'libsodium-wrappers-sumo';
// Build the libsodium-backed CryptoBackend. Awaits the WASM ready-gate once, // Build the libsodium-backed CryptoBackend. Awaits the WASM ready-gate once,
// then returns a synchronous implementation of the CryptoBackend contract. // then returns a synchronous implementation of the CryptoBackend contract.
+1 -1
View File
@@ -25,7 +25,7 @@ export function readLocalDeviceId(userId: string): string | null {
return window.localStorage.getItem(deviceIdStorageKey(userId)); return window.localStorage.getItem(deviceIdStorageKey(userId));
} }
function writeLocalDeviceId(userId: string, deviceId: string): void { export function writeLocalDeviceId(userId: string, deviceId: string): void {
window.localStorage.setItem(deviceIdStorageKey(userId), deviceId); window.localStorage.setItem(deviceIdStorageKey(userId), deviceId);
} }
+50 -1
View File
@@ -1,5 +1,5 @@
import { getCryptoBackend } from '@chat-app/shared/crypto'; import { getCryptoBackend } from '@chat-app/shared/crypto';
import sodium from 'libsodium-wrappers'; import sodium from 'libsodium-wrappers-sumo';
// Encrypts/decrypts the device private key with a user-provided passphrase // Encrypts/decrypts the device private key with a user-provided passphrase
// so the backup string can be safely written down or stored in a password // so the backup string can be safely written down or stored in a password
@@ -91,3 +91,52 @@ export async function importDeviceKey(
s.memzero(key); s.memzero(key);
} }
} }
// Full-device backup. Wraps userId + deviceId + privateKey in a JSON payload
// before encrypting, so a restore flow can re-seed localStorage + vault + server
// device row without requiring the user to remember IDs.
export interface DeviceBackupPayload {
v: 2;
userId: string;
deviceId: string;
privateKeyB64: string;
}
export async function exportDeviceBackup(
params: {
userId: string;
deviceId: string;
privateKey: Uint8Array;
passphrase: string;
},
): Promise<string> {
const payload: DeviceBackupPayload = {
v: 2,
userId: params.userId,
deviceId: params.deviceId,
privateKeyB64: b64url(params.privateKey),
};
const bytes = new TextEncoder().encode(JSON.stringify(payload));
return exportDeviceKey(bytes, params.passphrase);
}
export async function importDeviceBackup(
backup: string,
passphrase: string,
): Promise<DeviceBackupPayload> {
const plain = await importDeviceKey(backup, passphrase);
const text = new TextDecoder().decode(plain);
try {
const obj = JSON.parse(text) as DeviceBackupPayload;
if (obj && obj.v === 2 && obj.userId && obj.deviceId && obj.privateKeyB64) {
return obj;
}
} catch {
/* fall through */
}
throw new Error('Backup format not supported — v2 expected');
}
export function decodePrivateKeyFromBackup(payload: DeviceBackupPayload): Uint8Array {
return unb64url(payload.privateKeyB64);
}
+27 -2
View File
@@ -7,10 +7,31 @@ import {
import { isTauriRuntime } from './globalShortcut'; import { isTauriRuntime } from './globalShortcut';
// Tracks whether permission has already been requested this session so we // Tracks whether permission has already been requested this session so we
// don't spam the OS prompt. Actual permission state lives in the OS. // don't spam the OS prompt. Actual permission state lives in the OS, but we
// also persist a "we've asked" marker in localStorage so reloads don't
// re-request (OS would block anyway after denial, but calling it every reload
// triggers noisy plugin warnings on some platforms).
let permissionChecked = false; let permissionChecked = false;
let permissionGranted = false; let permissionGranted = false;
const ASKED_KEY = 'chatapp.notif.asked';
function readAskedMarker(): boolean {
try {
return window.localStorage.getItem(ASKED_KEY) === '1';
} catch {
return false;
}
}
function writeAskedMarker(): void {
try {
window.localStorage.setItem(ASKED_KEY, '1');
} catch {
/* quota / private mode */
}
}
export async function ensureNotificationPermission(): Promise<boolean> { export async function ensureNotificationPermission(): Promise<boolean> {
if (permissionChecked) return permissionGranted; if (permissionChecked) return permissionGranted;
permissionChecked = true; permissionChecked = true;
@@ -21,9 +42,13 @@ export async function ensureNotificationPermission(): Promise<boolean> {
} }
try { try {
let granted = await isPermissionGranted(); let granted = await isPermissionGranted();
if (!granted) { if (!granted && !readAskedMarker()) {
// First-install: prompt the user once. After this we remember via the
// marker and never re-prompt — the user can re-enable later via OS
// system settings if they change their mind.
const result = await requestPermission(); const result = await requestPermission();
granted = result === 'granted'; granted = result === 'granted';
writeAskedMarker();
} }
permissionGranted = granted; permissionGranted = granted;
} catch (err: unknown) { } catch (err: unknown) {
+9 -4
View File
@@ -1,7 +1,9 @@
import type { SecretStore } from '@chat-app/shared/auth'; import type { SecretStore } from '@chat-app/shared/auth';
import { exists, mkdir, readFile, rename, writeFile } from '@tauri-apps/plugin-fs'; import { exists, mkdir, readFile, rename, writeFile } from '@tauri-apps/plugin-fs';
import { appLocalDataDir } from '@tauri-apps/api/path'; import { appLocalDataDir } from '@tauri-apps/api/path';
import sodium from 'libsodium-wrappers'; // sumo variant ships crypto_pwhash (Argon2id). Standard `libsodium-wrappers`
// is the compact build without Argon2 — vault KDF would error otherwise.
import sodium from 'libsodium-wrappers-sumo';
// Encrypted single-file SecretStore for Tauri. Replaces the flaky // Encrypted single-file SecretStore for Tauri. Replaces the flaky
// tauri-plugin-stronghold implementation. // tauri-plugin-stronghold implementation.
@@ -93,10 +95,13 @@ async function loadOrCreateVault(userId: string): Promise<VaultState> {
const path = joinPath(dir, fileName); const path = joinPath(dir, fileName);
const tmpPath = path + '.tmp'; const tmpPath = path + '.tmp';
try { // First-run: AppLocalData dir may not exist yet. `mkdir(recursive)` is
// idempotent on macOS/Linux, but we need to surface genuine permission
// errors (silent catch masked a previous bug where the dir was never
// created and every subsequent writeFile failed with ENOENT).
const dirExists = await exists(dir).catch(() => false);
if (!dirExists) {
await mkdir(dir, { recursive: true }); await mkdir(dir, { recursive: true });
} catch {
/* parent likely already exists */
} }
const fileExists = await exists(path).catch(() => false); const fileExists = await exists(path).catch(() => false);
+44
View File
@@ -0,0 +1,44 @@
// Clean-Rail theme: persisted `.dark` class on <html>. Default follows the
// system preference; user-toggle persists to localStorage and wins over it.
export type Theme = 'light' | 'dark';
const STORAGE_KEY = 'netralax.theme';
function readStoredTheme(): Theme | null {
try {
const raw = window.localStorage.getItem(STORAGE_KEY);
if (raw === 'light' || raw === 'dark') return raw;
} catch {
/* localStorage unavailable (private mode / sandbox) */
}
return null;
}
function writeStoredTheme(theme: Theme): void {
try {
window.localStorage.setItem(STORAGE_KEY, theme);
} catch {
/* localStorage unavailable */
}
}
function systemPrefersDark(): boolean {
return typeof window !== 'undefined'
&& typeof window.matchMedia === 'function'
&& window.matchMedia('(prefers-color-scheme: dark)').matches;
}
export function getInitialTheme(): Theme {
return readStoredTheme() ?? (systemPrefersDark() ? 'dark' : 'light');
}
export function applyTheme(theme: Theme): void {
const root = document.documentElement;
root.classList.toggle('dark', theme === 'dark');
}
export function setThemePersisted(theme: Theme): void {
writeStoredTheme(theme);
applyTheme(theme);
}
+35
View File
@@ -0,0 +1,35 @@
import type { Participant, Room } from 'livekit-client';
import { RoomEvent } from 'livekit-client';
import { useEffect, useState } from 'react';
// Subscribe to LiveKit ActiveSpeakersChanged to drive the speaking-ring pulse
// on participant tiles. Returns the set of currently speaking identities
// (includes local participant when they're active).
export function useActiveSpeakers(room: Room | null): Set<string> {
const [ids, setIds] = useState<Set<string>>(() => new Set());
useEffect(() => {
if (!room) {
setIds(new Set());
return;
}
const update = (speakers: Participant[]) => {
const next = new Set<string>();
for (const s of speakers) {
if (s.identity) next.add(s.identity);
}
setIds(next);
};
// Seed from current state.
update(room.activeSpeakers ?? []);
room.on(RoomEvent.ActiveSpeakersChanged, update);
return () => {
room.off(RoomEvent.ActiveSpeakersChanged, update);
};
}, [room]);
return ids;
}
-94
View File
@@ -1,94 +0,0 @@
import type { RealtimeChannel } from '@supabase/supabase-js';
import { useEffect, useState } from 'react';
import { supabase } from './supabase';
// Observes the `call-presence:<conversationId>` channel for every conversation
// the user is a member of and returns the first one (if any) that currently
// has peers other than the viewer in the call. Enables a "call is live —
// rejoin" affordance in the sidebar for conversations the viewer never
// joined, mirroring Discord's active-voice indicator.
//
// Uses polling on each channel's `presenceState()` to side-step Supabase's
// topic-based channel dedupe (see useCallPresence.ts).
export function useAnyActiveCall(
conversationIds: readonly string[],
myId: string | null,
): { conversationId: string; userIds: string[] } | null {
const [byConv, setByConv] = useState<Record<string, string[]>>({});
const key = conversationIds.join(',');
useEffect(() => {
if (conversationIds.length === 0) {
setByConv({});
return;
}
const tracked: Array<{ id: string; ch: RealtimeChannel; owns: boolean }> = [];
for (const id of conversationIds) {
const ch = supabase.channel('call-presence:' + id, {
config: {
presence: {
key: 'obs-' + Math.random().toString(36).slice(2, 8),
enabled: true,
},
},
});
const owns = ch.state === 'closed';
if (owns) void ch.subscribe();
tracked.push({ id, ch, owns });
}
const resync = () => {
setByConv((prev) => {
const next: Record<string, string[]> = {};
let changed = false;
for (const { id, ch } of tracked) {
const presState = ch.presenceState() as Record<
string,
Array<Record<string, unknown>>
>;
const ids = new Set<string>();
for (const list of Object.values(presState)) {
for (const e of list) {
const uid = e?.userId;
if (typeof uid === 'string') ids.add(uid);
}
}
const arr = Array.from(ids).sort();
next[id] = arr;
const prevArr = prev[id] ?? [];
if (prevArr.length !== arr.length || !arr.every((v, i) => v === prevArr[i])) {
changed = true;
}
}
// Also pick up removed conv ids.
if (!changed && Object.keys(prev).length !== Object.keys(next).length) {
changed = true;
}
return changed ? next : prev;
});
};
resync();
const pollId = window.setInterval(resync, 1500);
return () => {
window.clearInterval(pollId);
for (const { ch, owns } of tracked) {
if (owns) void supabase.removeChannel(ch);
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [key]);
for (const id of conversationIds) {
const users = byConv[id] ?? [];
const others = myId ? users.filter((u) => u !== myId) : users;
if (others.length > 0) {
return { conversationId: id, userIds: others };
}
}
return null;
}
+32 -21
View File
@@ -6,11 +6,15 @@ import { supabase } from './supabase';
// the set of userIds currently in that call. Independent of whether the // the set of userIds currently in that call. Independent of whether the
// viewer is in the room — used to show "Active call · Join" affordances. // viewer is in the room — used to show "Active call · Join" affordances.
// //
// Supabase realtime 2.103+ dedupes channels by topic: calling // Why presence-callbacks + no-removeChannel:
// `supabase.channel(topic)` returns an existing channel if one already exists. // - Supabase realtime 2.103+ dedupes channels by topic. CallContext owns
// That means an observer can't safely register `.on('presence', ...)` because // the same channel during a live call to track its own presence.
// the tracker (CallContext) may have already subscribed it. We side-step this // - If this hook removed the channel on unmount (e.g. when ConversationHeader
// by polling `presenceState()` on the (shared or fresh) channel. // hides during an active call), the live tracking connection dies and the
// banner never shows the rejoin option afterwards.
// - Binding our own presence callbacks (sync/join/leave) ensures the local
// presence state is updated even when CallContext also listens on the same
// channel — multiple callbacks can co-exist.
export function useCallPresence(conversationId: string | undefined): string[] { export function useCallPresence(conversationId: string | undefined): string[] {
const [activeUserIds, setActiveUserIds] = useState<string[]>([]); const [activeUserIds, setActiveUserIds] = useState<string[]>([]);
@@ -24,23 +28,13 @@ export function useCallPresence(conversationId: string | undefined): string[] {
config: { config: {
presence: { presence: {
key: 'observer-' + Math.random().toString(36).slice(2, 8), key: 'observer-' + Math.random().toString(36).slice(2, 8),
// Supabase realtime only sends presence_state/diff events to a // Server only routes presence to channels that opt-in. Without this
// channel that has presence enabled. Without `enabled: true` (and // flag we'd receive zero presence_state/presence_diff messages.
// no `.on('presence', ...)` bindings) the server treats the channel
// as non-presence and `presenceState()` never populates.
enabled: true, enabled: true,
}, },
}, },
}); });
// If Supabase returned a fresh (closed) channel, we own it and must
// subscribe/remove it. If it returned an already-subscribed channel
// (tracker owns it), we just read state.
const ownsChannel = channel.state === 'closed';
if (ownsChannel) {
void channel.subscribe();
}
const resync = () => { const resync = () => {
const state = channel.presenceState() as Record<string, Array<Record<string, unknown>>>; const state = channel.presenceState() as Record<string, Array<Record<string, unknown>>>;
const ids = new Set<string>(); const ids = new Set<string>();
@@ -57,14 +51,31 @@ export function useCallPresence(conversationId: string | undefined): string[] {
}); });
}; };
// Supabase realtime forbids `.on()` after `.subscribe()`. So we only bind
// callbacks when we own the subscribe (channel was 'closed'). For deduped
// shared channels, the polling fallback below covers state changes.
if (channel.state === 'closed') {
channel
.on('presence', { event: 'sync' }, resync)
.on('presence', { event: 'join' }, resync)
.on('presence', { event: 'leave' }, resync);
void channel.subscribe();
}
// Initial poll covers the case where the channel is already 'joined' (we
// dedupe'd onto an existing subscription) and won't fire a fresh sync.
resync(); resync();
const pollId = window.setInterval(resync, 1500); // Belt-and-suspenders: a slow poll catches any drift between callback and
// server state (e.g. if a presence event was dropped during reconnect).
const pollId = window.setInterval(resync, 3000);
return () => { return () => {
window.clearInterval(pollId); window.clearInterval(pollId);
if (ownsChannel) { // Don't removeChannel — the channel is shared with CallContext (and any
void supabase.removeChannel(channel); // sibling observers) via Supabase's topic dedupe. Removing it would
} // tear down a live call's presence tracker. The channel naturally
// outlives the hook; leaks are bounded by the small number of
// conversations a user holds open in a session.
}; };
}, [conversationId]); }, [conversationId]);
@@ -51,7 +51,7 @@ function rowToMessage(row: Record<string, unknown>): MessageWithCipher {
} }
export function useConversationMessages({ conversationId, userId, deviceId }: Args): State & { export function useConversationMessages({ conversationId, userId, deviceId }: Args): State & {
send: (text: string, images?: File[]) => Promise<void>; send: (text: string, images?: File[], replyToId?: string | null) => Promise<void>;
refresh: () => Promise<void>; refresh: () => Promise<void>;
} { } {
const [state, setState] = useState<State>({ messages: [], loading: true, error: null }); const [state, setState] = useState<State>({ messages: [], loading: true, error: null });
@@ -192,18 +192,71 @@ export function useConversationMessages({ conversationId, userId, deviceId }: Ar
return { ...prev, messages: next }; return { ...prev, messages: next };
}); });
if (partial.editedAt && !partial.deletedAt) { if (partial.editedAt && !partial.deletedAt) {
const [decrypted] = await decryptBatch([partial]); // Realtime bytea encoding varies (base64 vs hex, even null for
// unchanged columns on some configs). Refetch via REST to get the
// canonical `\x…` hex then decrypt — same pattern as handleInsert.
if (!conversationId || !deviceId) return;
let decrypted: DecryptedMessage | null = null;
for (let attempt = 0; attempt < 6; attempt++) {
const { data, error } = await supabase
.from('messages')
.select(
'id, conversation_id, sender_id, sender_device_id, reply_to_id, edited_at, deleted_at, created_at, ciphertext, nonce, key_version',
)
.eq('id', partial.id)
.maybeSingle();
if (error) {
console.warn('handleUpdate refetch failed', error);
return;
}
if (!data) {
await new Promise((r) => window.setTimeout(r, 120 * (attempt + 1)));
continue;
}
const r = data as unknown as {
id: string;
conversation_id: string;
sender_id: string;
sender_device_id: string | null;
reply_to_id: string | null;
edited_at: string | null;
deleted_at: string | null;
created_at: string;
ciphertext: string;
nonce: string;
key_version: number;
};
const msg: MessageWithCipher = {
id: r.id,
conversationId: r.conversation_id,
senderId: r.sender_id,
senderDeviceId: r.sender_device_id,
replyToId: r.reply_to_id,
editedAt: r.edited_at,
deletedAt: r.deleted_at,
createdAt: r.created_at,
ciphertext: pgBytesToBytes(String(r.ciphertext)),
nonce: pgBytesToBytes(String(r.nonce)),
keyVersion: r.key_version,
};
const [d] = await decryptBatch([msg]);
if (d) {
decrypted = d;
if (d.plaintext !== null) break;
}
await new Promise((r) => window.setTimeout(r, 200 * (attempt + 1)));
}
if (!decrypted) return; if (!decrypted) return;
setState((prev) => { setState((prev) => {
const idx = prev.messages.findIndex((m) => m.id === decrypted.id); const idx = prev.messages.findIndex((m) => m.id === decrypted!.id);
if (idx === -1) return prev; if (idx === -1) return prev;
const next = [...prev.messages]; const next = [...prev.messages];
next[idx] = decrypted; next[idx] = decrypted!;
return { ...prev, messages: next }; return { ...prev, messages: next };
}); });
} }
}, },
[decryptBatch], [conversationId, deviceId, decryptBatch],
); );
const handleDelete = useCallback((row: Record<string, unknown>) => { const handleDelete = useCallback((row: Record<string, unknown>) => {
@@ -256,13 +309,32 @@ export function useConversationMessages({ conversationId, userId, deviceId }: Ar
) )
.subscribe(); .subscribe();
// Refresh + reconnect on wake from background throttle (mostly Windows
// WebView2). Without this, messages inserted while the window is
// minimised never arrive until the user explicitly reloads.
const onAwake = () => {
if (document.visibilityState !== 'visible') return;
void refresh();
try {
channel.subscribe();
} catch {
/* already live */
}
};
document.addEventListener('visibilitychange', onAwake);
window.addEventListener('focus', onAwake);
window.addEventListener('online', onAwake);
return () => { return () => {
document.removeEventListener('visibilitychange', onAwake);
window.removeEventListener('focus', onAwake);
window.removeEventListener('online', onAwake);
void supabase.removeChannel(channel); void supabase.removeChannel(channel);
}; };
}, [conversationId, userId, deviceId, refresh, handleInsert, handleUpdate, handleDelete]); }, [conversationId, userId, deviceId, refresh, handleInsert, handleUpdate, handleDelete]);
const send = useCallback( const send = useCallback(
async (text: string, images: File[] = []) => { async (text: string, images: File[] = [], replyToId: string | null = null) => {
const trimmed = text.trim(); const trimmed = text.trim();
if ((!trimmed && images.length === 0) || !conversationId || !userId || !deviceId) return; if ((!trimmed && images.length === 0) || !conversationId || !userId || !deviceId) return;
const priv = privateKeyRef.current; const priv = privateKeyRef.current;
@@ -299,6 +371,7 @@ export function useConversationMessages({ conversationId, userId, deviceId }: Ar
senderDeviceId: deviceId, senderDeviceId: deviceId,
senderPrivateKey: priv, senderPrivateKey: priv,
...(handles.length > 0 ? { attachmentHandles: handles } : {}), ...(handles.length > 0 ? { attachmentHandles: handles } : {}),
...(replyToId ? { replyToId } : {}),
}); });
// 3. Optimistic insert — we already have the plaintext in hand and the // 3. Optimistic insert — we already have the plaintext in hand and the
+17
View File
@@ -44,7 +44,24 @@ export function useFriendships(userId: string | undefined): FriendshipsState & {
}) })
.subscribe(); .subscribe();
// Windows WebView2 throttles background sockets — refresh on wake.
const onAwake = () => {
if (document.visibilityState !== 'visible') return;
void refresh();
try {
channel.subscribe();
} catch {
/* already live */
}
};
document.addEventListener('visibilitychange', onAwake);
window.addEventListener('focus', onAwake);
window.addEventListener('online', onAwake);
return () => { return () => {
document.removeEventListener('visibilitychange', onAwake);
window.removeEventListener('focus', onAwake);
window.removeEventListener('online', onAwake);
void supabase.removeChannel(channel); void supabase.removeChannel(channel);
}; };
}, [userId, refresh]); }, [userId, refresh]);
+40 -38
View File
@@ -16,6 +16,7 @@ import { extractErrorCode } from '@chat-app/shared/i18n';
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Avatar } from '../components/Avatar';
import { import {
AlertIcon, AlertIcon,
CopyIcon, CopyIcon,
@@ -64,9 +65,10 @@ export function AdminPage() {
}, [refresh]); }, [refresh]);
return ( return (
<div className="mx-auto flex max-w-4xl flex-col gap-6 px-6 py-8"> <div className="min-h-full bg-surface-3 text-fg">
<div className="mx-auto flex max-w-4xl flex-col gap-6 px-6 py-8">
<header> <header>
<h1 className="font-display text-2xl font-semibold tracking-tight text-white"> <h1 className="font-display text-2xl font-semibold tracking-tight text-fg">
{t('app:admin.title')} {t('app:admin.title')}
</h1> </h1>
</header> </header>
@@ -74,16 +76,16 @@ export function AdminPage() {
{error && ( {error && (
<div <div
role="alert" role="alert"
className="flex items-start gap-3 rounded-lg border border-rose-500/20 bg-rose-500/10 p-3 text-sm text-rose-100" className="flex items-start gap-3 rounded-lg border border-rose-500/30 bg-rose-500/10 p-3 text-sm text-rose-700 dark:text-rose-100"
> >
<AlertIcon className="mt-0.5 h-5 w-5 shrink-0 text-rose-400" /> <AlertIcon className="mt-0.5 h-5 w-5 shrink-0 text-rose-500 dark:text-rose-400" />
<p className="min-w-0 flex-1 break-words">{error}</p> <p className="min-w-0 flex-1 break-words">{error}</p>
</div> </div>
)} )}
{loading ? ( {loading ? (
<div className="flex items-center gap-2 text-sm text-neutral-500"> <div className="flex items-center gap-2 text-sm text-fg-muted">
<SpinnerIcon className="h-4 w-4 text-brand-400" /> <SpinnerIcon className="h-4 w-4 text-accent" />
</div> </div>
) : ( ) : (
<> <>
@@ -92,15 +94,16 @@ export function AdminPage() {
<UsersSection users={users} onRefresh={refresh} /> <UsersSection users={users} onRefresh={refresh} />
</> </>
)} )}
</div>
</div> </div>
); );
} }
function Section({ title, children, action }: { title: string; children: React.ReactNode; action?: React.ReactNode }) { function Section({ title, children, action }: { title: string; children: React.ReactNode; action?: React.ReactNode }) {
return ( return (
<section className="rounded-2xl border border-white/10 bg-ink-900/60 p-5 backdrop-blur-xl"> <section className="rounded-2xl border border-line bg-surface-2 p-5">
<header className="mb-4 flex items-center justify-between"> <header className="mb-4 flex items-center justify-between">
<h2 className="text-xs font-semibold uppercase tracking-wide text-neutral-400">{title}</h2> <h2 className="text-xs font-semibold uppercase tracking-[0.1em] text-fg-muted">{title}</h2>
{action} {action}
</header> </header>
{children} {children}
@@ -199,7 +202,7 @@ function InvitesSection({ invites, onRefresh }: { invites: InviteRecord[]; onRef
type="button" type="button"
onClick={() => void handleCreate()} onClick={() => void handleCreate()}
disabled={busy} disabled={busy}
className="inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-brand-500/90 px-3 py-1.5 text-xs font-semibold text-white transition hover:bg-brand-400 disabled:opacity-60" className="inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-xs font-semibold text-accent-fg transition hover:brightness-110 disabled:opacity-60"
> >
{busy ? <SpinnerIcon className="h-3.5 w-3.5" /> : <PlusIcon className="h-3.5 w-3.5" />} {busy ? <SpinnerIcon className="h-3.5 w-3.5" /> : <PlusIcon className="h-3.5 w-3.5" />}
<span>{t('app:admin.invites_create')}</span> <span>{t('app:admin.invites_create')}</span>
@@ -207,11 +210,11 @@ function InvitesSection({ invites, onRefresh }: { invites: InviteRecord[]; onRef
} }
> >
{invites.length === 0 ? ( {invites.length === 0 ? (
<p className="text-sm text-neutral-500">{t('app:admin.invites_empty')}</p> <p className="text-sm text-fg-muted">{t('app:admin.invites_empty')}</p>
) : ( ) : (
<div className="overflow-x-auto"> <div className="overflow-x-auto">
<table className="w-full text-left text-sm"> <table className="w-full text-left text-sm">
<thead className="text-[10px] uppercase tracking-wide text-neutral-500"> <thead className="text-[10px] uppercase tracking-[0.1em] text-fg-muted">
<tr> <tr>
<th className="py-2 pr-3">{t('app:admin.invite_col_code')}</th> <th className="py-2 pr-3">{t('app:admin.invite_col_code')}</th>
<th className="py-2 pr-3">{t('app:admin.invite_col_uses')}</th> <th className="py-2 pr-3">{t('app:admin.invite_col_uses')}</th>
@@ -220,7 +223,7 @@ function InvitesSection({ invites, onRefresh }: { invites: InviteRecord[]; onRef
<th className="py-2" /> <th className="py-2" />
</tr> </tr>
</thead> </thead>
<tbody className="divide-y divide-white/5"> <tbody className="divide-y divide-line">
{invites.map((inv) => { {invites.map((inv) => {
const expired = inv.expiresAt ? new Date(inv.expiresAt) < new Date() : false; const expired = inv.expiresAt ? new Date(inv.expiresAt) < new Date() : false;
const status = inv.disabled const status = inv.disabled
@@ -229,10 +232,10 @@ function InvitesSection({ invites, onRefresh }: { invites: InviteRecord[]; onRef
? t('app:admin.invite_status_expired') ? t('app:admin.invite_status_expired')
: t('app:admin.invite_status_active'); : t('app:admin.invite_status_active');
const statusColor = inv.disabled const statusColor = inv.disabled
? 'text-rose-300' ? 'text-rose-600 dark:text-rose-300'
: expired : expired
? 'text-amber-300' ? 'text-amber-600 dark:text-amber-300'
: 'text-emerald-300'; : 'text-emerald-600 dark:text-emerald-300';
const usesText = inv.usesLimit const usesText = inv.usesLimit
? inv.usesCount + '/' + inv.usesLimit ? inv.usesCount + '/' + inv.usesLimit
: inv.usesCount + '/∞'; : inv.usesCount + '/∞';
@@ -241,9 +244,9 @@ function InvitesSection({ invites, onRefresh }: { invites: InviteRecord[]; onRef
: t('app:admin.invite_expires_never'); : t('app:admin.invite_expires_never');
return ( return (
<tr key={inv.code} className="py-2"> <tr key={inv.code} className="py-2">
<td className="py-2 pr-3 font-mono text-xs">{inv.code}</td> <td className="py-2 pr-3 font-mono text-xs text-fg">{inv.code}</td>
<td className="py-2 pr-3 text-xs text-neutral-400">{usesText}</td> <td className="py-2 pr-3 text-xs text-fg-muted">{usesText}</td>
<td className="py-2 pr-3 text-xs text-neutral-400">{expiresText}</td> <td className="py-2 pr-3 text-xs text-fg-muted">{expiresText}</td>
<td className={'py-2 pr-3 text-xs font-medium ' + statusColor}>{status}</td> <td className={'py-2 pr-3 text-xs font-medium ' + statusColor}>{status}</td>
<td className="py-2 text-right"> <td className="py-2 text-right">
<div className="inline-flex gap-1"> <div className="inline-flex gap-1">
@@ -260,7 +263,7 @@ function InvitesSection({ invites, onRefresh }: { invites: InviteRecord[]; onRef
<button <button
type="button" type="button"
onClick={() => void handleToggle(inv.code, inv.disabled)} onClick={() => void handleToggle(inv.code, inv.disabled)}
className="rounded-md border border-white/10 bg-white/5 px-2 py-1 text-[11px] font-medium text-neutral-300 transition hover:bg-white/10" className="rounded-md border border-line bg-surface-3 px-2 py-1 text-[11px] font-medium text-fg transition hover:brightness-95"
> >
{inv.disabled ? t('app:admin.invites_enable') : t('app:admin.invites_disable')} {inv.disabled ? t('app:admin.invites_enable') : t('app:admin.invites_disable')}
</button> </button>
@@ -301,20 +304,19 @@ function UsersSection({ users, onRefresh }: { users: AdminProfileRow[]; onRefres
return ( return (
<Section title={t('app:admin.users_title')}> <Section title={t('app:admin.users_title')}>
{users.length === 0 ? ( {users.length === 0 ? (
<p className="text-sm text-neutral-500">{t('app:admin.users_empty')}</p> <p className="text-sm text-fg-muted">{t('app:admin.users_empty')}</p>
) : ( ) : (
<ul className="divide-y divide-white/5"> <ul className="divide-y divide-line">
{users.map((u) => { {users.map((u) => {
const letter =
(u.displayName ?? u.username ?? '?').trim().charAt(0).toUpperCase() || '?';
return ( return (
<li key={u.userId} className="flex items-center gap-3 py-3"> <li key={u.userId} className="flex items-center gap-3 py-3">
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-brand-500/30 text-sm font-semibold text-white ring-1 ring-brand-400/30"> <Avatar
{letter} displayName={u.displayName ?? u.username}
</div> className="h-9 w-9 text-sm"
/>
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="truncate text-sm font-semibold text-white">{u.displayName}</p> <p className="truncate text-sm font-semibold text-fg">{u.displayName}</p>
<p className="truncate text-xs text-neutral-500">@{u.username}</p> <p className="truncate text-xs text-fg-muted">@{u.username}</p>
</div> </div>
<div className="flex gap-2"> <div className="flex gap-2">
<FlagChip <FlagChip
@@ -361,8 +363,8 @@ function Toggle({
return ( return (
<label className="flex cursor-pointer items-start justify-between gap-4"> <label className="flex cursor-pointer items-start justify-between gap-4">
<span className="min-w-0 flex-1"> <span className="min-w-0 flex-1">
<span className="block text-sm text-neutral-200">{label}</span> <span className="block text-sm text-fg">{label}</span>
{hint && <span className="mt-1 block text-xs text-neutral-500">{hint}</span>} {hint && <span className="mt-1 block text-xs text-fg-muted">{hint}</span>}
</span> </span>
<span className="relative mt-0.5 inline-flex h-6 w-11 shrink-0"> <span className="relative mt-0.5 inline-flex h-6 w-11 shrink-0">
<input <input
@@ -372,8 +374,8 @@ function Toggle({
onChange={(e) => onChange(e.target.checked)} onChange={(e) => onChange(e.target.checked)}
className="peer sr-only" className="peer sr-only"
/> />
<span className="inline-block h-6 w-11 rounded-full bg-neutral-700 transition peer-checked:bg-brand-500/70 peer-disabled:opacity-50" /> <span className="inline-block h-6 w-11 rounded-full bg-surface transition peer-checked:bg-accent peer-disabled:opacity-50" />
<span className="absolute left-0.5 top-0.5 h-5 w-5 rounded-full bg-white transition peer-checked:translate-x-5" /> <span className="absolute left-0.5 top-0.5 h-5 w-5 rounded-full bg-white shadow transition peer-checked:translate-x-5" />
</span> </span>
</label> </label>
); );
@@ -399,8 +401,8 @@ function IconButton({
className={ className={
'flex h-7 w-7 cursor-pointer items-center justify-center rounded-md border transition focus:outline-none focus-visible:ring-2 ' + 'flex h-7 w-7 cursor-pointer items-center justify-center rounded-md border transition focus:outline-none focus-visible:ring-2 ' +
(tone === 'danger' (tone === 'danger'
? 'border-rose-500/30 bg-rose-500/10 text-rose-200 hover:bg-rose-500/20 focus-visible:ring-rose-400/40' ? 'border-rose-500/40 bg-rose-500/10 text-rose-600 hover:bg-rose-500/20 focus-visible:ring-rose-400/40 dark:text-rose-300'
: 'border-white/10 bg-white/5 text-neutral-300 hover:bg-white/10 focus-visible:ring-brand-400/40') : 'border-line bg-surface-3 text-fg hover:brightness-95 focus-visible:ring-accent/40')
} }
> >
{children} {children}
@@ -421,15 +423,15 @@ function FlagChip({
}) { }) {
const activeClass = const activeClass =
tone === 'danger' tone === 'danger'
? 'border-rose-400/40 bg-rose-500/20 text-rose-100' ? 'border-rose-500/40 bg-rose-500/20 text-rose-700 dark:text-rose-100'
: 'border-brand-400/40 bg-brand-500/20 text-brand-100'; : 'border-accent/40 bg-accent/20 text-accent';
return ( return (
<button <button
type="button" type="button"
onClick={() => onToggle(!active)} onClick={() => onToggle(!active)}
className={ className={
'cursor-pointer rounded-full border px-2.5 py-0.5 text-[11px] font-medium transition focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 ' + 'cursor-pointer rounded-full border px-2.5 py-0.5 text-[11px] font-medium transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ' +
(active ? activeClass : 'border-white/10 bg-white/5 text-neutral-400 hover:bg-white/10') (active ? activeClass : 'border-line bg-surface-3 text-fg-muted hover:brightness-95')
} }
> >
{label} {label}
+2 -2
View File
@@ -38,7 +38,7 @@ type UiState =
| { kind: 'sent'; email: string } | { kind: 'sent'; email: string }
| { kind: 'error'; message: string }; | { kind: 'error'; message: string };
const USERNAME_PATTERN = /^[a-z0-9_]{3,32}$/; const USERNAME_PATTERN = /^[A-Za-z0-9_]{3,32}$/;
export function AuthPage() { export function AuthPage() {
const { session } = useAuth(); const { session } = useAuth();
@@ -314,7 +314,7 @@ function FormCard({
required required
placeholder={t('auth:fields.username_placeholder')} placeholder={t('auth:fields.username_placeholder')}
value={username} value={username}
onChange={(e) => onUsernameChange(e.target.value.toLowerCase())} onChange={(e) => onUsernameChange(e.target.value)}
pattern={USERNAME_PATTERN.source} pattern={USERNAME_PATTERN.source}
className="w-full rounded-lg border border-white/10 bg-ink-800 py-2.5 pl-10 pr-3 text-sm text-white placeholder-neutral-500 transition focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-500/40" className="w-full rounded-lg border border-white/10 bg-ink-800 py-2.5 pl-10 pr-3 text-sm text-white placeholder-neutral-500 transition focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-500/40"
/> />
+238 -58
View File
@@ -1,11 +1,25 @@
import { acceptDm, type ConversationSummary } from '@chat-app/shared/chat'; import {
acceptDm,
type ConversationSummary,
isConversationMuted,
} from '@chat-app/shared/chat';
import { extractErrorCode } from '@chat-app/shared/i18n'; import { extractErrorCode } from '@chat-app/shared/i18n';
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { NavLink, Outlet, useParams } from 'react-router-dom'; import { NavLink, Outlet, useParams } from 'react-router-dom';
import { ConversationRowMenu } from '../components/ConversationRowMenu';
import { CreateGroupDialog } from '../components/CreateGroupDialog'; import { CreateGroupDialog } from '../components/CreateGroupDialog';
import { ChatBubbleIcon, PlusIcon, SpinnerIcon, UsersIcon } from '../components/icons'; import {
AddUserIcon,
ArchiveIcon,
BellOffIcon,
ChatBubbleIcon,
SearchIcon,
SpinnerIcon,
UsersIcon,
} from '../components/icons';
import { UserBar } from '../components/UserBar';
import { useConversationsContext } from '../context/ConversationsContext'; import { useConversationsContext } from '../context/ConversationsContext';
import { supabase } from '../lib/supabase'; import { supabase } from '../lib/supabase';
@@ -13,6 +27,8 @@ export function ChatsPage() {
const { conversations, loading, error, refresh, unread } = useConversationsContext(); const { conversations, loading, error, refresh, unread } = useConversationsContext();
const { id: activeId } = useParams<{ id: string }>(); const { id: activeId } = useParams<{ id: string }>();
const [createOpen, setCreateOpen] = useState(false); const [createOpen, setCreateOpen] = useState(false);
const [query, setQuery] = useState('');
const [showArchived, setShowArchived] = useState(false);
const sorted = useMemo(() => { const sorted = useMemo(() => {
return [...conversations].sort((a, b) => { return [...conversations].sort((a, b) => {
@@ -22,14 +38,40 @@ export function ChatsPage() {
}); });
}, [conversations]); }, [conversations]);
const queryFiltered = useMemo(() => {
const q = query.trim().toLowerCase();
if (!q) return sorted;
return sorted.filter((c) => {
const title = (c.type === 'dm' ? c.peer?.displayName : c.name) ?? '';
const handle = c.type === 'dm' ? c.peer?.username ?? '' : '';
return title.toLowerCase().includes(q) || handle.toLowerCase().includes(q);
});
}, [sorted, query]);
// Split into active vs archived — the user toggles which bucket shows in the
// main list. Archived conversations with unread messages still surface so
// the user can't accidentally silence an ongoing conversation permanently.
const activeItems = useMemo(
() => queryFiltered.filter((c) => !c.archived),
[queryFiltered],
);
const archivedItems = useMemo(
() => queryFiltered.filter((c) => c.archived),
[queryFiltered],
);
const archivedUnread = archivedItems.reduce((s, c) => s + (unread[c.id] ?? 0), 0);
return ( return (
<div className="flex h-full"> <div className="flex h-full">
<ConversationList <ConversationList
items={sorted} items={showArchived ? archivedItems : activeItems}
loading={loading} loading={loading}
error={error} error={error}
activeId={activeId} activeId={activeId}
unread={unread} unread={unread}
query={query}
onQueryChange={setQuery}
onAccept={async (id) => { onAccept={async (id) => {
try { try {
await acceptDm(supabase, id); await acceptDm(supabase, id);
@@ -40,8 +82,11 @@ export function ChatsPage() {
} }
}} }}
onNewGroup={() => setCreateOpen(true)} onNewGroup={() => setCreateOpen(true)}
showArchived={showArchived}
onToggleArchived={() => setShowArchived((v) => !v)}
archivedUnread={archivedUnread}
/> />
<div className="flex-1 border-l border-white/5"> <div className="flex-1 border-l border-line bg-surface-3">
<Outlet /> <Outlet />
</div> </div>
<CreateGroupDialog open={createOpen} onClose={() => setCreateOpen(false)} /> <CreateGroupDialog open={createOpen} onClose={() => setCreateOpen(false)} />
@@ -49,62 +94,140 @@ export function ChatsPage() {
); );
} }
interface ConversationListProps {
items: ConversationSummary[];
loading: boolean;
error: string | null;
activeId: string | undefined;
unread: Record<string, number>;
query: string;
onQueryChange: (q: string) => void;
onAccept: (id: string) => void;
onNewGroup: () => void;
showArchived: boolean;
onToggleArchived: () => void;
archivedUnread: number;
}
function ConversationList({ function ConversationList({
items, items,
loading, loading,
error, error,
activeId, activeId,
unread, unread,
query,
onQueryChange,
onAccept, onAccept,
onNewGroup, onNewGroup,
}: { showArchived,
items: ConversationSummary[]; onToggleArchived,
loading: boolean; archivedUnread,
error: string | null; }: ConversationListProps) {
activeId: string | undefined;
unread: Record<string, number>;
onAccept: (id: string) => void;
onNewGroup: () => void;
}) {
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
return ( return (
<aside <aside
aria-label="Conversations" aria-label="Conversations"
className="flex h-full w-[320px] shrink-0 flex-col bg-ink-900/40" className="flex h-full w-[320px] shrink-0 flex-col bg-surface-2"
> >
<header className="flex items-center justify-between px-4 pb-3 pt-5"> <header className="flex items-center justify-between px-4 pb-3 pt-5">
<h2 className="font-display text-base font-semibold tracking-tight text-white"> <h2 className="font-display text-base font-semibold tracking-tight text-fg">
{t('app:nav.chats')} {showArchived
? t('app:chats.archived_title', { defaultValue: 'Archiv' })
: t('app:nav.chats')}
</h2> </h2>
<button <div className="flex items-center gap-1">
type="button" <button
onClick={onNewGroup} type="button"
aria-label={t('app:chats.new_group')} onClick={onToggleArchived}
title={t('app:chats.new_group')} aria-label={
className="flex h-8 cursor-pointer items-center gap-1.5 rounded-lg border border-white/10 bg-white/5 px-2.5 text-xs font-medium text-neutral-300 transition hover:bg-white/10 hover:text-neutral-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40" showArchived
> ? t('app:chats.show_active', { defaultValue: 'Aktive anzeigen' })
<UsersIcon className="h-3.5 w-3.5" /> : t('app:chats.show_archived', { defaultValue: 'Archiv anzeigen' })
<PlusIcon className="h-3 w-3" /> }
</button> title={
showArchived
? t('app:chats.show_active', { defaultValue: 'Aktive anzeigen' })
: t('app:chats.show_archived', { defaultValue: 'Archiv anzeigen' })
}
className={
'relative flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ' +
(showArchived
? 'bg-accent/15 text-accent'
: 'text-fg-muted hover:bg-surface-3 hover:text-fg')
}
>
<ArchiveIcon className="h-4 w-4" />
{!showArchived && archivedUnread > 0 && (
<span
aria-hidden="true"
className="absolute -right-0.5 -top-0.5 flex min-w-[16px] items-center justify-center rounded-full bg-accent px-1 text-[9px] font-bold leading-tight text-accent-fg"
>
{archivedUnread > 9 ? '9+' : archivedUnread}
</span>
)}
</button>
{!showArchived && (
<button
type="button"
onClick={onNewGroup}
aria-label={t('app:chats.new_group')}
title={t('app:chats.new_group')}
className="flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg text-fg-muted transition hover:bg-surface-3 hover:text-fg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
>
<AddUserIcon className="h-4 w-4" />
</button>
)}
</div>
</header> </header>
<div className="px-3 pb-2">
<label className="relative block">
<span className="sr-only">{t('app:chats.search', { defaultValue: 'Suche' })}</span>
<SearchIcon
aria-hidden="true"
className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-fg-muted"
/>
<input
type="search"
value={query}
onChange={(e) => onQueryChange(e.target.value)}
placeholder={t('app:chats.search_placeholder', { defaultValue: 'Suche…' })}
className="w-full rounded-lg border border-line bg-surface-3 py-2 pl-9 pr-3 text-sm text-fg placeholder-fg-muted transition focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/30"
/>
</label>
</div>
{loading ? ( {loading ? (
<div className="flex items-center gap-2 px-4 py-2 text-xs text-neutral-500"> <div className="flex items-center gap-2 px-4 py-2 text-xs text-fg-muted">
<SpinnerIcon className="h-3.5 w-3.5 text-brand-400" /> <SpinnerIcon className="h-3.5 w-3.5 text-accent" />
</div> </div>
) : error ? ( ) : error ? (
<p className="px-4 py-2 text-xs text-rose-300">{error}</p> <p className="px-4 py-2 text-xs text-rose-500 dark:text-rose-300">{error}</p>
) : items.length === 0 ? ( ) : items.length === 0 ? (
<div className="flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center"> <div className="flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center">
<div className="flex h-12 w-12 items-center justify-center rounded-2xl border border-white/10 bg-white/5 text-brand-300"> <div className="flex h-12 w-12 items-center justify-center rounded-2xl border border-line bg-surface-3 text-accent">
<ChatBubbleIcon className="h-5 w-5" /> {showArchived ? (
<ArchiveIcon className="h-5 w-5" />
) : (
<ChatBubbleIcon className="h-5 w-5" />
)}
</div> </div>
<p className="text-sm text-neutral-400">{t('app:chats.empty_title')}</p> <p className="text-sm text-fg-muted">
<p className="text-xs text-neutral-500">{t('app:chats.empty_subtitle')}</p> {showArchived
? t('app:chats.archived_empty_title', { defaultValue: 'Nichts archiviert' })
: t('app:chats.empty_title')}
</p>
<p className="text-xs text-fg-muted/80">
{showArchived
? t('app:chats.archived_empty_subtitle', {
defaultValue: 'Archivierte Unterhaltungen erscheinen hier.',
})
: t('app:chats.empty_subtitle')}
</p>
</div> </div>
) : ( ) : (
<ul className="flex-1 overflow-y-auto px-2 pb-4"> <ul className="flex-1 overflow-y-auto px-2 pb-2">
{items.map((c) => ( {items.map((c) => (
<li key={c.id}> <li key={c.id}>
<ConversationRow <ConversationRow
@@ -117,6 +240,10 @@ function ConversationList({
))} ))}
</ul> </ul>
)} )}
<div className="shrink-0 border-t border-line bg-surface-2 p-2">
<UserBar />
</div>
</aside> </aside>
); );
} }
@@ -136,16 +263,22 @@ function ConversationRow({
const title = const title =
item.type === 'dm' ? (item.peer?.displayName ?? '?') : (item.name ?? '?'); item.type === 'dm' ? (item.peer?.displayName ?? '?') : (item.name ?? '?');
const handle = item.type === 'dm' ? '@' + (item.peer?.username ?? '?') : ''; const handle = item.type === 'dm' ? '@' + (item.peer?.username ?? '?') : '';
const letter = title.trim().charAt(0).toUpperCase() || '?'; const avatarUrl =
item.type === 'dm' ? (item.peer?.avatarUrl ?? null) : (item.avatarUrl ?? null);
const preview =
item.type === 'dm' ? handle : t('app:chats.group_preview', {
count: item.members.length,
defaultValue: `${item.members.length} Mitglieder`,
});
if (!item.acceptedByMe) { if (!item.acceptedByMe) {
return ( return (
<div className="my-1 rounded-xl border border-amber-500/20 bg-amber-500/5 p-3"> <div className="my-1 rounded-xl border border-amber-500/30 bg-amber-500/5 p-3">
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<Avatar letter={letter} /> <ConvAvatar url={avatarUrl} title={title} isGroup={item.type === 'group'} />
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="truncate text-sm font-semibold text-white">{title}</p> <p className="truncate text-sm font-semibold text-fg">{title}</p>
<p className="truncate text-xs text-amber-200/80"> <p className="truncate text-xs text-amber-600 dark:text-amber-200/80">
{t('app:friends.incoming_request')} {t('app:friends.incoming_request')}
</p> </p>
</div> </div>
@@ -153,7 +286,7 @@ function ConversationRow({
<button <button
type="button" type="button"
onClick={() => onAccept(item.id)} onClick={() => onAccept(item.id)}
className="mt-3 w-full cursor-pointer rounded-md bg-amber-500/20 px-3 py-1.5 text-xs font-semibold text-amber-100 transition hover:bg-amber-500/30 focus:outline-none focus-visible:ring-2 focus-visible:ring-amber-400/40" className="mt-3 w-full cursor-pointer rounded-md bg-amber-500/20 px-3 py-1.5 text-xs font-semibold text-amber-700 transition hover:bg-amber-500/30 focus:outline-none focus-visible:ring-2 focus-visible:ring-amber-400/40 dark:text-amber-100"
> >
{t('app:friends.action_accept')} {t('app:friends.action_accept')}
</button> </button>
@@ -161,41 +294,88 @@ function ConversationRow({
); );
} }
const muted = isConversationMuted(item.mutedUntil);
return ( return (
<NavLink <NavLink
to={'/chats/' + item.id} to={'/chats/' + item.id}
className={ className={
'my-1 flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2.5 transition focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 ' + 'group relative my-1 flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2.5 transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ' +
(active ? 'bg-brand-500/15 ring-1 ring-brand-400/30' : 'hover:bg-white/5') (active
? 'bg-accent/15 text-fg'
: 'text-fg hover:bg-surface-3/70')
} }
> >
<Avatar letter={letter} /> <ConvAvatar url={avatarUrl} title={title} isGroup={item.type === 'group'} />
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p <div className="flex items-center gap-1.5">
className={ <p
'truncate text-sm ' + className={
(unreadCount > 0 ? 'font-bold text-white' : 'font-semibold text-white') 'truncate text-sm ' +
} (unreadCount > 0 && !muted ? 'font-bold' : 'font-semibold')
> }
{title} >
</p> {title}
<p className="truncate text-xs text-neutral-500">{handle}</p> </p>
{muted && (
<BellOffIcon
aria-hidden="true"
className="h-3 w-3 shrink-0 text-fg-muted"
/>
)}
</div>
<p className="truncate text-xs text-fg-muted">{preview}</p>
</div> </div>
{unreadCount > 0 && ( {unreadCount > 0 && (
<span <span
aria-label={'Unread: ' + unreadCount} aria-label={'Unread: ' + unreadCount}
className="inline-flex min-w-[20px] items-center justify-center rounded-full bg-rose-500 px-1.5 text-[10px] font-bold leading-tight text-white" className={
'inline-flex min-w-[20px] items-center justify-center rounded-full px-1.5 text-[10px] font-bold leading-tight ' +
(muted
? 'bg-fg-muted/30 text-fg-muted'
: 'bg-accent text-accent-fg')
}
> >
{unreadCount > 99 ? '99+' : unreadCount} {unreadCount > 99 ? '99+' : unreadCount}
</span> </span>
)} )}
<ConversationRowMenu
conversationId={item.id}
archived={item.archived}
mutedUntil={item.mutedUntil}
/>
</NavLink> </NavLink>
); );
} }
function Avatar({ letter }: { letter: string }) { function ConvAvatar({
url,
title,
isGroup,
}: {
url: string | null;
title: string;
isGroup: boolean;
}) {
if (url) {
return (
<img
src={url}
alt=""
className="h-9 w-9 shrink-0 rounded-full object-cover"
draggable={false}
/>
);
}
if (isGroup) {
return (
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-accent/20 text-accent">
<UsersIcon className="h-4 w-4" />
</div>
);
}
const letter = title.trim().charAt(0).toUpperCase() || '?';
return ( return (
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-brand-500/30 text-sm font-semibold text-white ring-1 ring-brand-400/30"> <div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-accent/20 text-sm font-semibold text-accent">
{letter} {letter}
</div> </div>
); );
@@ -206,13 +386,13 @@ export function ChatsEmptyState() {
return ( return (
<div className="flex h-full items-center justify-center p-10"> <div className="flex h-full items-center justify-center p-10">
<div className="max-w-md text-center"> <div className="max-w-md text-center">
<div className="mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-2xl border border-white/10 bg-white/5 text-brand-300"> <div className="mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-2xl border border-line bg-surface-2 text-accent">
<ChatBubbleIcon className="h-6 w-6" /> <ChatBubbleIcon className="h-6 w-6" />
</div> </div>
<h2 className="font-display text-2xl font-semibold tracking-tight text-white"> <h2 className="font-display text-2xl font-semibold tracking-tight text-fg">
{t('app:chats.select_prompt')} {t('app:chats.select_prompt')}
</h2> </h2>
<p className="mt-2 text-sm text-neutral-400">{t('app:chats.select_subtitle')}</p> <p className="mt-2 text-sm text-fg-muted">{t('app:chats.select_subtitle')}</p>
</div> </div>
</div> </div>
); );
+324 -23
View File
@@ -1,15 +1,30 @@
import { parseMessagePayload } from '@chat-app/shared/chat';
import { extractErrorCode } from '@chat-app/shared/i18n'; import { extractErrorCode } from '@chat-app/shared/i18n';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { ConversationHeader } from '../components/ConversationHeader'; import { ConversationHeader } from '../components/ConversationHeader';
import { ForwardDialog } from '../components/ForwardDialog';
import { GroupInfoPanel } from '../components/GroupInfoPanel'; import { GroupInfoPanel } from '../components/GroupInfoPanel';
import { AlertIcon, ArrowRightIcon, PlusIcon, SpinnerIcon, XIcon } from '../components/icons'; import {
AlertIcon,
ArrowRightIcon,
ChevronDownIcon,
ChevronUpIcon,
PlusIcon,
ReplyIcon,
SearchIcon,
SpinnerIcon,
XIcon,
} from '../components/icons';
import { InCallPanel } from '../components/InCallPanel'; import { InCallPanel } from '../components/InCallPanel';
import { MessageBubble } from '../components/MessageBubble'; import { IncomingCallPanel } from '../components/IncomingCallPanel';
import { MessageBubble, type QuotedRef } from '../components/MessageBubble';
import { TypingIndicator } from '../components/TypingIndicator'; import { TypingIndicator } from '../components/TypingIndicator';
import type { DecryptedMessage } from '@chat-app/shared/chat';
import { useAuth } from '../context/AuthContext'; import { useAuth } from '../context/AuthContext';
import { useCall } from '../context/CallContext';
import { useConversationsContext } from '../context/ConversationsContext'; import { useConversationsContext } from '../context/ConversationsContext';
import { useConversationMessages } from '../lib/useConversationMessages'; import { useConversationMessages } from '../lib/useConversationMessages';
import { useMessageReactions } from '../lib/useMessageReactions'; import { useMessageReactions } from '../lib/useMessageReactions';
@@ -80,8 +95,114 @@ export function ConversationPage() {
const [stickToBottom, setStickToBottom] = useState(true); const [stickToBottom, setStickToBottom] = useState(true);
const [attachments, setAttachments] = useState<File[]>([]); const [attachments, setAttachments] = useState<File[]>([]);
const [infoPanelOpen, setInfoPanelOpen] = useState(false); const [infoPanelOpen, setInfoPanelOpen] = useState(false);
const [replyTo, setReplyTo] = useState<DecryptedMessage | null>(null);
const [forwardTarget, setForwardTarget] = useState<DecryptedMessage | null>(null);
const [searchOpen, setSearchOpen] = useState(false);
const [searchQuery, setSearchQuery] = useState('');
const [searchIdx, setSearchIdx] = useState(0);
const [highlightedId, setHighlightedId] = useState<string | null>(null);
const scrollRef = useRef<HTMLDivElement>(null); const scrollRef = useRef<HTMLDivElement>(null);
const fileInputRef = useRef<HTMLInputElement>(null); const fileInputRef = useRef<HTMLInputElement>(null);
const composerRef = useRef<HTMLTextAreaElement>(null);
// Drop reply-to / clear search state when switching conversation.
useEffect(() => {
setReplyTo(null);
setForwardTarget(null);
setSearchOpen(false);
setSearchQuery('');
}, [id]);
const messageById = useMemo(() => {
const m = new Map<string, DecryptedMessage>();
for (const msg of messages) m.set(msg.id, msg);
return m;
}, [messages]);
const senderNameFor = useCallback(
(senderId: string): string => {
if (senderId === myId) return t('app:chats.you', { defaultValue: 'Du' });
const profile =
conversation?.members.find((mm) => mm.userId === senderId)?.profile ??
(senderId !== myId ? conversation?.peer ?? null : null);
return profile?.displayName ?? '?';
},
[conversation, myId, t],
);
const buildQuoted = useCallback(
(replyToId: string | null): QuotedRef | null => {
if (!replyToId) return null;
const target = messageById.get(replyToId);
if (!target) {
return {
id: replyToId,
senderName: '…',
snippet: t('app:chats.quote_unavailable', { defaultValue: 'Nachricht nicht verfügbar' }),
isAttachment: false,
deleted: true,
};
}
const parsed = parseMessagePayload(target.plaintext);
const text = parsed.kind === 'text' ? parsed.text : '';
const hasAttachment = parsed.kind === 'text' && parsed.attachments.length > 0;
return {
id: target.id,
senderName: senderNameFor(target.senderId),
snippet: text.length > 120 ? text.slice(0, 120) + '…' : text,
isAttachment: hasAttachment,
deleted: !!target.deletedAt,
};
},
[messageById, senderNameFor, t],
);
const jumpToMessage = useCallback((targetId: string) => {
const el = scrollRef.current?.querySelector<HTMLElement>(
'[data-message-id="' + CSS.escape(targetId) + '"]',
);
if (!el) return;
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
setHighlightedId(targetId);
window.setTimeout(() => setHighlightedId((cur) => (cur === targetId ? null : cur)), 1600);
}, []);
const handleReply = useCallback((m: DecryptedMessage) => {
setReplyTo(m);
composerRef.current?.focus();
}, []);
const handleForward = useCallback((m: DecryptedMessage) => {
setForwardTarget(m);
}, []);
// Search matches: messages whose decrypted text includes the query.
const searchMatches = useMemo(() => {
const q = searchQuery.trim().toLowerCase();
if (!q) return [] as DecryptedMessage[];
return messages.filter((m) => {
if (!m.plaintext) return false;
const parsed = parseMessagePayload(m.plaintext);
if (parsed.kind !== 'text') return false;
return parsed.text.toLowerCase().includes(q);
});
}, [messages, searchQuery]);
// Reset/clamp the active match index when the match set changes.
useEffect(() => {
if (searchMatches.length === 0) {
setSearchIdx(0);
return;
}
setSearchIdx((cur) => Math.min(cur, searchMatches.length - 1));
}, [searchMatches.length]);
// Auto-jump to current match.
useEffect(() => {
if (!searchOpen || searchMatches.length === 0) return;
const target = searchMatches[searchIdx];
if (target) jumpToMessage(target.id);
}, [searchOpen, searchMatches, searchIdx, jumpToMessage]);
useEffect(() => { useEffect(() => {
if (!id) return; if (!id) return;
@@ -120,9 +241,10 @@ export function ConversationPage() {
setSending(true); setSending(true);
setSendError(null); setSendError(null);
try { try {
await send(text, attachments); await send(text, attachments, replyTo?.id ?? null);
setText(''); setText('');
setAttachments([]); setAttachments([]);
setReplyTo(null);
if (fileInputRef.current) fileInputRef.current.value = ''; if (fileInputRef.current) fileInputRef.current.value = '';
setStickToBottom(true); setStickToBottom(true);
notifyStopTyping(); notifyStopTyping();
@@ -157,14 +279,49 @@ export function ConversationPage() {
} }
const isGroup = conversation?.type === 'group'; const isGroup = conversation?.type === 'group';
const { state: callState } = useCall();
// Hide the chat header while this conversation hosts an active call — the
// call topbar inside the dock already shows the channel name + duration,
// and fullscreen cinema needs the whole slot.
const callHereActive =
(callState.kind === 'connected' ||
callState.kind === 'connecting' ||
callState.kind === 'outgoing') &&
callState.conversationId === id;
const incomingHere =
callState.kind === 'incoming' && callState.conversationId === id;
return ( return (
<div className="relative flex h-full flex-col"> <div className="relative flex h-full flex-col">
<ConversationHeader {!callHereActive && (
conversation={conversation} <ConversationHeader
peerPresence={peerPresence} conversation={conversation}
{...(isGroup ? { onInfoClick: () => setInfoPanelOpen(true) } : {})} peerPresence={peerPresence}
/> onSearchClick={() => setSearchOpen((v) => !v)}
{...(isGroup ? { onInfoClick: () => setInfoPanelOpen(true) } : {})}
/>
)}
{!callHereActive && searchOpen && (
<SearchBar
query={searchQuery}
onQueryChange={setSearchQuery}
matches={searchMatches.length}
activeIdx={searchIdx}
onPrev={() =>
setSearchIdx((cur) =>
searchMatches.length === 0 ? 0 : (cur - 1 + searchMatches.length) % searchMatches.length,
)
}
onNext={() =>
setSearchIdx((cur) => (searchMatches.length === 0 ? 0 : (cur + 1) % searchMatches.length))
}
onClose={() => {
setSearchOpen(false);
setSearchQuery('');
}}
/>
)}
{isGroup && conversation && ( {isGroup && conversation && (
<GroupInfoPanel <GroupInfoPanel
@@ -174,32 +331,64 @@ export function ConversationPage() {
/> />
)} )}
{incomingHere && conversation && <IncomingCallPanel conversation={conversation} />}
{conversation && <InCallPanel conversation={conversation} />} {conversation && <InCallPanel conversation={conversation} />}
<div ref={scrollRef} onScroll={handleScroll} className="flex-1 overflow-y-auto px-6 py-4"> <div ref={scrollRef} onScroll={handleScroll} className="flex-1 overflow-y-auto bg-surface-3 px-6 py-4">
{loading ? ( {loading ? (
<div className="flex items-center gap-2 text-xs text-neutral-500"> <div className="flex items-center gap-2 text-xs text-fg-muted">
<SpinnerIcon className="h-3.5 w-3.5 text-brand-400" /> <SpinnerIcon className="h-3.5 w-3.5 text-accent" />
</div> </div>
) : error ? ( ) : error ? (
<Banner>{error}</Banner> <Banner>{error}</Banner>
) : messages.length === 0 ? ( ) : messages.length === 0 ? (
<p className="text-center text-sm text-neutral-500"></p> <p className="text-center text-sm text-fg-muted"></p>
) : ( ) : (
<ul className="space-y-0.5"> <ul className="space-y-0.5">
{messages.map((m, idx) => { {messages.map((m, idx) => {
const prev = messages[idx - 1]; // A "run" is consecutive bubbles from the same sender with
const grouped = idx > 0 && prev?.senderId === m.senderId; // nothing between them. Call-event separators break the run —
// a bubble whose immediate next neighbour is a call_event must
// anchor the avatar, even if another bubble from the same
// sender appears after the separator.
const prevRaw = messages[idx - 1];
const nextRaw = messages[idx + 1];
const prevIsCallEvent =
!!prevRaw && parseMessagePayload(prevRaw.plaintext).kind === 'call_event';
const nextIsCallEvent =
!!nextRaw && parseMessagePayload(nextRaw.plaintext).kind === 'call_event';
const grouped =
!!prevRaw && prevRaw.senderId === m.senderId && !prevIsCallEvent;
// Anchor avatar on the LAST message of a run so it aligns with
// the bubble's tail (bottom corner). Tail is bottom-left for
// mine, bottom-right for peer — see rounded-[…_4px_…] above.
const isLastOfRun =
!nextRaw || nextRaw.senderId !== m.senderId || nextIsCallEvent;
// DM fallback: if member lookup fails (e.g. transient sync), fall
// back to conversation.peer so the peer's avatar still resolves.
const memberProfile =
conversation?.members.find((mm) => mm.userId === m.senderId)?.profile ?? null;
const senderProfile =
memberProfile ??
(m.senderId !== myId ? (conversation?.peer ?? null) : null);
return ( return (
<li key={m.id}> <li key={m.id}>
<MessageBubble <MessageBubble
message={m} message={m}
mine={m.senderId === myId} mine={m.senderId === myId}
groupedWithPrev={grouped} groupedWithPrev={grouped}
isLastOfRun={isLastOfRun}
senderDisplayName={senderProfile?.displayName}
senderAvatarUrl={senderProfile?.avatarUrl}
conversationId={id ?? ''} conversationId={id ?? ''}
reactions={reactionsByMessage.get(m.id) ?? []} reactions={reactionsByMessage.get(m.id) ?? []}
onToggleReaction={(emoji) => toggleReaction(m.id, emoji)} onToggleReaction={(emoji) => toggleReaction(m.id, emoji)}
showSeen={m.id === lastSeenMessageId} showSeen={m.id === lastSeenMessageId}
quoted={buildQuoted(m.replyToId)}
onJumpToMessage={jumpToMessage}
onReply={handleReply}
onForward={handleForward}
highlighted={highlightedId === m.id}
/> />
</li> </li>
); );
@@ -213,13 +402,45 @@ export function ConversationPage() {
members={conversation?.members ?? []} members={conversation?.members ?? []}
/> />
<form onSubmit={handleSend} className="border-t border-white/5 p-4"> <form onSubmit={handleSend} className="border-t border-line bg-surface-3 p-4">
{sendError && ( {sendError && (
<div className="mb-2"> <div className="mb-2">
<Banner>{sendError}</Banner> <Banner>{sendError}</Banner>
</div> </div>
)} )}
{replyTo && (
<div className="mb-2 flex items-stretch gap-2 rounded-lg border border-line bg-surface-2 p-2 text-sm">
<span aria-hidden="true" className="w-1 shrink-0 rounded-full bg-accent" />
<ReplyIcon className="mt-0.5 h-4 w-4 shrink-0 text-accent" />
<div className="min-w-0 flex-1">
<p className="truncate text-xs font-semibold text-fg">
{t('app:chats.replying_to', {
name: senderNameFor(replyTo.senderId),
defaultValue: 'Antwort an ' + senderNameFor(replyTo.senderId),
})}
</p>
<p className="truncate text-xs italic text-fg-muted">
{(() => {
if (!replyTo.plaintext) return '…';
const p = parseMessagePayload(replyTo.plaintext);
if (p.kind !== 'text') return '';
if (!p.text && p.attachments.length > 0) return '📎';
return p.text;
})()}
</p>
</div>
<button
type="button"
onClick={() => setReplyTo(null)}
aria-label={t('app:friends.action_cancel', { defaultValue: 'Abbrechen' })}
className="shrink-0 cursor-pointer rounded-md p-1 text-fg-muted transition hover:bg-surface-3 hover:text-fg"
>
<XIcon className="h-4 w-4" />
</button>
</div>
)}
{attachments.length > 0 && ( {attachments.length > 0 && (
<div className="mb-2 flex flex-wrap gap-2"> <div className="mb-2 flex flex-wrap gap-2">
{attachments.map((file, idx) => ( {attachments.map((file, idx) => (
@@ -248,11 +469,12 @@ export function ConversationPage() {
onClick={() => fileInputRef.current?.click()} onClick={() => fileInputRef.current?.click()}
aria-label="Bild anhängen" aria-label="Bild anhängen"
title="Bild anhängen" title="Bild anhängen"
className="inline-flex h-11 w-11 cursor-pointer items-center justify-center rounded-lg border border-white/10 bg-white/5 text-neutral-300 transition hover:bg-white/10 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40" className="inline-flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-lg bg-accent text-accent-fg transition hover:brightness-110 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/50"
> >
<PlusIcon className="h-4 w-4" /> <PlusIcon className="h-4 w-4" />
</button> </button>
<textarea <textarea
ref={composerRef}
value={text} value={text}
onChange={(e) => { onChange={(e) => {
setText(e.target.value); setText(e.target.value);
@@ -265,30 +487,109 @@ export function ConversationPage() {
} }
}} }}
rows={1} rows={1}
placeholder="…" placeholder="Nachricht schreiben…"
className="max-h-40 min-h-[44px] flex-1 resize-none rounded-lg border border-white/10 bg-ink-900/60 px-3 py-2.5 text-sm text-white placeholder-neutral-500 transition focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-500/40" className="max-h-40 min-h-[44px] flex-1 resize-none rounded-lg border border-line bg-surface-2 px-3 py-2.5 text-sm text-fg placeholder-fg-muted transition focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/30"
/> />
<button <button
type="submit" type="submit"
disabled={sending || (text.trim().length === 0 && attachments.length === 0)} disabled={sending || (text.trim().length === 0 && attachments.length === 0)}
aria-busy={sending} aria-busy={sending}
className="inline-flex h-11 w-11 cursor-pointer items-center justify-center rounded-lg bg-gradient-to-br from-brand-400 to-brand-600 text-white transition hover:from-brand-300 hover:to-brand-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/60 disabled:cursor-not-allowed disabled:opacity-60" className="inline-flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-lg bg-accent text-accent-fg transition hover:brightness-110 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/60 disabled:cursor-not-allowed disabled:opacity-60"
> >
{sending ? <SpinnerIcon className="h-4 w-4" /> : <ArrowRightIcon className="h-4 w-4" />} {sending ? <SpinnerIcon className="h-4 w-4" /> : <ArrowRightIcon className="h-4 w-4" />}
</button> </button>
</div> </div>
</form> </form>
<ForwardDialog
open={forwardTarget !== null}
message={forwardTarget}
currentConversationId={id ?? null}
onClose={() => setForwardTarget(null)}
/>
</div> </div>
); );
} }
interface SearchBarProps {
query: string;
onQueryChange: (q: string) => void;
matches: number;
activeIdx: number;
onPrev: () => void;
onNext: () => void;
onClose: () => void;
}
function SearchBar({ query, onQueryChange, matches, activeIdx, onPrev, onNext, onClose }: SearchBarProps) {
const { t } = useTranslation(['app']);
return (
<div className="flex items-center gap-2 border-b border-line bg-surface-2 px-4 py-2">
<SearchIcon className="h-4 w-4 shrink-0 text-fg-muted" />
<input
type="search"
autoFocus
value={query}
onChange={(e) => onQueryChange(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Escape') onClose();
if (e.key === 'Enter') {
e.preventDefault();
if (e.shiftKey) onPrev();
else onNext();
}
}}
placeholder={t('app:chats.search_in_conv', { defaultValue: 'In Unterhaltung suchen…' })}
className="min-w-0 flex-1 bg-transparent text-sm text-fg placeholder-fg-muted outline-none"
/>
<span className="shrink-0 text-xs tabular-nums text-fg-muted">
{matches === 0
? query.trim().length > 0
? t('app:chats.search_none', { defaultValue: 'Keine Treffer' })
: ''
: activeIdx + 1 + ' / ' + matches}
</span>
<button
type="button"
onClick={onPrev}
disabled={matches === 0}
aria-label="Previous"
className="cursor-pointer rounded-md p-1 text-fg-muted transition hover:bg-surface-3 hover:text-fg disabled:cursor-not-allowed disabled:opacity-40"
>
<ChevronUpIcon className="h-4 w-4" />
</button>
<button
type="button"
onClick={onNext}
disabled={matches === 0}
aria-label="Next"
className="cursor-pointer rounded-md p-1 text-fg-muted transition hover:bg-surface-3 hover:text-fg disabled:cursor-not-allowed disabled:opacity-40"
>
<ChevronDownIcon className="h-4 w-4" />
</button>
<button
type="button"
onClick={onClose}
aria-label="Close"
className="cursor-pointer rounded-md p-1 text-fg-muted transition hover:bg-surface-3 hover:text-fg"
>
<XIcon className="h-4 w-4" />
</button>
</div>
);
}
// Walks `messages` from `idx + step` skipping call_event entries until a
// regular bubble is found or the array boundary is reached. Used to decide
// run-grouping for avatar placement so call separators don't bleed into
// sender continuity.
function Banner({ children }: { children: React.ReactNode }) { function Banner({ children }: { children: React.ReactNode }) {
return ( return (
<div <div
role="alert" role="alert"
className="flex items-start gap-3 rounded-lg border border-rose-500/20 bg-rose-500/10 p-3 text-sm text-rose-100" className="flex items-start gap-3 rounded-lg border border-rose-500/30 bg-rose-500/10 p-3 text-sm text-rose-700 dark:text-rose-100"
> >
<AlertIcon className="mt-0.5 h-5 w-5 shrink-0 text-rose-400" /> <AlertIcon className="mt-0.5 h-5 w-5 shrink-0 text-rose-500 dark:text-rose-400" />
<p className="min-w-0 flex-1 break-words">{children}</p> <p className="min-w-0 flex-1 break-words">{children}</p>
</div> </div>
); );
@@ -302,7 +603,7 @@ function AttachmentPreview({ file, onRemove }: { file: File; onRemove: () => voi
return () => URL.revokeObjectURL(u); return () => URL.revokeObjectURL(u);
}, [file]); }, [file]);
return ( return (
<div className="relative overflow-hidden rounded-lg border border-white/10 bg-ink-900/60"> <div className="relative overflow-hidden rounded-lg border border-line bg-surface-2">
{url ? ( {url ? (
<img src={url} alt={file.name} className="block h-20 w-20 object-cover" /> <img src={url} alt={file.name} className="block h-20 w-20 object-cover" />
) : ( ) : (
@@ -312,7 +613,7 @@ function AttachmentPreview({ file, onRemove }: { file: File; onRemove: () => voi
type="button" type="button"
onClick={onRemove} onClick={onRemove}
aria-label="Entfernen" aria-label="Entfernen"
className="absolute right-1 top-1 flex h-5 w-5 cursor-pointer items-center justify-center rounded-full bg-ink-950/80 text-neutral-200 transition hover:bg-rose-500/70 hover:text-white" className="absolute right-1 top-1 flex h-5 w-5 cursor-pointer items-center justify-center rounded-full bg-black/70 text-white transition hover:bg-rose-500/80"
> >
<XIcon className="h-3 w-3" /> <XIcon className="h-3 w-3" />
</button> </button>
+77 -9
View File
@@ -1,11 +1,18 @@
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { DeviceRegistration } from '../components/DeviceRegistration'; import { DeviceRegistration } from '../components/DeviceRegistration';
import { DeviceRestore } from '../components/DeviceRestore';
import { useAuth } from '../context/AuthContext'; import { useAuth } from '../context/AuthContext';
type Mode = 'register' | 'restore';
export function DevicePage() { export function DevicePage() {
const { t } = useTranslation(['app']);
const { session, profile, setDevice } = useAuth(); const { session, profile, setDevice } = useAuth();
const navigate = useNavigate(); const navigate = useNavigate();
const [mode, setMode] = useState<Mode>('register');
if (!session) return null; // Guarded by RequireAuth, but be defensive. if (!session) return null; // Guarded by RequireAuth, but be defensive.
@@ -15,20 +22,81 @@ export function DevicePage() {
return ( return (
<main className="relative flex min-h-screen items-center justify-center overflow-hidden bg-ink-950 px-5 py-10 text-neutral-100 sm:px-8"> <main className="relative flex min-h-screen items-center justify-center overflow-hidden bg-ink-950 px-5 py-10 text-neutral-100 sm:px-8">
<BackgroundStage /> <BackgroundStage />
<div className="relative z-10 w-full max-w-md"> <div className="relative z-10 w-full max-w-md space-y-3">
<DeviceRegistration <div
userId={session.user.id} role="tablist"
defaultName={defaultName} aria-label={t('app:backup.mode_label', { defaultValue: 'Gerätemodus' })}
onRegistered={(device) => { className="flex gap-1 rounded-xl border border-white/10 bg-ink-900/60 p-1 backdrop-blur-xl"
setDevice(device); >
navigate('/chats', { replace: true }); <TabButton
}} active={mode === 'register'}
/> onClick={() => setMode('register')}
label={t('app:backup.mode_register', { defaultValue: 'Neu einrichten' })}
/>
<TabButton
active={mode === 'restore'}
onClick={() => setMode('restore')}
label={t('app:backup.mode_restore', { defaultValue: 'Backup wiederherstellen' })}
/>
</div>
{mode === 'register' ? (
<DeviceRegistration
userId={session.user.id}
defaultName={defaultName}
onRegistered={(device) => {
setDevice(device);
// Signal the chats page to open the post-registration backup
// prompt (AppShell reads this on mount).
try {
window.sessionStorage.setItem('chatapp.backup.prompt', '1');
} catch {
/* storage disabled — skip hint */
}
navigate('/chats', { replace: true });
}}
/>
) : (
<DeviceRestore
userId={session.user.id}
onRestored={(device) => {
setDevice(device);
navigate('/chats', { replace: true });
}}
/>
)}
</div> </div>
</main> </main>
); );
} }
function TabButton({
active,
onClick,
label,
}: {
active: boolean;
onClick: () => void;
label: string;
}) {
return (
<button
type="button"
role="tab"
aria-selected={active}
onClick={onClick}
className={
'flex-1 cursor-pointer rounded-lg px-3 py-2 text-xs font-semibold transition focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 ' +
(active
? 'bg-brand-500/20 text-brand-100 ring-1 ring-brand-400/40'
: 'text-neutral-400 hover:bg-white/5 hover:text-neutral-100')
}
>
{label}
</button>
);
}
function BackgroundStage() { function BackgroundStage() {
return ( return (
<div aria-hidden="true" className="pointer-events-none absolute inset-0"> <div aria-hidden="true" className="pointer-events-none absolute inset-0">
+41 -46
View File
@@ -10,7 +10,9 @@ import {
import { extractErrorCode } from '@chat-app/shared/i18n'; import { extractErrorCode } from '@chat-app/shared/i18n';
import { useCallback, useEffect, useMemo, useState } from 'react'; import { useCallback, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { Avatar } from '../components/Avatar';
import { import {
AlertIcon, AlertIcon,
ChatBubbleIcon, ChatBubbleIcon,
@@ -28,6 +30,7 @@ type Tab = 'friends' | 'pending' | 'requests';
export function FriendsPage() { export function FriendsPage() {
const { t } = useTranslation(['app', 'errors']); const { t } = useTranslation(['app', 'errors']);
const { friendships, loading, error, refresh } = useFriendshipsContext(); const { friendships, loading, error, refresh } = useFriendshipsContext();
const navigate = useNavigate();
const [tab, setTab] = useState<Tab>('friends'); const [tab, setTab] = useState<Tab>('friends');
const [query, setQuery] = useState(''); const [query, setQuery] = useState('');
const [debounced, setDebounced] = useState(''); const [debounced, setDebounced] = useState('');
@@ -104,25 +107,26 @@ export function FriendsPage() {
); );
return ( return (
<div className="mx-auto flex h-full max-w-3xl flex-col gap-5 px-6 py-8"> <div className="min-h-full bg-surface-3 text-fg">
<div className="mx-auto flex min-h-full max-w-3xl flex-col gap-5 px-6 py-8">
<header className="flex items-center justify-between gap-4"> <header className="flex items-center justify-between gap-4">
<h1 className="font-display text-2xl font-semibold tracking-tight text-white"> <h1 className="font-display text-2xl font-semibold tracking-tight text-fg">
{t('app:friends.title')} {t('app:friends.title')}
</h1> </h1>
</header> </header>
<div className="space-y-3"> <div className="space-y-3">
<div className="relative"> <div className="relative">
<SearchIcon className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-neutral-500" /> <SearchIcon className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-fg-muted" />
<input <input
type="search" type="search"
value={query} value={query}
onChange={(e) => setQuery(e.target.value.toLowerCase())} onChange={(e) => setQuery(e.target.value)}
placeholder={t('app:friends.search_placeholder')} placeholder={t('app:friends.search_placeholder')}
autoComplete="off" autoComplete="off"
autoCapitalize="none" autoCapitalize="none"
spellCheck={false} spellCheck={false}
className="w-full rounded-lg border border-white/10 bg-ink-900/60 py-2.5 pl-10 pr-3 text-sm text-white placeholder-neutral-500 transition focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-500/40" className="w-full rounded-lg border border-line bg-surface-2 py-2.5 pl-10 pr-3 text-sm text-fg placeholder-fg-muted transition focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/30"
/> />
</div> </div>
{query.length > 0 && ( {query.length > 0 && (
@@ -138,7 +142,7 @@ export function FriendsPage() {
)} )}
</div> </div>
<div className="flex gap-2 border-b border-white/5"> <div className="flex gap-2 border-b border-line">
<TabButton active={tab === 'friends'} onClick={() => setTab('friends')}> <TabButton active={tab === 'friends'} onClick={() => setTab('friends')}>
{t('app:friends.tab_friends')} · {accepted.length} {t('app:friends.tab_friends')} · {accepted.length}
</TabButton> </TabButton>
@@ -165,7 +169,7 @@ export function FriendsPage() {
onMessage={() => onMessage={() =>
performAction('msg-' + f.peer.userId, async () => { performAction('msg-' + f.peer.userId, async () => {
const id = await createDm(supabase, f.peer.userId); const id = await createDm(supabase, f.peer.userId);
navigateToChat(id); navigate('/chats/' + id);
}) })
} }
onUnfriend={() => onUnfriend={() =>
@@ -206,16 +210,11 @@ export function FriendsPage() {
)} )}
/> />
)} )}
</div>
</div> </div>
); );
} }
function navigateToChat(id: string): void {
// Push history + dispatch popstate so React Router re-evaluates the route.
window.history.pushState(null, '', '/chats/' + id);
window.dispatchEvent(new PopStateEvent('popstate'));
}
function translateError(err: unknown, t: ReturnType<typeof useTranslation>['t']): string { function translateError(err: unknown, t: ReturnType<typeof useTranslation>['t']): string {
const code = extractErrorCode(err); const code = extractErrorCode(err);
if (code) return t('errors:' + code, { defaultValue: t('errors:generic') }); if (code) return t('errors:' + code, { defaultValue: t('errors:generic') });
@@ -241,8 +240,8 @@ function TabButton({
className={ className={
'-mb-px cursor-pointer border-b-2 px-3 pb-2.5 text-sm font-medium transition focus:outline-none ' + '-mb-px cursor-pointer border-b-2 px-3 pb-2.5 text-sm font-medium transition focus:outline-none ' +
(active (active
? 'border-brand-400 text-white' ? 'border-accent text-fg'
: 'border-transparent text-neutral-400 hover:text-neutral-200') : 'border-transparent text-fg-muted hover:text-fg')
} }
> >
{children} {children}
@@ -262,10 +261,11 @@ function FriendList({
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
if (items.length === 0) { if (items.length === 0) {
return ( return (
<div className="flex flex-1 flex-col items-center justify-center text-center text-sm text-neutral-500"> <div className="flex flex-1 flex-col items-center justify-center text-center text-sm text-fg-muted">
<div className="mb-3 flex h-12 w-12 items-center justify-center rounded-2xl border border-white/10 bg-white/5 text-neutral-400"> <div className="mb-3 flex h-12 w-12 items-center justify-center rounded-2xl border border-line bg-surface-2 text-fg-muted">
<UsersIcon className="h-5 w-5" /> <UsersIcon className="h-5 w-5" />
</div> </div>
<p>{t(emptyKey)}</p> <p>{t(emptyKey)}</p>
</div> </div>
); );
@@ -283,26 +283,21 @@ function FriendList({
function FriendRow({ profile, children }: { profile: ProfileBrief; children: React.ReactNode }) { function FriendRow({ profile, children }: { profile: ProfileBrief; children: React.ReactNode }) {
return ( return (
<div className="flex items-center gap-3 rounded-xl border border-white/5 bg-ink-900/50 px-4 py-3 backdrop-blur-sm"> <div className="flex items-center gap-3 rounded-xl border border-line bg-surface-2 px-4 py-3">
<Avatar profile={profile} /> <Avatar
url={profile.avatarUrl}
displayName={profile.displayName ?? profile.username}
className="h-9 w-9 text-sm"
/>
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="truncate text-sm font-semibold text-white">{profile.displayName}</p> <p className="truncate text-sm font-semibold text-fg">{profile.displayName}</p>
<p className="truncate text-xs text-neutral-500">@{profile.username}</p> <p className="truncate text-xs text-fg-muted">@{profile.username}</p>
</div> </div>
<div className="flex shrink-0 gap-2">{children}</div> <div className="flex shrink-0 gap-2">{children}</div>
</div> </div>
); );
} }
function Avatar({ profile }: { profile: ProfileBrief }) {
const letter = (profile.displayName ?? profile.username ?? '?').trim().charAt(0).toUpperCase();
return (
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-brand-500/30 text-sm font-semibold text-white ring-1 ring-brand-400/30">
{letter || '?'}
</div>
);
}
function FriendActions({ function FriendActions({
busy, busy,
onMessage, onMessage,
@@ -371,7 +366,7 @@ function PrimaryButton({
type="button" type="button"
disabled={busy} disabled={busy}
onClick={onClick} onClick={onClick}
className="inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-brand-500/90 px-3 py-1.5 text-xs font-semibold text-white transition hover:bg-brand-400 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 disabled:cursor-not-allowed disabled:opacity-60" className="inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-xs font-semibold text-accent-fg transition hover:brightness-110 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:cursor-not-allowed disabled:opacity-60"
> >
{busy ? <SpinnerIcon className="h-3.5 w-3.5" /> : icon} {busy ? <SpinnerIcon className="h-3.5 w-3.5" /> : icon}
<span>{children}</span> <span>{children}</span>
@@ -393,7 +388,7 @@ function SecondaryButton({
type="button" type="button"
disabled={busy} disabled={busy}
onClick={onClick} onClick={onClick}
className="inline-flex cursor-pointer items-center gap-1.5 rounded-md border border-white/10 bg-white/5 px-3 py-1.5 text-xs font-medium text-neutral-200 transition hover:bg-white/10 focus:outline-none focus-visible:ring-2 focus-visible:ring-white/30 disabled:cursor-not-allowed disabled:opacity-60" className="inline-flex cursor-pointer items-center gap-1.5 rounded-md border border-line bg-surface-3 px-3 py-1.5 text-xs font-medium text-fg transition hover:brightness-95 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/30 disabled:cursor-not-allowed disabled:opacity-60"
> >
{busy && <SpinnerIcon className="h-3.5 w-3.5" />} {busy && <SpinnerIcon className="h-3.5 w-3.5" />}
<span>{children}</span> <span>{children}</span>
@@ -415,7 +410,7 @@ function DangerButton({
type="button" type="button"
disabled={busy} disabled={busy}
onClick={onClick} onClick={onClick}
className="inline-flex cursor-pointer items-center gap-1.5 rounded-md border border-rose-500/30 bg-rose-500/10 px-3 py-1.5 text-xs font-medium text-rose-200 transition hover:bg-rose-500/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-rose-400/40 disabled:cursor-not-allowed disabled:opacity-60" className="inline-flex cursor-pointer items-center gap-1.5 rounded-md border border-rose-500/40 bg-rose-500/10 px-3 py-1.5 text-xs font-medium text-rose-600 transition hover:bg-rose-500/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-rose-400/40 disabled:cursor-not-allowed disabled:opacity-60 dark:text-rose-300"
> >
{busy && <SpinnerIcon className="h-3.5 w-3.5" />} {busy && <SpinnerIcon className="h-3.5 w-3.5" />}
<span>{children}</span> <span>{children}</span>
@@ -425,8 +420,8 @@ function DangerButton({
function LoadingRow() { function LoadingRow() {
return ( return (
<div className="flex items-center gap-3 text-sm text-neutral-500"> <div className="flex items-center gap-3 text-sm text-fg-muted">
<SpinnerIcon className="h-4 w-4 text-brand-400" /> <SpinnerIcon className="h-4 w-4 text-accent" />
<span></span> <span></span>
</div> </div>
); );
@@ -440,14 +435,14 @@ function Banner({ kind, children }: { kind: 'error' | 'info'; children: React.Re
className={ className={
'flex items-start gap-3 rounded-lg border p-3 text-sm ' + 'flex items-start gap-3 rounded-lg border p-3 text-sm ' +
(isError (isError
? 'border-rose-500/20 bg-rose-500/10 text-rose-100' ? 'border-rose-500/30 bg-rose-500/10 text-rose-700 dark:text-rose-100'
: 'border-emerald-500/20 bg-emerald-500/10 text-emerald-100') : 'border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-100')
} }
> >
{isError ? ( {isError ? (
<AlertIcon className="mt-0.5 h-5 w-5 shrink-0 text-rose-400" /> <AlertIcon className="mt-0.5 h-5 w-5 shrink-0 text-rose-500 dark:text-rose-400" />
) : ( ) : (
<CheckCircleIcon className="mt-0.5 h-5 w-5 shrink-0 text-emerald-400" /> <CheckCircleIcon className="mt-0.5 h-5 w-5 shrink-0 text-emerald-600 dark:text-emerald-400" />
)} )}
<p className="min-w-0 flex-1 break-words">{children}</p> <p className="min-w-0 flex-1 break-words">{children}</p>
</div> </div>
@@ -474,24 +469,24 @@ function SearchResults({
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
if (query.length < 2) { if (query.length < 2) {
return <p className="text-xs text-neutral-500">{t('app:friends.search_min_chars')}</p>; return <p className="text-xs text-fg-muted">{t('app:friends.search_min_chars')}</p>;
} }
if (searching) { if (searching) {
return ( return (
<div className="flex items-center gap-2 text-xs text-neutral-500"> <div className="flex items-center gap-2 text-xs text-fg-muted">
<SpinnerIcon className="h-3.5 w-3.5 text-brand-400" /> <SpinnerIcon className="h-3.5 w-3.5 text-accent" />
<span></span> <span></span>
</div> </div>
); );
} }
if (error) return <Banner kind="error">{error}</Banner>; if (error) return <Banner kind="error">{error}</Banner>;
if (results.length === 0) { if (results.length === 0) {
return <p className="text-xs text-neutral-500">{t('app:friends.search_no_results')}</p>; return <p className="text-xs text-fg-muted">{t('app:friends.search_no_results')}</p>;
} }
return ( return (
<div> <div>
<p className="mb-2 text-xs font-medium uppercase tracking-wide text-neutral-500"> <p className="mb-2 text-xs font-medium uppercase tracking-[0.1em] text-fg-muted">
{t('app:friends.search_results_title')} {t('app:friends.search_results_title')}
</p> </p>
<ul className="space-y-1.5"> <ul className="space-y-1.5">
@@ -530,7 +525,7 @@ function SearchActionButton({
if (existing?.status === 'accepted') { if (existing?.status === 'accepted') {
return ( return (
<span className="inline-flex items-center gap-1.5 rounded-md border border-emerald-500/20 bg-emerald-500/10 px-3 py-1.5 text-xs font-medium text-emerald-200"> <span className="inline-flex items-center gap-1.5 rounded-md border border-emerald-500/30 bg-emerald-500/10 px-3 py-1.5 text-xs font-medium text-emerald-700 dark:text-emerald-200">
<CheckCircleIcon className="h-3.5 w-3.5" /> <CheckCircleIcon className="h-3.5 w-3.5" />
{t('app:friends.already_friends')} {t('app:friends.already_friends')}
</span> </span>
@@ -539,7 +534,7 @@ function SearchActionButton({
if (existing?.status === 'pending' && existing.direction === 'outgoing') { if (existing?.status === 'pending' && existing.direction === 'outgoing') {
return ( return (
<span className="inline-flex items-center gap-1.5 rounded-md border border-white/10 bg-white/5 px-3 py-1.5 text-xs text-neutral-300"> <span className="inline-flex items-center gap-1.5 rounded-md border border-line bg-surface-2 px-3 py-1.5 text-xs text-fg-muted">
{t('app:friends.request_sent')} {t('app:friends.request_sent')}
</span> </span>
); );
+391 -164
View File
@@ -4,13 +4,16 @@ import {
SUPPORTED_LOCALES, SUPPORTED_LOCALES,
type SupportedLocale, type SupportedLocale,
} from '@chat-app/shared/i18n'; } from '@chat-app/shared/i18n';
import { useEffect, useState } from 'react'; import { useCallback, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Avatar } from '../components/Avatar';
import { BackupExportDialog } from '../components/BackupExportDialog';
import { LockIcon } from '../components/icons'; import { LockIcon } from '../components/icons';
import { useAuth } from '../context/AuthContext'; import { useAuth } from '../context/AuthContext';
import { loadDevicePrivateKey, saveDevicePrivateKey } from '@chat-app/shared/auth'; import { useCall } from '../context/CallContext';
import { exportDeviceKey, importDeviceKey } from '../lib/deviceBackup'; import { loadDevicePrivateKey } from '@chat-app/shared/auth';
import { deleteAvatarObject, uploadAvatar } from '../lib/avatarUpload';
import { devLocalSecretStore } from '../lib/secretStore'; import { devLocalSecretStore } from '../lib/secretStore';
import { import {
getPttSettings, getPttSettings,
@@ -74,15 +77,20 @@ export function SettingsPage() {
} }
return ( return (
<div className="mx-auto flex max-w-3xl flex-col gap-6 px-6 py-8"> <div className="min-h-full bg-surface-3 text-fg">
<div className="mx-auto flex max-w-3xl flex-col gap-6 px-6 py-8">
<header className="mb-2"> <header className="mb-2">
<h1 className="font-display text-2xl font-semibold tracking-tight text-white"> <h1 className="font-display text-2xl font-semibold tracking-tight text-fg">
{t('app:settings.title')} {t('app:settings.title')}
</h1> </h1>
</header> </header>
{/* Account */} {/* Account */}
<Section title={t('app:settings.section_account')}> <Section title={t('app:settings.section_account')}>
<AvatarControls
patchProfile={patchProfile}
busy={busy}
/>
<Row label={t('auth:signed_in.username')} value={profile?.username ?? '—'} /> <Row label={t('auth:signed_in.username')} value={profile?.username ?? '—'} />
<Row label={t('auth:signed_in.display_name')} value={profile?.displayName ?? '—'} /> <Row label={t('auth:signed_in.display_name')} value={profile?.displayName ?? '—'} />
<Row label={t('auth:signed_in.email')} value={profile?.userId ?? '—'} mono /> <Row label={t('auth:signed_in.email')} value={profile?.userId ?? '—'} mono />
@@ -91,7 +99,7 @@ export function SettingsPage() {
{/* Appearance */} {/* Appearance */}
<Section title={t('app:settings.section_appearance')}> <Section title={t('app:settings.section_appearance')}>
<SettingRow label={t('app:settings.language')}> <SettingRow label={t('app:settings.language')}>
<div className="inline-flex rounded-lg border border-white/10 bg-ink-800 p-1"> <div className="inline-flex rounded-lg border border-line bg-surface-3 p-1">
{SUPPORTED_LOCALES.map((locale) => { {SUPPORTED_LOCALES.map((locale) => {
const active = (i18n.resolvedLanguage ?? i18n.language) === locale; const active = (i18n.resolvedLanguage ?? i18n.language) === locale;
return ( return (
@@ -101,10 +109,10 @@ export function SettingsPage() {
disabled={busy} disabled={busy}
onClick={() => void handleLocaleChange(locale)} onClick={() => void handleLocaleChange(locale)}
className={ className={
'cursor-pointer rounded-md px-3 py-1.5 text-xs font-medium transition focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 ' + 'cursor-pointer rounded-md px-3 py-1.5 text-xs font-medium transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ' +
(active (active
? 'bg-brand-500/25 text-white ring-1 ring-brand-400/40' ? 'bg-accent text-accent-fg'
: 'text-neutral-400 hover:text-neutral-200') : 'text-fg-muted hover:text-fg')
} }
> >
{LOCALE_LABELS[locale]} {LOCALE_LABELS[locale]}
@@ -135,11 +143,14 @@ export function SettingsPage() {
{/* Voice / Push-to-Talk + Audio Quality + E2EE */} {/* Voice / Push-to-Talk + Audio Quality + E2EE */}
<Section title={t('app:settings.section_voice', { defaultValue: 'Sprache' })}> <Section title={t('app:settings.section_voice', { defaultValue: 'Sprache' })}>
<AudioQualityControls /> <AudioDeviceControls />
<div className="mt-3 border-t border-white/5 pt-3"> <div className="mt-3 border-t border-line pt-3">
<AudioQualityControls />
</div>
<div className="mt-3 border-t border-line pt-3">
<PttControls /> <PttControls />
</div> </div>
<div className="mt-3 border-t border-white/5 pt-3"> <div className="mt-3 border-t border-line pt-3">
<CallE2EEControls /> <CallE2EEControls />
</div> </div>
</Section> </Section>
@@ -152,8 +163,8 @@ export function SettingsPage() {
{/* Devices */} {/* Devices */}
<Section title={t('app:settings.section_devices')}> <Section title={t('app:settings.section_devices')}>
{device && ( {device && (
<div className="rounded-xl border border-emerald-500/20 bg-emerald-500/5 p-4"> <div className="rounded-xl border border-emerald-500/30 bg-emerald-500/10 p-4">
<div className="flex items-center gap-2 text-sm font-semibold text-emerald-200"> <div className="flex items-center gap-2 text-sm font-semibold text-emerald-700 dark:text-emerald-200">
<LockIcon className="h-4 w-4" /> <LockIcon className="h-4 w-4" />
{t('app:settings.this_device')} {t('app:settings.this_device')}
</div> </div>
@@ -172,11 +183,12 @@ export function SettingsPage() {
<button <button
type="button" type="button"
onClick={() => void signOut()} onClick={() => void signOut()}
className="cursor-pointer rounded-lg border border-rose-500/30 bg-rose-500/10 px-4 py-2.5 text-sm font-semibold text-rose-200 transition hover:bg-rose-500/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-rose-400/50" className="cursor-pointer rounded-lg border border-rose-500/40 bg-rose-500/10 px-4 py-2.5 text-sm font-semibold text-rose-600 transition hover:bg-rose-500/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-rose-400/50 dark:text-rose-300"
> >
{t('app:settings.sign_out')} {t('app:settings.sign_out')}
</button> </button>
</Section> </Section>
</div>
</div> </div>
); );
} }
@@ -223,10 +235,10 @@ function PttControls() {
type="button" type="button"
onClick={() => setCapturing((v) => !v)} onClick={() => setCapturing((v) => !v)}
className={ className={
'inline-flex min-w-[7rem] cursor-pointer items-center justify-center rounded-lg border px-3 py-1.5 text-xs font-mono font-semibold transition focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 ' + 'inline-flex min-w-[7rem] cursor-pointer items-center justify-center rounded-lg border px-3 py-1.5 text-xs font-mono font-semibold transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ' +
(capturing (capturing
? 'border-brand-400 bg-brand-500/20 text-white animate-pulse' ? 'border-accent bg-accent/20 text-fg animate-pulse'
: 'border-white/10 bg-ink-800 text-neutral-200 hover:bg-ink-700') : 'border-line bg-surface-3 text-fg hover:brightness-95')
} }
> >
{capturing {capturing
@@ -283,7 +295,7 @@ function AudioQualityControls() {
return ( return (
<> <>
<SettingRow label={t('app:settings.audio_quality', { defaultValue: 'Audio-Qualität' })}> <SettingRow label={t('app:settings.audio_quality', { defaultValue: 'Audio-Qualität' })}>
<div className="inline-flex rounded-lg border border-white/10 bg-ink-800 p-1"> <div className="inline-flex rounded-lg border border-line bg-surface-2 p-1">
{AUDIO_QUALITY_ORDER.map((q) => { {AUDIO_QUALITY_ORDER.map((q) => {
const active = cfg.quality === q; const active = cfg.quality === q;
return ( return (
@@ -292,10 +304,10 @@ function AudioQualityControls() {
type="button" type="button"
onClick={() => updateAudioSettings({ quality: q })} onClick={() => updateAudioSettings({ quality: q })}
className={ className={
'cursor-pointer rounded-md px-3 py-1 text-xs font-medium transition focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40 ' + 'cursor-pointer rounded-md px-3 py-1 text-xs font-medium transition focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ' +
(active (active
? 'bg-brand-500/25 text-white ring-1 ring-brand-400/40' ? 'bg-accent text-accent-fg'
: 'text-neutral-400 hover:text-neutral-200') : 'text-fg-muted hover:text-fg')
} }
> >
{labels[q]} {labels[q]}
@@ -304,7 +316,7 @@ function AudioQualityControls() {
})} })}
</div> </div>
</SettingRow> </SettingRow>
<div className="rounded-lg border border-white/5 bg-ink-900/40 p-3 text-[11px] text-neutral-400"> <div className="rounded-lg border border-line bg-surface-3 p-3 text-[11px] text-fg-muted">
<div className="grid grid-cols-4 gap-3"> <div className="grid grid-cols-4 gap-3">
<Stat label="Bitrate" value={params.bitrateKbps + ' kbps'} /> <Stat label="Bitrate" value={params.bitrateKbps + ' kbps'} />
<Stat label="Channels" value={params.stereo ? 'Stereo' : 'Mono'} /> <Stat label="Channels" value={params.stereo ? 'Stereo' : 'Mono'} />
@@ -312,7 +324,7 @@ function AudioQualityControls() {
<Stat label="DSP" value={params.echoCancellation ? 'On' : 'Off'} /> <Stat label="DSP" value={params.echoCancellation ? 'On' : 'Off'} />
</div> </div>
</div> </div>
<p className="text-xs text-neutral-500"> <p className="text-xs text-fg-muted">
{cfg.quality === 'hifi' {cfg.quality === 'hifi'
? t('app:settings.audio_hifi_hint', { ? t('app:settings.audio_hifi_hint', {
defaultValue: defaultValue:
@@ -327,155 +339,177 @@ function AudioQualityControls() {
); );
} }
function DeviceKeyBackupControls() { interface AvatarControlsProps {
patchProfile: (patch: Parameters<typeof updateOwnProfile>[1]) => Promise<void>;
busy: boolean;
}
function AvatarControls({ patchProfile, busy }: AvatarControlsProps) {
const { t } = useTranslation(['app']); const { t } = useTranslation(['app']);
const { profile, device } = useAuth(); const { profile } = useAuth();
const [busy, setBusy] = useState(false); const inputRef = useRef<HTMLInputElement | null>(null);
const [backupOut, setBackupOut] = useState<string | null>(null); const [uploading, setUploading] = useState(false);
const [exportPass, setExportPass] = useState(''); const [error, setError] = useState<string | null>(null);
const [importPass, setImportPass] = useState('');
const [importBlob, setImportBlob] = useState('');
const [msg, setMsg] = useState<{ kind: 'ok' | 'err'; text: string } | null>(null);
const canRun = !!profile?.userId && !!device?.id; const userId = profile?.userId;
const url = profile?.avatarUrl ?? null;
async function handleExport() { async function handleFile(file: File) {
if (!canRun) return; if (!userId) return;
setMsg(null); setError(null);
setBusy(true); setUploading(true);
try { try {
const priv = await loadDevicePrivateKey(devLocalSecretStore, profile.userId, device.id); const newUrl = await uploadAvatar(userId, file);
if (!priv) throw new Error('No device key on this install'); const oldUrl = url;
const out = await exportDeviceKey(priv, exportPass); await patchProfile({ avatarUrl: newUrl });
setBackupOut(out); if (oldUrl) {
setExportPass(''); // Best-effort cleanup of the previous file (don't block on it).
setMsg({ void deleteAvatarObject(oldUrl).catch(() => {
kind: 'ok', /* ignore */
text: t('app:settings.backup_export_ok', { });
defaultValue: 'Backup erstellt — kopiere und bewahre es sicher auf.', }
}),
});
} catch (err: unknown) { } catch (err: unknown) {
setMsg({ setError(err instanceof Error ? err.message : 'upload failed');
kind: 'err',
text: err instanceof Error ? err.message : 'export failed',
});
} finally { } finally {
setBusy(false); setUploading(false);
if (inputRef.current) inputRef.current.value = '';
} }
} }
async function handleImport() { async function handleRemove() {
if (!canRun) return; if (!userId || !url) return;
setMsg(null); setError(null);
setBusy(true); setUploading(true);
try { try {
const priv = await importDeviceKey(importBlob.trim(), importPass); await patchProfile({ avatarUrl: null });
await saveDevicePrivateKey(devLocalSecretStore, profile.userId, device.id, priv); void deleteAvatarObject(url).catch(() => undefined);
setImportBlob('');
setImportPass('');
setMsg({
kind: 'ok',
text: t('app:settings.backup_import_ok', {
defaultValue:
'Schlüssel importiert. Beim nächsten Reload sollten alte Nachrichten lesbar sein.',
}),
});
} catch (err: unknown) { } catch (err: unknown) {
setMsg({ setError(err instanceof Error ? err.message : 'remove failed');
kind: 'err',
text: err instanceof Error ? err.message : 'import failed',
});
} finally { } finally {
setBusy(false); setUploading(false);
} }
} }
return ( return (
<div className="mt-4 rounded-xl border border-white/10 bg-ink-900/40 p-4"> <div className="flex items-center gap-4">
<div className="text-sm font-semibold text-white"> <Avatar
{t('app:settings.device_key_backup', { defaultValue: 'Geräteschlüssel-Backup' })} url={url}
</div> displayName={profile?.displayName ?? profile?.username}
<p className="mt-1 text-xs text-neutral-400"> className="h-16 w-16 text-2xl"
{t('app:settings.device_key_backup_hint', { />
defaultValue:
'Sichere deinen privaten Schlüssel passwortgeschützt, damit du auf neuen Geräten alte Nachrichten weiter lesen kannst.',
})}
</p>
<div className="mt-4 space-y-2"> <div className="flex flex-1 flex-col gap-1">
<div className="text-xs font-semibold uppercase tracking-wide text-neutral-500"> <div className="text-sm font-medium text-fg">
{t('app:settings.backup_export', { defaultValue: 'Export' })} {t('app:settings.avatar', { defaultValue: 'Avatar' })}
</div> </div>
<div className="flex gap-2"> <div className="text-xs text-fg-muted">
<input {t('app:settings.avatar_hint', {
type="password" defaultValue: 'Quadratisch, max 512×512, WebP. Sichtbar für deine Freunde.',
value={exportPass} })}
onChange={(e) => setExportPass(e.target.value)}
placeholder={t('app:settings.backup_passphrase', { defaultValue: 'Passphrase (min 8)' })}
className="flex-1 rounded-lg border border-white/10 bg-ink-800 px-3 py-2 text-sm text-white placeholder-neutral-500 focus:border-brand-400 focus:outline-none"
/>
<button
type="button"
disabled={busy || exportPass.length < 8 || !canRun}
onClick={() => void handleExport()}
className="cursor-pointer rounded-lg bg-brand-500/80 px-4 text-sm font-semibold text-white transition hover:bg-brand-400 disabled:cursor-not-allowed disabled:opacity-50"
>
{t('app:settings.backup_create', { defaultValue: 'Erstellen' })}
</button>
</div> </div>
{backupOut && ( {error && (
<textarea <div className="text-xs text-rose-500 dark:text-rose-300">{error}</div>
readOnly
value={backupOut}
onClick={(e) => (e.target as HTMLTextAreaElement).select()}
rows={3}
className="w-full rounded-lg border border-emerald-500/30 bg-ink-950/60 p-2 font-mono text-[10px] text-emerald-200"
/>
)} )}
</div> </div>
<div className="mt-4 space-y-2 border-t border-white/5 pt-4"> <input
<div className="text-xs font-semibold uppercase tracking-wide text-neutral-500"> ref={inputRef}
{t('app:settings.backup_import', { defaultValue: 'Import' })} type="file"
</div> accept="image/*"
<textarea className="hidden"
value={importBlob} onChange={(e) => {
onChange={(e) => setImportBlob(e.target.value)} const f = e.target.files?.[0];
rows={3} if (f) void handleFile(f);
placeholder={t('app:settings.backup_blob_placeholder', { }}
defaultValue: 'chatapp-backup-v1.…', />
})} <button
className="w-full rounded-lg border border-white/10 bg-ink-800 p-2 font-mono text-[11px] text-white placeholder-neutral-500 focus:border-brand-400 focus:outline-none" type="button"
/> onClick={() => inputRef.current?.click()}
<div className="flex gap-2"> disabled={busy || uploading}
<input className="cursor-pointer rounded-lg bg-accent px-3 py-1.5 text-xs font-semibold text-accent-fg transition hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-50"
type="password" >
value={importPass} {uploading
onChange={(e) => setImportPass(e.target.value)} ? t('app:settings.avatar_uploading', { defaultValue: 'Lade…' })
placeholder={t('app:settings.backup_passphrase', { defaultValue: 'Passphrase' })} : url
className="flex-1 rounded-lg border border-white/10 bg-ink-800 px-3 py-2 text-sm text-white placeholder-neutral-500 focus:border-brand-400 focus:outline-none" ? t('app:settings.avatar_change', { defaultValue: 'Ändern' })
/> : t('app:settings.avatar_upload', { defaultValue: 'Hochladen' })}
<button </button>
type="button" {url && (
disabled={busy || !importBlob || !importPass || !canRun} <button
onClick={() => void handleImport()} type="button"
className="cursor-pointer rounded-lg bg-emerald-500/80 px-4 text-sm font-semibold text-white transition hover:bg-emerald-400 disabled:cursor-not-allowed disabled:opacity-50" onClick={() => void handleRemove()}
> disabled={busy || uploading}
{t('app:settings.backup_restore', { defaultValue: 'Wiederherstellen' })} className="cursor-pointer rounded-lg border border-rose-500/40 bg-rose-500/10 px-3 py-1.5 text-xs font-semibold text-rose-600 transition hover:bg-rose-500/20 disabled:cursor-not-allowed disabled:opacity-50 dark:text-rose-300"
</button>
</div>
</div>
{msg && (
<p
className={
'mt-3 text-xs ' +
(msg.kind === 'ok' ? 'text-emerald-300' : 'text-rose-300')
}
> >
{msg.text} {t('app:settings.avatar_remove', { defaultValue: 'Entfernen' })}
</p> </button>
)}
</div>
);
}
function DeviceKeyBackupControls() {
const { t } = useTranslation(['app']);
const { profile, device } = useAuth();
const [open, setOpen] = useState(false);
const [privateKey, setPrivateKey] = useState<Uint8Array | null>(null);
const [err, setErr] = useState<string | null>(null);
const canRun = !!profile?.userId && !!device?.id;
async function handleOpen() {
if (!canRun) return;
setErr(null);
try {
const priv = await loadDevicePrivateKey(devLocalSecretStore, profile.userId, device.id);
if (!priv) throw new Error(t('app:backup.no_key_here', {
defaultValue: 'Kein Geräteschlüssel auf dieser Installation.',
}));
setPrivateKey(priv);
setOpen(true);
} catch (e: unknown) {
setErr(e instanceof Error ? e.message : 'failed to load key');
}
}
function handleClose() {
setOpen(false);
if (privateKey) {
for (let i = 0; i < privateKey.length; i++) privateKey[i] = 0;
}
setPrivateKey(null);
}
return (
<div className="mt-4 rounded-xl border border-line bg-surface-3 p-4">
<div className="text-sm font-semibold text-fg">
{t('app:settings.device_key_backup', { defaultValue: 'Geräteschlüssel-Backup' })}
</div>
<p className="mt-1 text-xs text-fg-muted">
{t('app:settings.device_key_backup_hint_v2', {
defaultValue:
'Backup deines Geräteschlüssels. Ohne Backup kein Zugriff auf alte Nachrichten wenn Gerät oder Browser-Storage verloren geht. Wiederherstellung passiert im Gerät-Einrichtungsbildschirm.',
})}
</p>
<button
type="button"
disabled={!canRun}
onClick={() => void handleOpen()}
className="mt-3 inline-flex cursor-pointer items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-sm font-semibold text-accent-fg transition hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-50"
>
{t('app:backup.export_open', { defaultValue: 'Backup erstellen' })}
</button>
{err && (
<p className="mt-2 text-xs text-rose-600 dark:text-rose-300">{err}</p>
)}
{open && profile && device && privateKey && (
<BackupExportDialog
open={open}
userId={profile.userId}
deviceId={device.id}
privateKey={privateKey}
onClose={handleClose}
/>
)} )}
</div> </div>
); );
@@ -497,7 +531,7 @@ function ScreenShareControls() {
onChange={(e) => onChange={(e) =>
updateScreenShareSettings({ preset: e.target.value as ScreenSharePreset }) updateScreenShareSettings({ preset: e.target.value as ScreenSharePreset })
} }
className="cursor-pointer rounded-lg border border-white/10 bg-ink-800 px-3 py-1.5 text-xs text-neutral-200 focus:border-brand-400 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400/40" className="cursor-pointer rounded-lg border border-line bg-surface-3 px-3 py-1.5 text-xs text-fg focus:border-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"
> >
{PRESET_ORDER.map((p) => ( {PRESET_ORDER.map((p) => (
<option key={p} value={p}> <option key={p} value={p}>
@@ -506,7 +540,7 @@ function ScreenShareControls() {
))} ))}
</select> </select>
</SettingRow> </SettingRow>
<div className="rounded-lg border border-white/5 bg-ink-900/40 p-3 text-[11px] text-neutral-400"> <div className="rounded-lg border border-line bg-surface-3 p-3 text-[11px] text-fg-muted">
<div className="grid grid-cols-3 gap-3"> <div className="grid grid-cols-3 gap-3">
<Stat label="Bitrate (max)" value={formatBitrate(params.bitrateKbps)} /> <Stat label="Bitrate (max)" value={formatBitrate(params.bitrateKbps)} />
<Stat <Stat
@@ -516,7 +550,7 @@ function ScreenShareControls() {
<Stat label="Framerate" value={params.framerate + ' fps'} /> <Stat label="Framerate" value={params.framerate + ' fps'} />
</div> </div>
</div> </div>
<p className="text-xs text-neutral-500"> <p className="text-xs text-fg-muted">
{t('app:settings.screen_share_hint', { {t('app:settings.screen_share_hint', {
defaultValue: defaultValue:
'WebRTC passt Bitrate + Auflösung dynamisch an die Netzwerkqualität an (SVC/VP9). Die Werte sind Obergrenzen. Änderungen greifen beim nächsten Call.', 'WebRTC passt Bitrate + Auflösung dynamisch an die Netzwerkqualität an (SVC/VP9). Die Werte sind Obergrenzen. Änderungen greifen beim nächsten Call.',
@@ -529,8 +563,8 @@ function ScreenShareControls() {
function Stat({ label, value }: { label: string; value: string }) { function Stat({ label, value }: { label: string; value: string }) {
return ( return (
<div> <div>
<div className="text-[10px] uppercase tracking-wide text-neutral-500">{label}</div> <div className="text-[10px] uppercase tracking-[0.1em] text-fg-muted">{label}</div>
<div className="mt-0.5 font-mono text-neutral-200">{value}</div> <div className="mt-0.5 font-mono text-fg">{value}</div>
</div> </div>
); );
} }
@@ -544,8 +578,8 @@ function formatBitrate(kbps: number): string {
function Section({ title, children }: { title: string; children: React.ReactNode }) { function Section({ title, children }: { title: string; children: React.ReactNode }) {
return ( return (
<section className="rounded-2xl border border-white/10 bg-ink-900/60 p-5 backdrop-blur-xl"> <section className="rounded-2xl border border-line bg-surface-2 p-5">
<h2 className="mb-4 text-xs font-semibold uppercase tracking-wide text-neutral-400"> <h2 className="mb-4 text-xs font-semibold uppercase tracking-[0.1em] text-fg-muted">
{title} {title}
</h2> </h2>
<div className="space-y-3">{children}</div> <div className="space-y-3">{children}</div>
@@ -556,10 +590,10 @@ function Section({ title, children }: { title: string; children: React.ReactNode
function Row({ label, value, mono }: { label: string; value: string; mono?: boolean }) { function Row({ label, value, mono }: { label: string; value: string; mono?: boolean }) {
return ( return (
<div className="flex items-center justify-between gap-4"> <div className="flex items-center justify-between gap-4">
<dt className="text-sm text-neutral-500">{label}</dt> <dt className="text-sm text-fg-muted">{label}</dt>
<dd <dd
className={ className={
'max-w-[60%] truncate text-right text-sm text-neutral-200 ' + 'max-w-[60%] truncate text-right text-sm text-fg ' +
(mono ? 'font-mono text-xs' : '') (mono ? 'font-mono text-xs' : '')
} }
title={value} title={value}
@@ -573,7 +607,7 @@ function Row({ label, value, mono }: { label: string; value: string; mono?: bool
function SettingRow({ label, children }: { label: string; children: React.ReactNode }) { function SettingRow({ label, children }: { label: string; children: React.ReactNode }) {
return ( return (
<div className="flex items-center justify-between gap-4"> <div className="flex items-center justify-between gap-4">
<span className="text-sm text-neutral-200">{label}</span> <span className="text-sm text-fg">{label}</span>
{children} {children}
</div> </div>
); );
@@ -595,8 +629,8 @@ function Toggle({
return ( return (
<label className="flex cursor-pointer items-start justify-between gap-4"> <label className="flex cursor-pointer items-start justify-between gap-4">
<span className="min-w-0 flex-1"> <span className="min-w-0 flex-1">
<span className="block text-sm text-neutral-200">{label}</span> <span className="block text-sm text-fg">{label}</span>
{hint && <span className="mt-1 block text-xs text-neutral-500">{hint}</span>} {hint && <span className="mt-1 block text-xs text-fg-muted">{hint}</span>}
</span> </span>
<span className="relative mt-0.5 inline-flex h-6 w-11 shrink-0"> <span className="relative mt-0.5 inline-flex h-6 w-11 shrink-0">
<input <input
@@ -606,9 +640,202 @@ function Toggle({
onChange={(e) => onChange(e.target.checked)} onChange={(e) => onChange(e.target.checked)}
className="peer sr-only" className="peer sr-only"
/> />
<span className="inline-block h-6 w-11 rounded-full bg-neutral-700 transition peer-checked:bg-brand-500/70 peer-disabled:opacity-50" /> <span className="inline-block h-6 w-11 rounded-full bg-surface transition peer-checked:bg-accent peer-disabled:opacity-50" />
<span className="absolute left-0.5 top-0.5 h-5 w-5 rounded-full bg-white transition peer-checked:translate-x-5" /> <span className="absolute left-0.5 top-0.5 h-5 w-5 rounded-full bg-white shadow transition peer-checked:translate-x-5" />
</span> </span>
</label> </label>
); );
} }
// ---------------------------------------------------------------------------
// Audio device selection — persisted input + output deviceIds, hot-swap on
// active calls. Output swap uses HTMLMediaElement.setSinkId on our attached
// <audio> elements (LiveKit's switchActiveDevice only tracks elements it
// attached itself).
// ---------------------------------------------------------------------------
function AudioDeviceControls() {
const { t } = useTranslation(['app']);
const { setAudioInputDevice, setAudioOutputDevice } = useCall();
const [inputs, setInputs] = useState<MediaDeviceInfo[]>([]);
const [outputs, setOutputs] = useState<MediaDeviceInfo[]>([]);
const [inputId, setInputId] = useState<string | null>(
() => getAudioSettings().inputDeviceId,
);
const [outputId, setOutputId] = useState<string | null>(
() => getAudioSettings().outputDeviceId,
);
const [error, setError] = useState<string | null>(null);
const [permission, setPermission] = useState<'unknown' | 'granted' | 'denied'>(
'unknown',
);
const refresh = useCallback(async () => {
try {
const list = await navigator.mediaDevices.enumerateDevices();
setInputs(list.filter((d) => d.kind === 'audioinput'));
setOutputs(list.filter((d) => d.kind === 'audiooutput'));
// If labels are empty, permission hasn't been granted yet — browsers
// mask device names until a getUserMedia call succeeds at least once.
const hasLabels = list.some(
(d) => (d.kind === 'audioinput' || d.kind === 'audiooutput') && d.label.length > 0,
);
setPermission(hasLabels ? 'granted' : 'unknown');
} catch (err: unknown) {
setError(err instanceof Error ? err.message : 'enumerateDevices failed');
}
}, []);
useEffect(() => {
void refresh();
const onChange = () => void refresh();
try {
navigator.mediaDevices.addEventListener('devicechange', onChange);
} catch {
/* some browsers omit devicechange */
}
const unsubSettings = subscribeAudioSettings((s) => {
setInputId(s.inputDeviceId);
setOutputId(s.outputDeviceId);
});
return () => {
try {
navigator.mediaDevices.removeEventListener('devicechange', onChange);
} catch {
/* ignore */
}
unsubSettings();
};
}, [refresh]);
const requestPermission = useCallback(async () => {
setError(null);
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
stream.getTracks().forEach((t) => t.stop());
setPermission('granted');
await refresh();
} catch (err: unknown) {
setPermission('denied');
setError(err instanceof Error ? err.message : 'permission denied');
}
}, [refresh]);
const handleInput = useCallback(
async (id: string) => {
const next = id === '' ? null : id;
setInputId(next);
await setAudioInputDevice(next);
},
[setAudioInputDevice],
);
const handleOutput = useCallback(
async (id: string) => {
const next = id === '' ? null : id;
setOutputId(next);
await setAudioOutputDevice(next);
},
[setAudioOutputDevice],
);
const outputSupported =
typeof HTMLAudioElement !== 'undefined' &&
typeof HTMLAudioElement.prototype.setSinkId === 'function';
return (
<div className="space-y-4">
<div>
<div className="text-sm font-semibold text-fg">
{t('app:settings.mic_title', { defaultValue: 'Mikrofon' })}
</div>
<p className="mt-1 text-xs text-fg-muted">
{t('app:settings.mic_hint', {
defaultValue: 'Eingabegerät. Bei aktivem Anruf wird live umgeschaltet.',
})}
</p>
<div className="mt-2 flex items-center gap-2">
<select
value={inputId ?? ''}
onChange={(e) => void handleInput(e.target.value)}
className="flex-1 rounded-lg border border-line bg-surface-2 px-3 py-2 text-sm text-fg focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/30"
>
<option value="">
{t('app:settings.mic_default', { defaultValue: 'Systemstandard' })}
</option>
{inputs.map((d) => (
<option key={d.deviceId} value={d.deviceId}>
{d.label || t('app:settings.mic_unnamed', { defaultValue: 'Unbenannt' })}
</option>
))}
</select>
<button
type="button"
onClick={() => void refresh()}
className="cursor-pointer rounded-lg border border-line bg-surface-2 px-3 py-2 text-xs font-medium text-fg transition hover:bg-surface-3"
>
{t('app:settings.mic_refresh', { defaultValue: 'Neu laden' })}
</button>
</div>
</div>
<div>
<div className="text-sm font-semibold text-fg">
{t('app:settings.speaker_title', { defaultValue: 'Ausgabegerät' })}
</div>
<p className="mt-1 text-xs text-fg-muted">
{t('app:settings.speaker_hint', {
defaultValue:
'Lautsprecher oder Kopfhörer. Wird auf alle aktiven Audio-Streams angewendet.',
})}
</p>
{!outputSupported && (
<p className="mt-1 text-xs text-amber-600 dark:text-amber-300">
{t('app:settings.speaker_unsupported', {
defaultValue: 'Browser unterstützt setSinkId nicht — Ausgabe folgt System-Default.',
})}
</p>
)}
<div className="mt-2 flex items-center gap-2">
<select
value={outputId ?? ''}
disabled={!outputSupported}
onChange={(e) => void handleOutput(e.target.value)}
className="flex-1 rounded-lg border border-line bg-surface-2 px-3 py-2 text-sm text-fg focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/30 disabled:opacity-50"
>
<option value="">
{t('app:settings.mic_default', { defaultValue: 'Systemstandard' })}
</option>
{outputs.map((d) => (
<option key={d.deviceId} value={d.deviceId}>
{d.label || t('app:settings.mic_unnamed', { defaultValue: 'Unbenannt' })}
</option>
))}
</select>
</div>
</div>
{permission !== 'granted' && (
<div className="flex items-center justify-between gap-3 rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-xs text-amber-700 dark:text-amber-200">
<span>
{t('app:settings.mic_permission_hint', {
defaultValue:
'Ohne Mikrofon-Freigabe erscheinen Gerätenamen nicht. Einmal erlauben und Liste lädt neu.',
})}
</span>
<button
type="button"
onClick={() => void requestPermission()}
className="shrink-0 cursor-pointer rounded-md bg-amber-600 px-2.5 py-1 text-xs font-semibold text-white transition hover:bg-amber-500"
>
{t('app:settings.mic_grant', { defaultValue: 'Freigeben' })}
</button>
</div>
)}
{error && (
<p className="text-xs text-rose-600 dark:text-rose-300">{error}</p>
)}
</div>
);
}
+48 -6
View File
@@ -4,11 +4,42 @@
@tailwind components; @tailwind components;
@tailwind utilities; @tailwind utilities;
@layer base { /* ---------------------------------------------------------------------------
:root { * Clean-Rail design tokens.
color-scheme: dark; *
} * `--bg-rgb / --fg-rgb / --accent-rgb` are *space-separated rgb triplets*
* (no `rgb(...)` wrapper) so Tailwind's `rgb(var(--x) / <alpha-value>)`
* alpha modifier works (e.g. `bg-surface/40`).
*
* `--line` is a full color value with baked-in alpha — theme decides whether
* borders are inked-on-white or white-on-ink.
* ------------------------------------------------------------------------- */
:root {
--bg-rgb: 250 250 249;
--bg-2-rgb: 244 244 242;
--bg-3-rgb: 255 255 255;
--fg-rgb: 10 10 15;
--fg-muted-rgb: 115 115 128;
--accent-rgb: 79 70 229;
--accent-fg-rgb: 255 255 255;
--line: rgba(10, 10, 15, 0.08);
color-scheme: light;
}
.dark {
--bg-rgb: 5 5 7;
--bg-2-rgb: 17 17 24;
--bg-3-rgb: 10 10 15;
--fg-rgb: 244 244 245;
--fg-muted-rgb: 138 138 153;
--accent-rgb: 109 115 255;
--accent-fg-rgb: 255 255 255;
--line: rgba(255, 255, 255, 0.07);
color-scheme: dark;
}
@layer base {
html, html,
body, body,
#root { #root {
@@ -16,12 +47,12 @@
} }
body { body {
@apply bg-ink-950 text-neutral-100 font-sans antialiased; @apply bg-surface text-fg font-sans antialiased;
font-feature-settings: 'cv11', 'ss01'; font-feature-settings: 'cv11', 'ss01';
} }
::selection { ::selection {
@apply bg-brand-500/40 text-white; @apply bg-accent/40 text-white;
} }
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
@@ -46,4 +77,15 @@
background-size: 32px 32px; background-size: 32px 32px;
background-position: -1px -1px; background-position: -1px -1px;
} }
/* Glass pill used for the fullscreen call controls bar. */
.glass-pill {
background: rgba(10, 10, 15, 0.7);
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.glass-chip {
background: rgba(0, 0, 0, 0.55);
backdrop-filter: blur(10px);
color: #fff;
}
} }
+9
View File
@@ -0,0 +1,9 @@
// Shim sumo types to the non-sumo types package. sumo is an API superset of
// libsodium-wrappers; its runtime exports match the standard wrappers module
// and additionally include `crypto_pwhash` (Argon2id). Reuse the existing
// `@types/libsodium-wrappers` definitions rather than duplicating them.
declare module 'libsodium-wrappers-sumo' {
import sodium from 'libsodium-wrappers';
export default sodium;
export * from 'libsodium-wrappers';
}
+42
View File
@@ -1,5 +1,6 @@
/** @type {import('tailwindcss').Config} */ /** @type {import('tailwindcss').Config} */
export default { export default {
darkMode: 'class',
content: [ content: [
'./index.html', './index.html',
'./src/**/*.{ts,tsx}', './src/**/*.{ts,tsx}',
@@ -51,12 +52,28 @@ export default {
800: '#312E81', 800: '#312E81',
900: '#1E1B4B', 900: '#1E1B4B',
}, },
// Clean-Rail design tokens. RGB-tuple form so alpha modifiers
// (e.g. bg-surface/50) work under both themes.
surface: 'rgb(var(--bg-rgb) / <alpha-value>)',
'surface-2': 'rgb(var(--bg-2-rgb) / <alpha-value>)',
'surface-3': 'rgb(var(--bg-3-rgb) / <alpha-value>)',
fg: 'rgb(var(--fg-rgb) / <alpha-value>)',
'fg-muted': 'rgb(var(--fg-muted-rgb) / <alpha-value>)',
accent: 'rgb(var(--accent-rgb) / <alpha-value>)',
'accent-fg': 'rgb(var(--accent-fg-rgb) / <alpha-value>)',
// Line has baked-in theme-specific alpha — direct var, no modifier.
line: 'var(--line)',
}, },
animation: { animation: {
'blob-a': 'blob 22s ease-in-out infinite', 'blob-a': 'blob 22s ease-in-out infinite',
'blob-b': 'blob 28s ease-in-out infinite reverse', 'blob-b': 'blob 28s ease-in-out infinite reverse',
'fade-in': 'fadeIn 400ms ease-out', 'fade-in': 'fadeIn 400ms ease-out',
'slide-up': 'slideUp 350ms ease-out', 'slide-up': 'slideUp 350ms ease-out',
'pulse-ring': 'pulseRing 2s ease-out infinite',
'audio-pulse': 'audioPulse 1.3s ease-out infinite',
'live-dot': 'liveDotPulse 1.5s ease-in-out infinite',
'slide-in-call': 'slideInCall 0.4s cubic-bezier(0.22,1,0.36,1)',
'fs-hint': 'fsHintFade 3.5s ease-out forwards',
}, },
keyframes: { keyframes: {
blob: { blob: {
@@ -72,9 +89,34 @@ export default {
from: { opacity: '0', transform: 'translateY(8px)' }, from: { opacity: '0', transform: 'translateY(8px)' },
to: { opacity: '1', transform: 'translateY(0)' }, to: { opacity: '1', transform: 'translateY(0)' },
}, },
pulseRing: {
'0%': { transform: 'scale(0.85)', opacity: '0.6' },
'100%': { transform: 'scale(1.25)', opacity: '0' },
},
audioPulse: {
'0%': { transform: 'scale(1)', opacity: '0.8' },
'100%': { transform: 'scale(1.3)', opacity: '0' },
},
liveDotPulse: {
'0%, 100%': { opacity: '1' },
'50%': { opacity: '0.4' },
},
slideInCall: {
from: { opacity: '0', transform: 'translateY(20px)' },
to: { opacity: '1', transform: 'translateY(0)' },
},
fsHintFade: {
'0%': { opacity: '0', transform: 'translate(-50%, -6px)' },
'15%, 75%': { opacity: '1', transform: 'translate(-50%, 0)' },
'100%': { opacity: '0', transform: 'translate(-50%, -6px)' },
},
}, },
boxShadow: { boxShadow: {
glow: '0 0 40px -8px rgba(99, 102, 241, 0.35)', glow: '0 0 40px -8px rgba(99, 102, 241, 0.35)',
'call-card': '0 20px 60px rgba(0,0,0,0.1)',
'call-card-dark': '0 20px 60px rgba(0,0,0,0.5)',
'pip-call': '0 12px 40px rgba(0,0,0,0.2), 0 0 0 3px rgba(79,70,229,0.15)',
'accept-btn': '0 4px 14px rgba(22,163,74,0.3)',
}, },
}, },
}, },
+5 -5
View File
@@ -16,11 +16,11 @@ export default defineConfig({
}, },
}, },
optimizeDeps: { optimizeDeps: {
// libsodium-wrappers 0.7.16 ships a broken "import" condition in its // libsodium-wrappers-sumo (and the compact variant) ship broken "import"
// package exports (the ESM bundle references a sibling ./libsodium.mjs // conditions in package exports the ESM bundle references a sibling
// that isn't in the published artefact). Force esbuild to pick the // ./libsodium.mjs that isn't in the published artefact. Force esbuild to
// "require" condition so the self-contained CJS build is used. // pick the "require" condition so the self-contained CJS build is used.
include: ['libsodium-wrappers'], include: ['libsodium-wrappers-sumo'],
esbuildOptions: { esbuildOptions: {
conditions: ['require', 'node', 'default'], conditions: ['require', 'node', 'default'],
}, },
@@ -0,0 +1,150 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>ChatApp Redesign — 6 Varianten</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Geist:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@500;600;700;800&family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&family=Fraunces:wght@600;700;800&family=Archivo+Black&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles/base.css">
<link rel="stylesheet" href="styles/variants.css">
<link rel="stylesheet" href="styles/rail.css">
<link rel="stylesheet" href="styles/call.css">
<script src="https://unpkg.com/react@18.3.1/umd/react.development.js" integrity="sha384-hD6/rw4ppMLGNu3tX5cjIb+uRZ7UkRJ6BPkLpg4hAu/6onKUg4lLsHAs9EBPT82L" crossorigin="anonymous"></script>
<script src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.development.js" integrity="sha384-u6aeetuaXnQ38mYT8rp6sbXaQe3NL9t+IBXmnYxwkUI2Hw4bsp2Wvmx4yRQF1uAm" crossorigin="anonymous"></script>
<script src="https://unpkg.com/@babel/standalone@7.29.0/babel.min.js" integrity="sha384-m08KidiNqLdpJqLq95G/LEi8Qvjl/xUYll3QILypMoQ65QorJ9Lvtp2RXYGBFj1y" crossorigin="anonymous"></script>
</head>
<body>
<!-- TWEAKS state -->
<script>
const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
"showCall": false,
"density": "normal",
"font": "default"
}/*EDITMODE-END*/;
</script>
<!-- Variant switcher -->
<div class="variant-switcher" id="variant-switcher"></div>
<div class="variant-container" id="root"></div>
<!-- Tweaks panel -->
<div class="tweaks-panel" id="tweaks-panel">
<h3>Tweaks</h3>
<div class="tweaks-row">
<label>Incoming call overlay</label>
<select id="tweak-call">
<option value="false">Off</option>
<option value="true">Show</option>
</select>
</div>
<div class="tweaks-row">
<label>Content density</label>
<select id="tweak-density">
<option value="normal">Normal</option>
<option value="compact">Compact</option>
<option value="spacious">Spacious</option>
</select>
</div>
<div class="tweaks-row" style="font-size: 11px; opacity: 0.6; margin-top: 16px;">
Tipp: Klicke oben auf die Varianten um zu wechseln.
</div>
</div>
<script src="components/icons.jsx" type="text/babel"></script>
<script src="components/data.jsx" type="text/babel"></script>
<script src="components/call.jsx" type="text/babel"></script>
<script src="components/app.jsx" type="text/babel"></script>
<script type="text/babel">
const VARIANTS = [
{ key: 'clean', label: 'Clean Minimal', layout: 'topnav' },
{ key: 'clean-rail', label: 'Clean Rail', baseKey: 'clean', layout: 'rail' },
{ key: 'playful', label: 'Playful', layout: 'topnav' },
{ key: 'y2k', label: 'Y2K Glass', layout: 'topnav' },
{ key: 'cyber', label: 'Cyberpunk', layout: 'topnav' },
{ key: 'warm', label: 'Warm Soft', layout: 'topnav' },
{ key: 'brutal', label: 'Brutal Gaming', layout: 'topnav' },
];
const App = () => {
const [activeVariant, setActiveVariant] = React.useState(() => {
return localStorage.getItem('chatapp-variant') || 'clean';
});
const [isDark, setIsDark] = React.useState(() => {
return localStorage.getItem('chatapp-dark') === 'true';
});
const [tweaks, setTweaks] = React.useState(TWEAK_DEFAULTS);
React.useEffect(() => {
localStorage.setItem('chatapp-variant', activeVariant);
}, [activeVariant]);
React.useEffect(() => {
localStorage.setItem('chatapp-dark', String(isDark));
}, [isDark]);
// Tweaks wiring
React.useEffect(() => {
const handler = (e) => {
if (e.data?.type === '__activate_edit_mode') {
document.getElementById('tweaks-panel').classList.add('open');
} else if (e.data?.type === '__deactivate_edit_mode') {
document.getElementById('tweaks-panel').classList.remove('open');
}
};
window.addEventListener('message', handler);
window.parent.postMessage({type: '__edit_mode_available'}, '*');
const callSel = document.getElementById('tweak-call');
const densSel = document.getElementById('tweak-density');
callSel.value = String(tweaks.showCall);
densSel.value = tweaks.density;
callSel.onchange = () => {
const v = callSel.value === 'true';
setTweaks(t => ({...t, showCall: v}));
window.parent.postMessage({type: '__edit_mode_set_keys', edits: {showCall: v}}, '*');
};
densSel.onchange = () => {
setTweaks(t => ({...t, density: densSel.value}));
window.parent.postMessage({type: '__edit_mode_set_keys', edits: {density: densSel.value}}, '*');
};
return () => window.removeEventListener('message', handler);
}, []);
// Render variant switcher buttons
React.useEffect(() => {
const sw = document.getElementById('variant-switcher');
sw.innerHTML = '';
VARIANTS.forEach((v, i) => {
const b = document.createElement('button');
b.textContent = `${String(i+1).padStart(2,'0')} ${v.label}`;
if (v.key === activeVariant) b.classList.add('active');
b.onclick = () => setActiveVariant(v.key);
sw.appendChild(b);
});
}, [activeVariant]);
const idx = VARIANTS.findIndex(v => v.key === activeVariant);
const variant = { ...VARIANTS[idx], idx };
return (
<ChatApp
key={activeVariant}
variant={variant}
showCall={tweaks.showCall}
showProfile={false}
isDark={isDark}
onToggleDark={() => setIsDark(d => !d)}
/>
);
};
ReactDOM.createRoot(document.getElementById('root')).render(<App />);
</script>
</body>
</html>
+314
View File
@@ -0,0 +1,314 @@
# Handoff: ChatApp — Clean Rail Redesign + Discord-Style Call UI
## Overview
This package contains the full design spec for redesigning the existing ChatApp (Netralax) interface around a **Clean Rail** layout aesthetic, plus a complete **Discord-style call system** (incoming call, in-call dock, picture-in-picture, fullscreen cinema mode).
The redesign covers:
1. The main chat interface (icon-rail sidebar + chat list + conversation area) in both **light** and **dark** mode.
2. The call UX: incoming call overlay → active call docked above the chat (so users can keep typing while on a call) → fullscreen cinema mode → minimizable PiP bubble.
## About the Design Files
The files in this bundle are **design references created in HTML/React/CSS** — prototypes showing the intended look, layout, and behavior. They are **not production code** to copy verbatim.
Your task is to **recreate these designs inside the existing ChatApp codebase**, using its established patterns (existing React components, styling conventions, state management, icon library, etc.). If some tokens or helper components don't exist yet in the codebase, add them but keep them aligned with what's already there.
The design files are organized as:
- `ChatApp Redesign.html` — entry HTML that boots the prototype
- `components/app.jsx` — main layout (rail + chat list + chat area, plus call state machine)
- `components/call.jsx` — all call UI components (IncomingCallScreen, ActiveCallScreen, ParticipantTile, CallControls, PipCall)
- `components/icons.jsx` — SVG icon set used
- `components/data.jsx` — dummy chat/message data
- `styles/base.css` — shared base tokens + layout primitives
- `styles/variants.css``variant-clean` light + dark token definitions (this is the look you're targeting)
- `styles/rail.css` — rail-layout specifics
- `styles/call.css`**all call UI styles** (the most important file for the call feature)
- `screenshots/` — reference images of each state
## Fidelity
**High-fidelity.** Exact colors, radii, spacing, typography and motion are specified. Recreate pixel-perfectly using the codebase's existing component library — but prefer the codebase's primitives over duplicating the prototype's raw CSS where equivalents exist.
---
## Design Tokens (Clean Rail)
### Colors — Light mode (`.variant-clean`)
```
--bg: #fafaf9 (app background)
--bg-2: #f4f4f2 (secondary surfaces, hover, search input)
--bg-3: #ffffff (elevated surfaces — chat list, chat area, cards)
--fg: #0a0a0f (primary text)
--fg-muted: #737380 (secondary text, icons)
--line: rgba(10,10,15,0.08) (dividers, borders)
--accent: #4F46E5 (indigo — primary actions, active states, my-bubble)
--accent-fg: #ffffff
```
### Colors — Dark mode (`.variant-clean.dark`)
```
--bg: #050507
--bg-2: #111118
--bg-3: #0A0A0F
--fg: #f4f4f5
--fg-muted: #8a8a99
--line: rgba(255,255,255,0.07)
--accent: #6D73FF (slightly lighter indigo for contrast)
--accent-fg: #ffffff
```
### Status / Semantic Colors (both modes)
```
Speaking/Online/Success: #16a34a light · #22c55e / #4ade80 dark
Danger/Decline/Hangup: #dc2626 (hover #b91c1c) · #fb7185 dark accent
Warning/Idle: #f59e0b
Live/Recording: #ef4444
E2EE indicator (light): #16a34a (dark: #4ade80)
```
### Avatar color swatches (assigned per chat)
```
violet: bg #ddd6fe / fg #5b21b6 (dark: #312E81 / #C4B5FD)
amber: bg #fde68a / fg #78350f
rose: bg #fecdd3 / fg #881337
teal: bg #99f6e4 / fg #134e4a (dark: #134e4a / #99f6e4)
```
### Typography
- Family: `'Inter', system-ui, sans-serif` — Inter is the base. Display/headline use `'Outfit'` (participant name in IncomingCall).
- Scale:
- Chat title / participant name large: 24px / 700
- Primary labels, chat name: 1415px / 600
- Body (bubbles, messages): 14px / 400500
- Meta, timestamps, presence: 1112px / 400500
- Rail tooltips, badges: 1011px / 500600
- Uppercase eyebrow (e.g. "EINGEHENDER ANRUF"): 12px / 600 / letter-spacing 0.12em
### Spacing
- Container padding: 16px (call-stage), 1420px (topbars, composer)
- Tile gap in grid: 810px
- Control-button row gap: 810px
- Border radius scale: 4 (small), 8 (tiles/badges), 10 (buttons), 14 (cards, large buttons), 18 (bubbles, bottom-fs controls), 24 (modal/card)
### Shadows
- Elevated card light: `0 20px 60px rgba(0,0,0,0.1)`
- Elevated card dark: `0 20px 60px rgba(0,0,0,0.5)`
- Accent button: `0 4px 14px rgba(22,163,74,0.3)` (green accept) / same pattern for accent
- PiP glow: `0 12px 40px rgba(0,0,0,0.2), 0 0 0 3px rgba(79,70,229,0.15)`
### Motion
- Standard UI transition: `all 0.15s`
- Pulse ring (incoming call): `2s ease-out infinite`, scale 0.85→1.25, opacity 0.6→0
- Audio pulse (speaking ring): `1.3s ease-out infinite`, scale 1→1.3
- Live dot: `1.5s ease-in-out infinite`, opacity 1↔0.4
- PiP entrance: `slideInCall 0.4s cubic-bezier(0.22,1,0.36,1)`
- Fullscreen hint fade: 3.5s total (015% fade in, 75100% fade out)
---
## Screens / Views
### 1. Main Chat — Clean Rail Layout
**Structure (left → right):**
- **Icon Rail** (72px wide): brand logo at top, tab buttons (Chats / Friends / Admin), spacer, Settings + theme-toggle at bottom. Active tab shows a vertical pill indicator on the left edge.
- **Chat List** (280px wide): header with title + "new chat" icon, search input, list of `ChatItem`s (avatar + name + time + preview, optional unread dot), `rail-user` footer showing own profile + quick mute/settings.
- **Chat Area** (flex, fills rest): chat header (counterpart avatar + name + presence/handle + search/voice/video buttons), messages scroll area, composer at bottom.
**Chat header actions (right side):** search icon, phone icon, video icon. Phone triggers voice call (`callScreen → 'active'`, `callState.video = false`), Video triggers video call (`callState.video = true`).
**Message bubbles:**
- Mine (outgoing): filled accent bg, white text, radius `18px 18px 4px 18px`.
- Theirs (incoming): transparent bg, 1px line border, fg text, radius `18px 18px 18px 4px`.
- Avatars appear only on the **last message of a run** from that sender.
- Reactions: pill row below bubble, `.mine` = filled accent.
- System events ("Kaiwandi hat einen Anruf gestartet — Anruf beitreten"): centered `event-pill`, muted bg, muted fg, 11px.
**Composer:** plus button (attach), rounded input bar with inline emoji + mic icons, send button.
---
### 2. Incoming Call Overlay
Full-bleed overlay replacing the chat area (takes over `.chat-area` space), radial-gradient background tinted with accent.
Centered card (420px wide):
- Eyebrow "EINGEHENDER ANRUF" (uppercase, 12px, tracked)
- Large avatar (96px) with **two pulsing rings** (staggered 1s)
- Caller name (24px / 700 / Outfit)
- Subtitle row: lock icon + "E2E verschlüsselt · Voice Call"
- Two side-by-side action buttons:
- **Ablehnen**: transparent, red border/text, hover = 8% red bg
- **Annehmen**: green #16a34a, white, shadow
### 3. Active Call — Docked (Default)
**CRITICAL layout decision:** The active call does NOT take over the chat area. Instead it renders as a **dock above the messages**, taking roughly 50% of the chat-area height (min 280px, max 420px). The chat header is **hidden** while the dock is active (redundant — call topbar shows the channel name). Messages + composer remain fully visible and usable below, so users can keep chatting during the call. This is the Discord desktop pattern.
**Dock content:**
- **Call topbar**: left side shows group icon + "Die Squad" + duration (tabular-nums), with E2E verschlüsselt below in success-green. Right side has 3 mode toggles: Grid / Focus / Fullscreen.
- **Call stage**: fills the remaining space, renders either:
- **Grid**: CSS grid, 2×2 for 4 people, 3×2 for 56, 1fr 1fr for 2.
- **Focus**: main speaker tile takes most height, bottom strip with 110px-tall smaller tiles for others.
- **Fullscreen**: switches to `mode === 'fullscreen'` — see screen 4.
- **Call controls bar** at the bottom of the dock: Mic, Video, Screen-share, Participants, **Hangup** (wider, red). Compact 36px buttons when docked.
### 4. Active Call — Fullscreen Cinema Mode
When mode = `fullscreen`:
- Entire call-dock container becomes absolute-positioned and takes over everything below the window bar (chat list still visible on the left).
- The **call topbar is hidden** entirely.
- Main speaker fills the whole frame, no border/radius.
- Participants strip moves to a **floating column in the bottom-right** (`.fs-strip`): 180px wide, 100px tall tiles, glass-blurred bg.
- **Call controls bar floats** at bottom center — glass pill: `rgba(10,10,15,0.7)` + `backdrop-filter: blur(20px)` + subtle border + 18px radius.
- **"Esc zum Verlassen" hint** fades in top-center on entry and auto-fades out over 3.5s. Pressing Esc or clicking Grid/Focus buttons exits.
- **No visible X button** (intentional — keyboard-only exit, confirmed design decision).
### 5. Participant Tile — Shared Component
A participant is either in **audio-only**, **video**, or **sharing screen** mode.
- Tile border: 1px `var(--line)`, radius 14 (10 in dock). Hover → border becomes accent. `.speaking` → 2px green border + green glow shadow. `.focused` → accent border.
- **Audio-only**: centered avatar (72px large, 44px small). When `speaking`, a green ring pulses around the avatar (`::before` pseudo).
- **Video**: placeholder stub (gradient background + centered avatar, since real video not in scope here).
- **Screenshare**: renders a "fake window" — chrome row with 3 dots, content row with grey skeleton lines + one accent-tinted block. A glass badge top-left: monitor icon + "Max teilt Bildschirm" (badge hidden on small tiles).
- **Meta row** (absolute, bottom 8px, glass): left shows crown (if me) + name + lock (if E2EE), right shows muted mic icon (red chip) and/or sharing icon (green chip).
### 6. Picture-in-Picture (PiP)
A compact 260px pill docked bottom-right of the chat area:
- 44px preview square (avatar of speaker, or mini shared-window placeholder if someone's sharing)
- Title "Die Squad · {participantCount}"
- Subtitle row: red pulsing dot + "Live · tippe zum Öffnen"
- Circular red hangup button on the right
- Whole thing is clickable → expands back to active call
- Entrance animation: slide from bottom + fade in (`slideInCall`)
- Shadow: standard + 3px accent glow ring
---
## Interactions & Behavior
### Call State Machine (lives in `ChatApp`)
```js
// Primary state
const [callScreen, setCallScreen] = useState('none'); // 'none' | 'incoming' | 'active' | 'pip'
const [callMode, setCallMode] = useState('grid'); // 'grid' | 'focus' | 'fullscreen'
const [focusedId, setFocusedId] = useState(firstSharingOrSpeakerId);
const [callState, setCallState] = useState({ muted: false, sharing: false, video: false, duration });
```
### Triggers & Transitions
- Chat-header **phone icon** click → `setCallScreen('active')`, `callState.video = false`
- Chat-header **video icon** click → `setCallScreen('active')`, `callState.video = true`
- Grid tile click → `setFocusedId(id); setCallMode('focus')`
- Focus/Grid/Fullscreen buttons in call topbar → set mode directly
- Incoming "Annehmen" → `setCallScreen('active')`
- Incoming "Ablehnen" → `setCallScreen('none')`
- Hangup → `setCallScreen('none')`
- PiP clicked → `setCallScreen('active')`
- PiP hangup (circle red btn) → `stopPropagation()` + `setCallScreen('none')`
- **Esc key** (global listener while `callScreen === 'active' && callMode === 'fullscreen'`) → `setCallMode('grid')`
### Chat Header Visibility Rule
```
if (callScreen === 'active' && callMode !== 'fullscreen') → hide chat header
else → show chat header
```
### Keyboard
- `Esc` exits fullscreen (only). No other global keybindings.
---
## State Management
Data shapes to wire up (see `components/call.jsx`):
```ts
type Participant = {
id: string;
name: string;
initial: string;
color: 'violet' | 'amber' | 'rose' | 'teal';
speaking: boolean;
muted: boolean;
video: boolean;
sharing?: boolean;
me?: boolean;
e2ee: boolean;
};
type CallState = {
muted: boolean;
sharing: boolean;
video: boolean;
duration: string; // "HH:MM:SS"
};
```
In production these all come from your real-time signaling layer (WebRTC, LiveKit, etc.). The prototype uses static data for layout purposes only — wire them to your call store.
---
## Assets
No custom imagery. Everything is SVG icons (inlined in `components/icons.jsx`) and CSS. Fonts from Google Fonts: `Inter`, `Outfit`.
Icons used in this scope: Chat, Friends, Shield, Settings, Logo, AddUser, Search, Phone, Video, Plus, Smile, Mic, MicOff, Send, Sun, Moon, Monitor, Lock, Crown, Grid, Focus, Maximize, PhoneOff.
Replace with your codebase's icon library if one exists (e.g. lucide-react, heroicons) — names match lucide conventions.
---
## Implementation Checklist
1. **Tokens**: add the Clean-variant light + dark CSS variables to your theme layer. If you already have a token system, map them to your existing names; otherwise create `--bg`, `--bg-2`, `--bg-3`, `--fg`, `--fg-muted`, `--line`, `--accent`, `--accent-fg`.
2. **Icon rail + chat list + chat area**: refactor the current top-nav layout into the 3-column rail layout. Use your existing `Avatar`, `ChatItem`, `Message` components — only restyle.
3. **Message bubbles**: outlined `them` / filled `me`, asymmetric radius, avatars only on last-of-run.
4. **Call state machine**: add the four `useState` hooks to whatever component owns the chat screen. Hook the Esc key effect.
5. **IncomingCallScreen**: new component, full-bleed overlay of `.chat-area`.
6. **Call dock**: new component, renders above `.messages`. Hide chat-header while docked.
7. **ParticipantTile**: audio / video / sharing modes, speaking ring, meta overlay.
8. **Fullscreen mode**: switch call container to position absolute, floating strip + floating controls + Esc hint.
9. **PiP**: minimizable widget bottom-right of chat area.
10. **Wire real data**: replace `CALL_PARTICIPANTS` dummy with your live call-session participants.
---
## Files in This Handoff
```
design_handoff_chatapp/
├── README.md (this file)
├── ChatApp Redesign.html (entry — open in browser to see the prototype)
├── components/
│ ├── app.jsx (chat app + rail layout + call state machine)
│ ├── call.jsx (Incoming / Active / Pip / ParticipantTile / CallControls)
│ ├── icons.jsx (all SVG icons)
│ └── data.jsx (dummy chats, messages)
├── styles/
│ ├── base.css
│ ├── variants.css (Clean light + dark tokens — this is your theme)
│ ├── rail.css (rail layout)
│ └── call.css (all call UI — highest priority file)
└── screenshots/
├── 01-chat-light.png
├── 03-chat-dark.png
├── 04-incoming-dark.png
├── 05-incall-grid-dark.png
├── 06-incall-focus-dark.png
├── 07-incall-fullscreen-dark.png
├── 09-pip-dark.png
└── 11-incall-light.png
```
---
## Notes for Claude Code
- The Clean Rail variant is **Variante 2** in the prototype's variant switcher — ignore the other 5 aesthetic variants (Playful, Y2K, Cyberpunk, Warm, Brutal), they were design exploration and not the chosen direction.
- Prefer composition over copying raw CSS. If the codebase has a `Card`, `Button`, `Tooltip`, use them.
- Duration ("00:12:47") should tick live from the call start timestamp, not be static.
- For WebRTC/media handling: this package specifies **UI only**. The media/signaling layer is out of scope and already exists in the codebase (see `CallUI.tsx`, `InCallPanel.tsx`).
+439
View File
@@ -0,0 +1,439 @@
// Main ChatApp component — layout shared across all variants
const Avatar = ({ chat, size = '' }) => (
<div className={`avatar ${size}`} data-color={chat.color}>
{chat.initial}
{chat.presence && <div className={`presence ${chat.presence}`}></div>}
</div>
);
const ChatItem = ({ chat, onClick }) => (
<div className={`chat-item ${chat.active ? 'active' : ''}`} onClick={onClick}>
<Avatar chat={chat} />
<div className="chat-item-body">
<div className="chat-item-name">
<span>{chat.name}</span>
<span className="chat-item-time">{chat.time}</span>
</div>
<div className="chat-item-preview">
{chat.preview}
{chat.unread && <span className="unread-dot" style={{background: 'var(--accent, #a78bfa)', display: 'inline-block'}}></span>}
</div>
</div>
</div>
);
const Reactions = ({ reactions }) => (
<div className="reactions">
{reactions.map((r, i) => (
<div key={i} className={`reaction ${r.mine ? 'mine' : ''}`}>
<span>{r.emoji}</span>
<span className="count">{r.count}</span>
</div>
))}
</div>
);
const Bubble = ({ msg }) => (
<div className={`bubble ${msg.from}`}>
{msg.text}
<span className="ts">{msg.time}{msg.read && msg.from === 'me' ? ' · Gelesen' : ''}</span>
</div>
);
const MediaBubble = ({ msg }) => (
<div className="bubble me" style={{padding: 4}}>
<div className="media-preview">
<div className="media-image">{msg.label}</div>
<div className="media-meta">
<span>{msg.filename}</span>
<span>{msg.size}</span>
</div>
</div>
<span className="ts" style={{paddingLeft: 8, paddingBottom: 4}}>{msg.time}</span>
</div>
);
const EventPill = ({ evt }) => {
const IconComp = evt.icon === 'phone' ? Icon.Phone : Icon.PhoneOff;
return (
<div className="event-row">
<div className={`event-pill ${evt.kind === 'rejected' ? 'rejected' : ''}`}>
<IconComp />
<span>{evt.text}</span>
{evt.duration && <span>· {evt.duration}</span>}
<span>· {evt.time}</span>
</div>
</div>
);
};
const TypingIndicator = () => (
<div className="bubble them" style={{padding: '10px 14px'}}>
<div className="typing"><span></span><span></span><span></span></div>
</div>
);
const MessageItem = ({ msg, showAvatar, chat, myChat }) => {
if (msg.type === 'event') return <EventPill evt={msg} />;
const wrapWithAvatar = (inner) => (
<div className={`message-row ${msg.from}`}>
{msg.from === 'them' && (
<div className="message-avatar-slot">
{showAvatar && <Avatar chat={{...chat, presence: null}} size="sm" />}
</div>
)}
<div className={`message-group ${msg.from}`}>
{inner}
</div>
{msg.from === 'me' && (
<div className="message-avatar-slot">
{showAvatar && <Avatar chat={{...myChat, presence: null}} size="sm" />}
</div>
)}
</div>
);
if (msg.type === 'typing') {
return wrapWithAvatar(<TypingIndicator />);
}
if (msg.type === 'media') {
return wrapWithAvatar(<MediaBubble msg={msg} />);
}
return wrapWithAvatar(
<>
<Bubble msg={msg} />
{msg.reactions && <Reactions reactions={msg.reactions} />}
</>
);
};
const ProfileCard = ({ chat, position }) => (
<div className="profile-card" style={{top: position.top, left: position.left}}>
<div className="profile-card-banner"></div>
<div className="profile-card-body">
<div className="profile-card-avatar" data-color={chat.color} style={{background: 'var(--accent, #a78bfa)', color: '#fff'}}>
{chat.initial}
</div>
<div className="profile-card-name">{chat.name}</div>
<div className="profile-card-handle">{chat.handle}</div>
<div className="profile-card-meta">
<div>🟢 Online · seit 2h</div>
<div>📍 Beigetreten am 14. Mär 2026</div>
<div>🎮 Zockt gerade: Valorant</div>
</div>
</div>
</div>
);
const CallOverlay = ({ chat }) => (
<div className="call-overlay">
<Avatar chat={{...chat, presence: null}} size="lg" />
<div className="call-info">
<div className="call-name">Max ruft an</div>
<div className="call-sub">Voice Call · klingelt</div>
</div>
<div className="call-actions">
<button className="call-btn decline"><Icon.PhoneOff /></button>
<button className="call-btn accept"><Icon.Phone /></button>
</div>
</div>
);
const ChatApp = ({ variant, showCall, showProfile, isDark, onToggleDark }) => {
const [activeChat, setActiveChat] = React.useState(CHATS[0]);
const [activeTab, setActiveTab] = React.useState('chats');
// Call state: 'none' | 'incoming' | 'active' | 'pip'
const [callScreen, setCallScreen] = React.useState('none');
const [callMode, setCallMode] = React.useState('grid'); // grid | focus | fullscreen
const [focusedId, setFocusedId] = React.useState('max');
const [callState, setCallState] = React.useState({
muted: false, sharing: false, video: false, duration: '00:12:47'
});
// Esc exits fullscreen
React.useEffect(() => {
const onKey = (e) => {
if (e.key === 'Escape' && callScreen === 'active' && callMode === 'fullscreen') {
setCallMode('grid');
}
};
window.addEventListener('keydown', onKey);
return () => window.removeEventListener('keydown', onKey);
}, [callScreen, callMode]);
const chats = CHATS.map(c => ({...c, active: c.id === activeChat.id}));
const messagesEndRef = React.useRef(null);
React.useEffect(() => {
if (messagesEndRef.current) {
messagesEndRef.current.parentElement.scrollTop = messagesEndRef.current.parentElement.scrollHeight;
}
}, []);
return (
<div className={`variant variant-${variant.baseKey || variant.key} ${isDark ? 'dark' : ''} ${variant.layout === 'rail' ? 'layout-rail' : 'layout-topnav'} active`} data-screen-label={`0${variant.idx+1} ${variant.label}`}>
<div className="app-window" style={{position: 'relative'}}>
<div className="window-bar">
<div className="dots">
<div className="dot" style={{background: '#ff5f57'}}></div>
<div className="dot" style={{background: '#febc2e'}}></div>
<div className="dot" style={{background: '#28c840'}}></div>
</div>
<div className="title">ChatApp {variant.label}</div>
<div style={{width: 52}}></div>
</div>
<div className="app-body">
{variant.layout === 'rail' ? (
<div className="rail-layout">
{/* Icon rail left */}
<div className="icon-rail">
<div className="rail-brand" title="Netralax"><Icon.Logo /></div>
<div className="rail-divider"></div>
<button className={`rail-btn ${activeTab === 'chats' ? 'active' : ''}`} onClick={() => setActiveTab('chats')} title="Chats">
<Icon.Chat />
{activeTab === 'chats' && <div className="rail-pill"></div>}
</button>
<button className={`rail-btn ${activeTab === 'friends' ? 'active' : ''}`} onClick={() => setActiveTab('friends')} title="Freunde">
<Icon.Friends />
{activeTab === 'friends' && <div className="rail-pill"></div>}
</button>
<button className={`rail-btn ${activeTab === 'admin' ? 'active' : ''}`} onClick={() => setActiveTab('admin')} title="Admin">
<Icon.Shield />
{activeTab === 'admin' && <div className="rail-pill"></div>}
</button>
<div style={{flex: 1}}></div>
<button className={`rail-btn ${activeTab === 'settings' ? 'active' : ''}`} onClick={() => setActiveTab('settings')} title="Einstellungen">
<Icon.Settings />
</button>
<button className="rail-btn" onClick={onToggleDark} title={isDark ? 'Light mode' : 'Dark mode'}>
{isDark ? <Icon.Sun /> : <Icon.Moon />}
</button>
</div>
{/* Chatlist + user profile at bottom */}
<div className="chat-list rail-chatlist">
<div className="chat-list-header">
<div className="chat-list-title">Chats</div>
<button className="icon-btn" title="Neuer Chat"><Icon.AddUser /></button>
</div>
<input className="chat-search" placeholder="Suche…" />
<div className="chat-items">
{chats.map(c => (
<ChatItem key={c.id} chat={c} onClick={() => setActiveChat(c)} />
))}
</div>
<div className="rail-user">
<Avatar chat={{initial: 'D', color: 'teal', presence: 'online'}} size="sm" />
<div style={{fontSize: 12, flex: 1, minWidth: 0}}>
<div style={{fontWeight: 600}}>dennis</div>
<div style={{opacity: 0.6, fontSize: 10}}> Online</div>
</div>
<button className="icon-btn" title="Mute"><Icon.Mic /></button>
<button className="icon-btn" title="Einstellungen"><Icon.Settings /></button>
</div>
</div>
{/* Chat area (unchanged below) */}
<div className="chat-area">
{!(callScreen === 'active' && callMode !== 'fullscreen') && (
<div className="chat-header">
<Avatar chat={activeChat} />
<div className="chat-header-info">
<div className="chat-header-name">{activeChat.name}</div>
<div className="chat-header-status">
{activeChat.presence === 'online' ? '● Online' :
activeChat.presence === 'idle' ? '● Abwesend' :
activeChat.presence === 'dnd' ? '● Nicht stören' :
'● Offline · zuletzt vor 2h'}
{' · '}{activeChat.handle}
</div>
</div>
<div className="chat-header-actions">
<button className="icon-btn" title="Suche"><Icon.Search /></button>
<button className="icon-btn" title="Voice" onClick={() => setCallScreen('active')}><Icon.Phone /></button>
<button className="icon-btn" title="Video" onClick={() => { setCallState(s => ({...s, video: true})); setCallScreen('active'); }}><Icon.Video /></button>
</div>
</div>
)}
{/* Call dock — rendered above messages, Discord-style */}
{callScreen === 'active' && callMode !== 'fullscreen' && (
<div className="call-dock">
<ActiveCallScreen
participants={CALL_PARTICIPANTS}
mode={callMode}
setMode={setCallMode}
focused={focusedId}
setFocused={setFocusedId}
onHangup={() => setCallScreen('none')}
callState={callState}
setCallState={setCallState}
/>
</div>
)}
<div className="messages">
{MESSAGES.map((m, i) => {
const next = MESSAGES[i+1];
const isLastOfRun = (m.from === 'them' || m.from === 'me') && (!next || next.from !== m.from || next.type === 'event');
const myChat = { initial: 'D', color: 'teal' };
return <MessageItem key={i} msg={m} showAvatar={isLastOfRun} chat={activeChat} myChat={myChat} />;
})}
<div ref={messagesEndRef} />
</div>
<div className="composer">
<button className="composer-btn" title="Attach"><Icon.Plus /></button>
<div className="composer-box">
<input placeholder="Nachricht schreiben…" />
<button className="icon-btn"><Icon.Smile /></button>
<button className="icon-btn"><Icon.Mic /></button>
</div>
<button className="composer-btn"><Icon.Send /></button>
</div>
</div>
</div>
) : (
<>
<div className="top-nav">
<div className="nav-brand">
<Icon.Logo />
<span>Netralax</span>
</div>
<div className="nav-tabs">
<button className={`nav-tab ${activeTab === 'chats' ? 'active' : ''}`} onClick={() => setActiveTab('chats')}>
<Icon.Chat /> Chats
</button>
<button className={`nav-tab ${activeTab === 'friends' ? 'active' : ''}`} onClick={() => setActiveTab('friends')}>
<Icon.Friends /> Freunde
</button>
<button className={`nav-tab ${activeTab === 'settings' ? 'active' : ''}`} onClick={() => setActiveTab('settings')}>
<Icon.Settings /> Einstellungen
</button>
<button className={`nav-tab ${activeTab === 'admin' ? 'active' : ''}`} onClick={() => setActiveTab('admin')}>
<Icon.Shield /> Admin
</button>
</div>
<div className="nav-user">
<Avatar chat={{initial: 'D', color: 'teal', presence: 'online'}} size="sm" />
<div style={{fontSize: 12}}>
<div style={{fontWeight: 600}}>dennis</div>
<div style={{opacity: 0.6, fontSize: 10}}>@dennis</div>
</div>
<Icon.Chevron />
</div>
{variant.key === 'clean' && (
<button className="icon-btn theme-toggle" onClick={onToggleDark} title={isDark ? 'Light mode' : 'Dark mode'} style={{marginLeft: 6}}>
{isDark ? <Icon.Sun /> : <Icon.Moon />}
</button>
)}
</div>
<div className="main-area">
<div className="chat-list">
<div className="chat-list-header">
<div className="chat-list-title">Chats</div>
<button className="icon-btn" title="Neuer Chat"><Icon.AddUser /></button>
</div>
<input className="chat-search" placeholder="Suche…" />
<div className="chat-items">
{chats.map(c => (
<ChatItem key={c.id} chat={c} onClick={() => setActiveChat(c)} />
))}
</div>
</div>
<div className="chat-area">
<div className="chat-header">
<Avatar chat={activeChat} />
<div className="chat-header-info">
<div className="chat-header-name">{activeChat.name}</div>
<div className="chat-header-status">
{activeChat.presence === 'online' ? '● Online' :
activeChat.presence === 'idle' ? '● Abwesend' :
activeChat.presence === 'dnd' ? '● Nicht stören' :
'● Offline · zuletzt vor 2h'}
{' · '}{activeChat.handle}
</div>
</div>
<div className="chat-header-actions">
<button className="icon-btn" title="Suche"><Icon.Search /></button>
<button className="icon-btn" title="Voice"><Icon.Phone /></button>
<button className="icon-btn" title="Video"><Icon.Video /></button>
</div>
</div>
<div className="messages">
{MESSAGES.map((m, i) => {
const next = MESSAGES[i+1];
const isLastOfRun = (m.from === 'them' || m.from === 'me') && (!next || next.from !== m.from || next.type === 'event');
const myChat = { initial: 'D', color: 'teal' };
return <MessageItem key={i} msg={m} showAvatar={isLastOfRun} chat={activeChat} myChat={myChat} />;
})}
<div ref={messagesEndRef} />
</div>
<div className="composer">
<button className="composer-btn" title="Attach"><Icon.Plus /></button>
<div className="composer-box">
<input placeholder="Nachricht schreiben…" />
<button className="icon-btn"><Icon.Smile /></button>
<button className="icon-btn"><Icon.Mic /></button>
</div>
<button className="composer-btn"><Icon.Send /></button>
</div>
</div>
</div>
</>
)}
</div>
{/* Call screen switcher — only in Clean Rail */}
{variant.layout === 'rail' && (
<div className="screen-switcher">
<button className={callScreen === 'none' ? 'active' : ''} onClick={() => setCallScreen('none')}>Chat</button>
<button className={callScreen === 'incoming' ? 'active' : ''} onClick={() => setCallScreen('incoming')}>Incoming</button>
<button className={callScreen === 'active' ? 'active' : ''} onClick={() => setCallScreen('active')}>In-Call</button>
<button className={callScreen === 'pip' ? 'active' : ''} onClick={() => setCallScreen('pip')}>PiP</button>
</div>
)}
{/* Incoming call is a full overlay */}
{callScreen === 'incoming' && (
<div className="call-screen">
<IncomingCallScreen
chat={activeChat}
onAccept={() => setCallScreen('active')}
onDecline={() => setCallScreen('none')}
/>
</div>
)}
{/* Fullscreen call hides chat entirely */}
{callScreen === 'active' && callMode === 'fullscreen' && (
<div className="call-screen">
<ActiveCallScreen
participants={CALL_PARTICIPANTS}
mode={callMode}
setMode={setCallMode}
focused={focusedId}
setFocused={setFocusedId}
onHangup={() => setCallScreen('none')}
callState={callState}
setCallState={setCallState}
/>
</div>
)}
{callScreen === 'pip' && (
<PipCall
participants={CALL_PARTICIPANTS}
onExpand={() => setCallScreen('active')}
onHangup={() => setCallScreen('none')}
/>
)}
{showCall && callScreen === 'none' && <CallOverlay chat={activeChat} />}
</div>
</div>
);
};
Object.assign(window, { ChatApp, Avatar, ChatItem, MessageItem, CallOverlay });
+194
View File
@@ -0,0 +1,194 @@
// Call UI components — Discord-style, matched to Clean-Rail aesthetic
const CALL_PARTICIPANTS = [
{ id: 'dennis', name: 'dennis', initial: 'D', color: 'teal', speaking: false, muted: false, video: false, me: true, e2ee: true },
{ id: 'max', name: 'Max', initial: 'M', color: 'teal', speaking: true, muted: false, video: true, sharing: true, e2ee: true },
{ id: 'lena', name: 'Lena', initial: 'L', color: 'amber', speaking: false, muted: true, video: false, e2ee: true },
{ id: 'tom', name: 'Tom', initial: 'T', color: 'violet', speaking: false, muted: false, video: false, e2ee: true },
{ id: 'nico', name: 'nico', initial: 'N', color: 'teal', speaking: true, muted: false, video: false, e2ee: true },
];
const ParticipantTile = ({ p, focused, onClick, small }) => (
<div className={`participant-tile ${p.speaking ? 'speaking' : ''} ${focused ? 'focused' : ''} ${small ? 'small' : ''}`} onClick={onClick}>
{p.video || p.sharing ? (
<div className="participant-video">
{p.sharing ? (
<div className="screenshare-stub">
<div className="ss-window">
<div className="ss-chrome"><span></span><span></span><span></span></div>
<div className="ss-content">
<div className="ss-line" style={{width: '60%'}}></div>
<div className="ss-line" style={{width: '80%'}}></div>
<div className="ss-line" style={{width: '40%'}}></div>
<div className="ss-block"></div>
<div className="ss-line" style={{width: '70%'}}></div>
</div>
</div>
<div className="ss-badge">
<Icon.Monitor /> {p.name} teilt Bildschirm
</div>
</div>
) : (
<div className="video-stub">
<Avatar chat={{initial: p.initial, color: p.color}} size="lg" />
</div>
)}
</div>
) : (
<div className="participant-audio">
<div className={`audio-ring ${p.speaking ? 'pulse' : ''}`}>
<Avatar chat={{initial: p.initial, color: p.color}} size="lg" />
</div>
</div>
)}
<div className="participant-meta">
<div className="participant-name">
{p.me && <Icon.Crown />}
<span>{p.name}{p.me ? ' (du)' : ''}</span>
{p.e2ee && <span className="e2ee-dot" title="End-to-End verschlüsselt"><Icon.Lock /></span>}
</div>
<div className="participant-icons">
{p.muted && <span className="pi muted"><Icon.MicOff /></span>}
{p.sharing && <span className="pi sharing"><Icon.Monitor /></span>}
</div>
</div>
</div>
);
const CallControls = ({ muted, onToggleMute, sharing, onToggleShare, video, onToggleVideo, onHangup, compact }) => (
<div className={`call-controls ${compact ? 'compact' : ''}`}>
<button className={`cc-btn ${muted ? 'active-danger' : ''}`} onClick={onToggleMute} title={muted ? 'Unmute' : 'Mute'}>
{muted ? <Icon.MicOff /> : <Icon.Mic />}
</button>
<button className={`cc-btn ${video ? 'active-brand' : ''}`} onClick={onToggleVideo} title="Video">
<Icon.Video />
</button>
<button className={`cc-btn ${sharing ? 'active-brand' : ''}`} onClick={onToggleShare} title="Bildschirm teilen">
<Icon.Monitor />
</button>
<button className="cc-btn" title="Teilnehmer"><Icon.Friends /></button>
<button className="cc-btn hangup" onClick={onHangup} title="Auflegen"><Icon.PhoneOff /></button>
</div>
);
const IncomingCallScreen = ({ chat, onAccept, onDecline }) => (
<div className="incoming-call">
<div className="incoming-card">
<div className="incoming-ringing">Eingehender Anruf</div>
<div className="incoming-avatar">
<div className="pulse-ring"></div>
<div className="pulse-ring d2"></div>
<Avatar chat={{initial: chat.initial, color: chat.color}} size="lg" />
</div>
<div className="incoming-name">{chat.name}</div>
<div className="incoming-sub">
<Icon.Lock /> E2E verschlüsselt · Voice Call
</div>
<div className="incoming-actions">
<button className="incoming-btn decline" onClick={onDecline}>
<Icon.PhoneOff /> Ablehnen
</button>
<button className="incoming-btn accept" onClick={onAccept}>
<Icon.Phone /> Annehmen
</button>
</div>
</div>
</div>
);
const ActiveCallScreen = ({ participants, mode, setMode, focused, setFocused, onHangup, callState, setCallState }) => {
const speaker = participants.find(p => p.id === focused) || participants.find(p => p.sharing) || participants[0];
const others = participants.filter(p => p.id !== speaker.id);
const sharingParticipant = participants.find(p => p.sharing);
return (
<div className={`active-call mode-${mode}`}>
<div className="call-topbar">
<div className="call-topbar-left">
<div className="call-title">
<Icon.Friends />
<span>Die Squad</span>
<span className="call-dot">·</span>
<span className="call-duration">{callState.duration}</span>
</div>
<div className="call-e2ee"><Icon.Lock /> E2E verschlüsselt</div>
</div>
<div className="call-topbar-right">
<button className={`cc-btn sm ${mode === 'grid' ? 'active-brand' : ''}`} onClick={() => setMode('grid')} title="Grid"><Icon.Grid /></button>
<button className={`cc-btn sm ${mode === 'focus' ? 'active-brand' : ''}`} onClick={() => setMode('focus')} title="Fokus"><Icon.Focus /></button>
<button className={`cc-btn sm ${mode === 'fullscreen' ? 'active-brand' : ''}`} onClick={() => setMode('fullscreen')} title="Vollbild"><Icon.Maximize /></button>
</div>
</div>
<div className="call-stage">
{mode === 'grid' && (
<div className={`grid grid-${participants.length}`}>
{participants.map(p => (
<ParticipantTile key={p.id} p={p} onClick={() => { setFocused(p.id); setMode('focus'); }} />
))}
</div>
)}
{mode === 'focus' && (
<div className="focus-layout">
<div className="focus-main">
<ParticipantTile p={speaker} focused />
</div>
<div className="focus-strip">
{others.map(p => (
<ParticipantTile key={p.id} p={p} small onClick={() => setFocused(p.id)} />
))}
</div>
</div>
)}
{mode === 'fullscreen' && (
<div className="fullscreen-layout">
<ParticipantTile p={speaker} focused />
<div className="fs-strip">
{others.slice(0,4).map(p => (
<ParticipantTile key={p.id} p={p} small onClick={() => setFocused(p.id)} />
))}
</div>
<div className="fs-hint">Esc zum Verlassen</div>
</div>
)}
</div>
<CallControls
muted={callState.muted}
onToggleMute={() => setCallState(s => ({...s, muted: !s.muted}))}
sharing={callState.sharing}
onToggleShare={() => setCallState(s => ({...s, sharing: !s.sharing}))}
video={callState.video}
onToggleVideo={() => setCallState(s => ({...s, video: !s.video}))}
onHangup={onHangup}
/>
</div>
);
};
const PipCall = ({ onExpand, onHangup, participants }) => {
const speaker = participants.find(p => p.sharing) || participants.find(p => p.speaking) || participants[0];
return (
<div className="pip-call" onClick={onExpand}>
<div className="pip-preview">
{speaker.sharing ? (
<div className="screenshare-stub small"><div className="ss-window mini"></div></div>
) : (
<Avatar chat={{initial: speaker.initial, color: speaker.color}} size="sm" />
)}
</div>
<div className="pip-info">
<div className="pip-title">Die Squad · {participants.length}</div>
<div className="pip-sub">
<span className="live-dot"></span>
Live · tippe zum Öffnen
</div>
</div>
<button className="pip-hangup" onClick={(e) => { e.stopPropagation(); onHangup(); }}>
<Icon.PhoneOff />
</button>
</div>
);
};
Object.assign(window, { CALL_PARTICIPANTS, ParticipantTile, CallControls, IncomingCallScreen, ActiveCallScreen, PipCall });
@@ -0,0 +1,28 @@
// Sample data
const CHATS = [
{ id: 'test', name: 'test', handle: '@test', color: 'violet', initial: 'T', preview: 'Hallo 👋', time: '21:13', unread: false, presence: 'offline', active: true },
{ id: 'max', name: 'Max', handle: '@maxx', color: 'teal', initial: 'M', preview: 'bro du musst das sehen', time: '20:44', unread: true, presence: 'online' },
{ id: 'squad', name: 'Die Squad', handle: '5 Mitglieder', color: 'rose', initial: 'S', preview: 'leon: bin gleich da', time: '19:12', unread: true, presence: 'online', isGroup: true },
{ id: 'lena', name: 'Lena', handle: '@lenae', color: 'amber', initial: 'L', preview: 'Du: ok passt', time: 'Gestern', unread: false, presence: 'idle' },
{ id: 'tom', name: 'Tom', handle: '@tomg', color: 'violet', initial: 'T', preview: 'sent a photo', time: 'Gestern', unread: false, presence: 'dnd' },
{ id: 'nico', name: 'nico', handle: '@nicoo', color: 'teal', initial: 'N', preview: 'gg wp', time: 'Mo.', unread: false, presence: 'offline' },
];
const MESSAGES = [
{ type: 'message', from: 'them', text: 'Hi', time: '20:12' },
{ type: 'message', from: 'them', text: 'Lol', time: '20:14' },
{ type: 'message', from: 'them', text: 'Wie gehts', time: '20:24' },
{ type: 'message', from: 'them', text: 'einer da?', time: '20:25' },
{ type: 'message', from: 'them', text: 'Hallo', time: '21:03', reactions: [{emoji: '👋', count: 1, mine: true}] },
{ type: 'event', kind: 'call', icon: 'phone', text: 'Eingehender Anruf', duration: '1:01', time: '21:06' },
{ type: 'event', kind: 'rejected', icon: 'phone-off', text: 'Anruf abgelehnt', time: '21:06' },
{ type: 'event', kind: 'rejected', icon: 'phone-off', text: 'Anruf abgelehnt', time: '21:06' },
{ type: 'message', from: 'me', text: 'sry war afk', time: '21:09', reactions: [{emoji: '😅', count: 2}, {emoji: '❤️', count: 1, mine: true}] },
{ type: 'media', from: 'me', filename: 'IMG_4120.jpg', size: '2.4 MB', label: '[ PLACEHOLDER IMAGE ]', time: '21:10' },
{ type: 'message', from: 'them', text: 'pushhh sick', time: '21:12' },
{ type: 'message', from: 'me', text: 'Hallo', time: '21:13', read: true },
{ type: 'typing', from: 'them' },
];
Object.assign(window, { CHATS, MESSAGES });
@@ -0,0 +1,87 @@
// Shared SVG icon components
const Icon = {
Logo: () => (
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
<path d="M4 6 L12 2 L20 6 L20 18 L12 22 L4 18 Z" stroke="currentColor" strokeWidth="1.8" strokeLinejoin="round"/>
<path d="M4 6 L12 10 L20 6" stroke="currentColor" strokeWidth="1.8" strokeLinejoin="round"/>
<path d="M12 10 L12 22" stroke="currentColor" strokeWidth="1.8"/>
</svg>
),
Chat: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
),
Friends: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
),
Settings: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
),
Shield: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
),
Phone: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/></svg>
),
PhoneOff: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.42 19.42 0 0 1-3.33-2.67m-2.67-3.34a19.79 19.79 0 0 1-3.07-8.63A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91"/><line x1="23" y1="1" x2="1" y2="23"/></svg>
),
Video: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2" ry="2"/></svg>
),
Search: () => (
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
),
Plus: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
),
Send: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
),
AddUser: () => (
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="8.5" cy="7" r="4"/><line x1="20" y1="8" x2="20" y2="14"/><line x1="23" y1="11" x2="17" y2="11"/></svg>
),
Chevron: () => (
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><polyline points="6 9 12 15 18 9"/></svg>
),
Paperclip: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>
),
Smile: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"/><path d="M8 14s1.5 2 4 2 4-2 4-2"/><line x1="9" y1="9" x2="9.01" y2="9"/><line x1="15" y1="9" x2="15.01" y2="9"/></svg>
),
Mic: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></svg>
),
Sun: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"/></svg>
),
Moon: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>
),
MicOff: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><line x1="1" y1="1" x2="23" y2="23"/><path d="M9 9v3a3 3 0 0 0 5.12 2.12M15 9.34V4a3 3 0 0 0-5.94-.6"/><path d="M17 16.95A7 7 0 0 1 5 12v-2m14 0v2a7 7 0 0 1-.11 1.23"/><line x1="12" y1="19" x2="12" y2="23"/></svg>
),
Monitor: () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>
),
Lock: () => (
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
),
Crown: () => (
<svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><path d="M5 16l-2-8 5 4 4-7 4 7 5-4-2 8z"/></svg>
),
Grid: () => (
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/></svg>
),
Focus: () => (
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="4" width="18" height="12" rx="1"/><rect x="3" y="18" width="4" height="3" rx="0.5"/><rect x="9" y="18" width="4" height="3" rx="0.5"/><rect x="15" y="18" width="4" height="3" rx="0.5"/></svg>
),
Maximize: () => (
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg>
),
Minimize: () => (
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M4 14h6v6M20 10h-6V4M14 10l7-7M3 21l7-7"/></svg>
),
};
Object.assign(window, { Icon });
Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

+459
View File
@@ -0,0 +1,459 @@
/* ================= BASE ================= */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
width: 100%;
min-height: 100vh;
overflow-x: hidden;
}
body {
font-family: var(--font-body, 'Inter', system-ui, sans-serif);
background: var(--bg, #0e0e12);
color: var(--fg, #eaeaea);
-webkit-font-smoothing: antialiased;
transition: background 0.3s ease;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }
/* Variant switcher — top fixed */
.variant-switcher {
position: fixed;
top: 12px; left: 50%; transform: translateX(-50%);
z-index: 100;
display: flex; gap: 6px;
padding: 6px;
background: rgba(20,20,24,0.85);
backdrop-filter: blur(20px);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 14px;
box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.variant-switcher button {
padding: 8px 14px;
font-size: 12px;
font-weight: 500;
color: rgba(255,255,255,0.6);
border-radius: 9px;
transition: all 0.2s;
white-space: nowrap;
font-family: 'Inter', system-ui, sans-serif;
}
.variant-switcher button:hover { color: #fff; background: rgba(255,255,255,0.05); }
.variant-switcher button.active {
color: #fff;
background: rgba(255,255,255,0.12);
}
.variant-container {
padding-top: 72px;
min-height: 100vh;
}
/* Variant wrapper */
.variant {
display: none;
width: 100%;
}
.variant.active { display: block; }
/* Device frame — desktop window */
.app-window {
width: min(1320px, 96vw);
margin: 0 auto 60px;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 30px 80px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05);
height: 820px;
display: flex;
flex-direction: column;
}
.window-bar {
height: 38px;
flex-shrink: 0;
display: flex;
align-items: center;
padding: 0 14px;
gap: 8px;
}
.window-bar .dots { display: flex; gap: 7px; }
.window-bar .dot { width: 12px; height: 12px; border-radius: 50%; }
.window-bar .title {
flex: 1; text-align: center; font-size: 12px;
letter-spacing: 0.02em;
}
.app-body {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.top-nav {
height: 56px;
display: flex;
align-items: center;
padding: 0 20px;
gap: 20px;
flex-shrink: 0;
}
.nav-brand {
display: flex; align-items: center; gap: 10px;
font-weight: 700;
letter-spacing: -0.02em;
}
.nav-tabs {
display: flex;
gap: 4px;
flex: 1;
margin-left: 20px;
}
.nav-tab {
padding: 8px 14px;
font-size: 13px;
border-radius: 8px;
display: flex; align-items: center; gap: 8px;
transition: all 0.15s;
}
.nav-user {
display: flex;
align-items: center;
gap: 10px;
padding: 4px 10px 4px 4px;
border-radius: 999px;
}
.main-area {
flex: 1;
display: grid;
grid-template-columns: 320px 1fr;
overflow: hidden;
min-height: 0;
}
/* Chat list */
.chat-list {
display: flex;
flex-direction: column;
overflow: hidden;
}
.chat-list-header {
padding: 16px 18px;
display: flex;
justify-content: space-between;
align-items: center;
}
.chat-list-title { font-weight: 600; font-size: 14px; letter-spacing: 0.01em; }
.chat-search {
margin: 0 14px 10px;
padding: 9px 12px;
border-radius: 10px;
font-size: 13px;
outline: none;
border: none;
}
.chat-items { flex: 1; overflow-y: auto; padding: 4px 10px; }
.chat-item {
display: flex; align-items: center; gap: 12px;
padding: 10px 12px;
border-radius: 10px;
cursor: pointer;
margin-bottom: 2px;
transition: background 0.15s;
}
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-name { font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.chat-item-preview {
font-size: 12px;
opacity: 0.6;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-top: 2px;
}
.chat-item-time { font-size: 10px; opacity: 0.5; font-weight: 400; }
.unread-dot {
width: 8px; height: 8px; border-radius: 50%;
margin-left: 6px;
flex-shrink: 0;
}
/* Avatar */
.avatar {
width: 38px; height: 38px;
border-radius: 50%;
display: flex; align-items: center; justify-content: center;
font-weight: 600;
font-size: 14px;
flex-shrink: 0;
position: relative;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 44px; height: 44px; font-size: 16px; }
.presence {
position: absolute;
bottom: -1px; right: -1px;
width: 12px; height: 12px;
border-radius: 50%;
border: 2px solid var(--bg, #0e0e12);
}
.presence.online { background: #22c55e; }
.presence.idle { background: #f59e0b; }
.presence.dnd { background: #ef4444; }
.presence.offline { background: #71717a; }
/* Chat area */
.chat-area {
display: flex;
flex-direction: column;
overflow: hidden;
min-width: 0;
}
.chat-header {
height: 64px;
padding: 0 22px;
display: flex;
align-items: center;
gap: 14px;
flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-weight: 600; font-size: 15px; }
.chat-header-status { font-size: 11px; opacity: 0.6; margin-top: 2px; }
.chat-header-actions { display: flex; gap: 4px; }
.icon-btn {
width: 34px; height: 34px;
border-radius: 9px;
display: flex; align-items: center; justify-content: center;
transition: background 0.15s;
}
.messages {
flex: 1;
overflow-y: auto;
padding: 20px 26px;
display: flex;
flex-direction: column;
gap: 4px;
}
.message-row {
display: flex;
gap: 8px;
align-items: flex-end;
margin-bottom: 14px;
width: 100%;
}
.message-row.me { justify-content: flex-end; }
.message-row.them { justify-content: flex-start; }
.message-avatar-slot {
width: 28px;
flex-shrink: 0;
}
.message-row .message-group {
margin-bottom: 0;
min-width: 0;
max-width: calc(100% - 40px);
flex: 1 1 auto;
align-items: flex-start;
}
.message-row.me .message-group { align-items: flex-end; }
.message-row .bubble { max-width: 100%; width: fit-content; }
.message-row.me .bubble { margin-left: auto; }
.message-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.message-group.me { align-items: flex-end; }
.message-group.them { align-items: flex-start; }
.message-sender {
font-size: 11px;
font-weight: 600;
margin-bottom: 4px;
opacity: 0.7;
padding: 0 4px;
}
.bubble {
max-width: 70%;
min-width: 60px;
padding: 10px 14px;
border-radius: 18px;
font-size: 14px;
line-height: 1.45;
position: relative;
word-wrap: break-word;
white-space: normal;
}
.bubble .ts {
font-size: 10px;
opacity: 0.5;
margin-top: 2px;
display: block;
white-space: nowrap;
}
.reactions {
display: flex;
gap: 4px;
margin-top: 4px;
flex-wrap: wrap;
}
.reaction {
font-size: 11px;
padding: 3px 8px;
border-radius: 999px;
display: flex; align-items: center; gap: 4px;
cursor: pointer;
transition: all 0.15s;
}
.reaction .count { font-weight: 600; opacity: 0.8; }
/* System events (calls etc) */
.event-row { display: flex; justify-content: center; margin: 10px 0; }
.event-pill {
display: flex; align-items: center; gap: 8px;
padding: 6px 12px;
border-radius: 999px;
font-size: 11px;
font-weight: 500;
white-space: nowrap;
}
.event-pill svg { width: 12px; height: 12px; }
/* Media preview */
.media-preview {
width: 240px;
border-radius: 14px;
overflow: hidden;
position: relative;
}
.media-preview .media-image {
width: 100%;
aspect-ratio: 4/3;
background: repeating-linear-gradient(
45deg,
rgba(255,255,255,0.04),
rgba(255,255,255,0.04) 10px,
rgba(255,255,255,0.07) 10px,
rgba(255,255,255,0.07) 20px
);
display: flex; align-items: center; justify-content: center;
font-size: 10px; font-family: 'JetBrains Mono', monospace; opacity: 0.5;
letter-spacing: 0.1em;
}
.media-preview .media-meta {
padding: 10px 12px;
font-size: 11px;
display: flex; justify-content: space-between;
font-family: 'JetBrains Mono', monospace;
opacity: 0.7;
}
/* Composer */
.composer {
padding: 14px 20px 18px;
flex-shrink: 0;
display: flex;
align-items: center;
gap: 10px;
}
.composer-box {
flex: 1;
display: flex;
align-items: center;
gap: 8px;
padding: 4px 4px 4px 12px;
border-radius: 12px;
min-height: 44px;
}
.composer-box input {
flex: 1;
background: none;
border: none;
outline: none;
color: inherit;
font-size: 14px;
padding: 8px 0;
}
.composer-btn {
width: 36px; height: 36px;
border-radius: 9px;
display: flex; align-items: center; justify-content: center;
flex-shrink: 0;
}
/* Incoming call overlay */
.call-overlay {
position: absolute;
right: 24px;
bottom: 100px;
width: 300px;
border-radius: 16px;
padding: 16px;
display: flex;
align-items: center;
gap: 14px;
box-shadow: 0 20px 60px rgba(0,0,0,0.4);
animation: slideInCall 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slideInCall {
from { transform: translateX(120%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
.call-info { flex: 1; min-width: 0; }
.call-name { font-weight: 600; font-size: 14px; }
.call-sub { font-size: 11px; opacity: 0.7; margin-top: 2px; }
.call-actions { display: flex; gap: 6px; }
.call-btn {
width: 36px; height: 36px;
border-radius: 50%;
display: flex; align-items: center; justify-content: center;
color: white;
}
.call-btn.accept { background: #22c55e; }
.call-btn.decline { background: #ef4444; }
/* Profile hover card */
.profile-card {
position: absolute;
z-index: 10;
width: 280px;
border-radius: 14px;
overflow: hidden;
box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}
.profile-card-banner { height: 64px; }
.profile-card-body { padding: 14px; margin-top: -20px; position: relative; }
.profile-card-avatar {
width: 60px; height: 60px;
border-radius: 50%;
border: 4px solid var(--bg);
display: flex; align-items: center; justify-content: center;
font-weight: 700;
font-size: 22px;
}
.profile-card-name { font-weight: 700; font-size: 16px; margin-top: 10px; }
.profile-card-handle { font-size: 12px; opacity: 0.6; }
.profile-card-meta {
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid rgba(255,255,255,0.08);
font-size: 11px;
display: flex; flex-direction: column; gap: 6px;
opacity: 0.8;
}
/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
+529
View File
@@ -0,0 +1,529 @@
/* ============ CALL UI — Clean Rail matched ============ */
/* Discord-style call dock: call takes top portion, chat continues below */
.call-dock {
flex-shrink: 0;
height: 50%;
max-height: 420px;
min-height: 280px;
border-bottom: 1px solid var(--line);
display: flex;
flex-direction: column;
overflow: hidden;
background: var(--bg-2);
}
.call-dock > .active-call {
flex: 1;
min-height: 0;
}
.call-dock .call-topbar { padding: 8px 14px; }
.call-dock .call-stage { padding: 10px; }
.call-dock .grid { gap: 8px; }
.call-dock .participant-tile { border-radius: 10px; }
.call-dock .audio-ring .avatar.lg { width: 52px; height: 52px; font-size: 20px; }
.call-dock .participant-meta { padding: 4px 8px; font-size: 11px; bottom: 6px; left: 6px; right: 6px; }
.call-dock .participant-name { font-size: 11px; }
.call-dock .pi { width: 18px; height: 18px; }
/* When docked, compact the controls */
.call-dock .call-controls { padding: 8px; gap: 8px; }
.call-dock .cc-btn { width: 36px; height: 36px; border-radius: 10px; }
.call-dock .cc-btn.hangup { width: 54px; }
.call-dock .ss-content { padding: 8px; gap: 4px; }
.call-dock .ss-line { height: 4px; }
.call-dock .ss-block { height: 20px; }
.call-dock .ss-badge { font-size: 9px; padding: 3px 7px; }
/* Screen switcher pill (top-right of window) */
.screen-switcher {
position: absolute;
top: 52px;
right: 20px;
z-index: 50;
display: flex;
gap: 4px;
padding: 4px;
background: var(--bg-2);
border: 1px solid var(--line);
border-radius: 10px;
font-size: 11px;
}
.screen-switcher button {
padding: 6px 10px;
border-radius: 7px;
color: var(--fg-muted);
font-weight: 500;
}
.screen-switcher button.active { background: var(--accent); color: #fff; }
/* Call stage overlay */
.call-screen {
position: absolute;
inset: 38px 0 0 0; /* below window bar */
background: var(--bg);
display: flex;
flex-direction: column;
overflow: hidden;
}
/* === Incoming Call === */
.incoming-call {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
background:
radial-gradient(circle at 30% 20%, rgba(79,70,229,0.15), transparent 50%),
radial-gradient(circle at 70% 80%, rgba(109,115,255,0.1), transparent 50%),
var(--bg);
}
.incoming-card {
width: 420px;
padding: 40px 32px 28px;
background: var(--bg-3);
border: 1px solid var(--line);
border-radius: 24px;
text-align: center;
box-shadow: 0 20px 60px rgba(0,0,0,0.1);
}
.variant-clean.dark .incoming-card { box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.incoming-ringing {
font-size: 12px;
text-transform: uppercase;
letter-spacing: 0.12em;
color: var(--fg-muted);
font-weight: 600;
}
.incoming-avatar {
margin: 22px auto 18px;
width: 112px; height: 112px;
position: relative;
display: flex; align-items: center; justify-content: center;
}
.incoming-avatar .avatar.lg {
width: 96px; height: 96px;
font-size: 40px;
font-weight: 700;
border: 3px solid var(--bg-3);
}
.pulse-ring {
position: absolute;
inset: 0;
border: 2px solid var(--accent);
border-radius: 50%;
opacity: 0;
animation: pulseRing 2s ease-out infinite;
}
.pulse-ring.d2 { animation-delay: 1s; }
@keyframes pulseRing {
0% { transform: scale(0.85); opacity: 0.6; }
100% { transform: scale(1.25); opacity: 0; }
}
.incoming-name {
font-size: 24px;
font-weight: 700;
font-family: 'Outfit', 'Inter', sans-serif;
letter-spacing: -0.02em;
}
.incoming-sub {
margin-top: 6px;
font-size: 12px;
color: var(--fg-muted);
display: flex; align-items: center; justify-content: center; gap: 6px;
}
.incoming-actions {
margin-top: 28px;
display: flex;
gap: 12px;
justify-content: center;
}
.incoming-btn {
flex: 1;
padding: 14px 20px;
border-radius: 14px;
font-size: 14px;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
transition: all 0.15s;
}
.incoming-btn.decline {
background: transparent;
color: #dc2626;
border: 1px solid rgba(220,38,38,0.3);
}
.variant-clean.dark .incoming-btn.decline { color: #fb7185; border-color: rgba(251,113,133,0.3); }
.incoming-btn.decline:hover { background: rgba(220,38,38,0.08); }
.incoming-btn.accept {
background: #16a34a;
color: #fff;
box-shadow: 0 4px 14px rgba(22,163,74,0.3);
}
.incoming-btn.accept:hover { background: #15803d; }
/* === Active Call === */
.active-call {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
background: linear-gradient(180deg, var(--bg-2), var(--bg));
}
.call-topbar {
padding: 14px 20px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid var(--line);
background: var(--bg-3);
}
.call-topbar-left { display: flex; flex-direction: column; gap: 2px; }
.call-title {
display: flex; align-items: center; gap: 8px;
font-weight: 600; font-size: 14px;
}
.call-dot { opacity: 0.4; }
.call-duration { font-variant-numeric: tabular-nums; color: var(--fg-muted); font-size: 13px; }
.call-e2ee {
display: flex; align-items: center; gap: 5px;
font-size: 11px; color: #16a34a; font-weight: 500;
}
.variant-clean.dark .call-e2ee { color: #4ade80; }
.call-topbar-right { display: flex; gap: 4px; }
.call-stage {
flex: 1;
padding: 16px;
overflow: hidden;
display: flex;
}
/* Participant tiles */
.participant-tile {
position: relative;
background: var(--bg-3);
border: 1px solid var(--line);
border-radius: 14px;
overflow: hidden;
cursor: pointer;
transition: all 0.2s;
display: flex;
flex-direction: column;
}
.participant-tile:hover { border-color: var(--accent); }
.participant-tile.speaking { border-color: #16a34a; box-shadow: 0 0 0 2px rgba(22,163,74,0.25); }
.participant-tile.focused { border-color: var(--accent); }
.participant-tile.small { min-width: 140px; }
.participant-audio, .participant-video {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
min-height: 0;
overflow: hidden;
}
.audio-ring {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.audio-ring .avatar.lg {
width: 72px; height: 72px;
font-size: 28px;
font-weight: 700;
}
.participant-tile.small .audio-ring .avatar.lg { width: 44px; height: 44px; font-size: 18px; }
.audio-ring.pulse::before {
content: '';
position: absolute;
inset: -6px;
border-radius: 50%;
border: 2px solid #22c55e;
animation: audioPulse 1.3s ease-out infinite;
}
@keyframes audioPulse {
0% { transform: scale(1); opacity: 0.8; }
100% { transform: scale(1.3); opacity: 0; }
}
.video-stub {
width: 100%; height: 100%;
background:
radial-gradient(circle at 30% 40%, rgba(109,115,255,0.2), transparent 60%),
linear-gradient(135deg, #1a1a24, #0A0A0F);
display: flex;
align-items: center;
justify-content: center;
}
.variant-clean:not(.dark) .video-stub { background: linear-gradient(135deg, #e0e7ff, #c7d2fe); }
/* Screenshare stub */
.screenshare-stub {
width: 100%; height: 100%;
position: relative;
background: #0A0A0F;
padding: 12px;
display: flex;
align-items: center;
justify-content: center;
}
.variant-clean:not(.dark) .screenshare-stub { background: #111118; }
.ss-window {
width: 90%; height: 85%;
background: #1a1a24;
border-radius: 8px;
overflow: hidden;
border: 1px solid rgba(255,255,255,0.06);
}
.ss-chrome {
height: 20px;
background: #252533;
display: flex;
align-items: center;
padding: 0 8px;
gap: 4px;
}
.ss-chrome span { width: 6px; height: 6px; border-radius: 50%; background: #3A3A4D; }
.ss-content { padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.ss-line { height: 6px; background: #3A3A4D; border-radius: 3px; }
.ss-block { height: 40px; background: rgba(109,115,255,0.25); border-radius: 4px; margin: 4px 0; }
.participant-tile.small .ss-content { padding: 6px; gap: 3px; }
.participant-tile.small .ss-line { height: 3px; }
.participant-tile.small .ss-block { height: 14px; }
.ss-badge {
position: absolute;
top: 12px; left: 12px;
padding: 4px 10px;
background: rgba(0,0,0,0.6);
backdrop-filter: blur(8px);
color: #fff;
border-radius: 8px;
font-size: 10px;
font-weight: 500;
display: flex; align-items: center; gap: 5px;
}
.participant-tile.small .ss-badge { display: none; }
.participant-meta {
position: absolute;
bottom: 8px; left: 8px; right: 8px;
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
padding: 6px 10px;
background: rgba(0,0,0,0.55);
backdrop-filter: blur(10px);
border-radius: 8px;
color: #fff;
}
.participant-tile.small .participant-meta { padding: 4px 8px; font-size: 10px; }
.participant-name {
display: flex; align-items: center; gap: 5px;
font-size: 12px;
font-weight: 600;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.e2ee-dot { opacity: 0.7; display: flex; }
.participant-icons { display: flex; gap: 4px; }
.pi {
width: 20px; height: 20px;
border-radius: 6px;
display: flex; align-items: center; justify-content: center;
}
.pi.muted { background: rgba(220,38,38,0.8); }
.pi.sharing { background: rgba(34,197,94,0.8); }
/* Grid layouts */
.grid {
display: grid;
gap: 10px;
width: 100%; height: 100%;
}
.grid-1 { grid-template-columns: 1fr; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
.grid-5, .grid-6 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); }
/* Focus layout */
.focus-layout {
width: 100%; height: 100%;
display: flex;
flex-direction: column;
gap: 10px;
}
.focus-main { flex: 1; min-height: 0; }
.focus-main .participant-tile { height: 100%; }
.focus-strip {
height: 110px;
display: flex;
gap: 10px;
overflow-x: auto;
}
.focus-strip .participant-tile { min-width: 160px; height: 100%; }
/* Fullscreen layout (hides topbar, pure cinema) */
.active-call.mode-fullscreen .call-topbar { display: none; }
.active-call.mode-fullscreen .call-stage { padding: 0; position: relative; }
.fullscreen-layout {
width: 100%; height: 100%;
position: relative;
}
.fullscreen-layout > .participant-tile { width: 100%; height: 100%; border-radius: 0; border: none; }
.fs-strip {
position: absolute;
bottom: 90px;
right: 16px;
display: flex;
flex-direction: column;
gap: 8px;
width: 180px;
}
.fs-strip .participant-tile { height: 100px; backdrop-filter: blur(20px); background: rgba(0,0,0,0.4); }
/* Call controls bar */
.call-controls {
padding: 16px;
display: flex;
justify-content: center;
gap: 10px;
background: var(--bg-3);
border-top: 1px solid var(--line);
}
.active-call.mode-fullscreen .call-controls {
position: absolute;
bottom: 16px; left: 50%; transform: translateX(-50%);
background: rgba(10,10,15,0.7);
backdrop-filter: blur(20px);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 18px;
padding: 10px;
}
.cc-btn {
width: 48px; height: 48px;
border-radius: 14px;
background: var(--bg-2);
color: var(--fg);
display: flex; align-items: center; justify-content: center;
transition: all 0.15s;
border: 1px solid var(--line);
}
.cc-btn:hover { background: var(--bg); transform: translateY(-1px); }
.cc-btn.sm { width: 32px; height: 32px; border-radius: 8px; }
.cc-btn.active-brand { background: var(--accent); color: #fff; border-color: var(--accent); }
.cc-btn.active-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.cc-btn.hangup { background: #dc2626; color: #fff; border-color: #dc2626; width: 72px; }
.cc-btn.hangup:hover { background: #b91c1c; }
.active-call.mode-fullscreen .cc-btn { background: rgba(255,255,255,0.08); color: #fff; border-color: rgba(255,255,255,0.1); }
.active-call.mode-fullscreen .cc-btn.active-brand { background: var(--accent); border-color: var(--accent); }
.active-call.mode-fullscreen .cc-btn.active-danger { background: #dc2626; border-color: #dc2626; }
.active-call.mode-fullscreen .cc-btn.hangup { background: #dc2626; border-color: #dc2626; }
/* Exit fullscreen button */
.fs-exit {
position: absolute;
top: 16px;
right: 16px;
z-index: 10;
padding: 8px 14px;
background: rgba(10,10,15,0.7);
backdrop-filter: blur(20px);
border: 1px solid rgba(255,255,255,0.15);
border-radius: 10px;
color: #fff;
font-size: 12px;
font-weight: 500;
display: flex;
align-items: center;
gap: 6px;
transition: all 0.15s;
}
.fs-exit:hover { background: rgba(10,10,15,0.9); transform: translateY(-1px); }
/* Fullscreen hint — subtle, fades in then out */
.fs-hint {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
padding: 6px 14px;
background: rgba(10,10,15,0.6);
backdrop-filter: blur(16px);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 8px;
color: rgba(255,255,255,0.7);
font-size: 11px;
font-weight: 500;
letter-spacing: 0.02em;
z-index: 10;
animation: fsHintFade 3.5s ease-out forwards;
pointer-events: none;
}
@keyframes fsHintFade {
0% { opacity: 0; transform: translate(-50%, -6px); }
15%, 75% { opacity: 1; transform: translate(-50%, 0); }
100% { opacity: 0; transform: translate(-50%, -6px); }
}
/* PiP in chat view */
.pip-call {
position: absolute;
bottom: 82px; right: 20px;
width: 260px;
padding: 10px;
display: flex;
align-items: center;
gap: 10px;
background: var(--bg-3);
border: 1px solid var(--accent);
border-radius: 14px;
box-shadow: 0 12px 40px rgba(0,0,0,0.2), 0 0 0 3px rgba(79,70,229,0.15);
cursor: pointer;
z-index: 30;
animation: slideInCall 0.4s cubic-bezier(0.22,1,0.36,1);
transition: transform 0.15s;
}
.pip-call:hover { transform: translateY(-2px); }
.pip-preview {
width: 44px; height: 44px;
border-radius: 10px;
background: var(--bg-2);
display: flex; align-items: center; justify-content: center;
overflow: hidden;
}
.pip-preview .ss-window.mini {
width: 36px; height: 28px;
background: #1a1a24;
border-radius: 4px;
}
.pip-info { flex: 1; min-width: 0; }
.pip-title { font-weight: 600; font-size: 13px; }
.pip-sub {
font-size: 11px; color: var(--fg-muted);
margin-top: 2px;
display: flex; align-items: center; gap: 5px;
}
.live-dot {
width: 6px; height: 6px; border-radius: 50%;
background: #ef4444;
animation: liveDotPulse 1.5s ease-in-out infinite;
}
@keyframes liveDotPulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
}
.pip-hangup {
width: 32px; height: 32px;
border-radius: 50%;
background: #dc2626;
color: #fff;
display: flex; align-items: center; justify-content: center;
}
+53
View File
@@ -0,0 +1,53 @@
/* Rail layout — Discord-style icon sidebar */
.rail-layout {
flex: 1;
display: grid;
grid-template-columns: 64px 280px 1fr;
overflow: hidden;
min-height: 0;
}
.icon-rail {
display: flex;
flex-direction: column;
align-items: center;
padding: 12px 0;
gap: 6px;
}
.rail-brand {
width: 44px; height: 44px;
border-radius: 14px;
display: flex; align-items: center; justify-content: center;
background: var(--accent, #4F46E5);
color: #fff;
margin-bottom: 4px;
}
.rail-divider { width: 32px; height: 2px; background: rgba(128,128,128,0.2); border-radius: 1px; margin: 4px 0; }
.rail-btn {
width: 44px; height: 44px;
border-radius: 14px;
display: flex; align-items: center; justify-content: center;
color: var(--fg-muted);
position: relative;
transition: all 0.15s;
}
.rail-btn:hover { background: rgba(128,128,128,0.1); color: var(--fg); border-radius: 12px; }
.rail-btn.active { background: var(--accent); color: #fff; border-radius: 12px; }
.rail-pill {
position: absolute;
left: -12px; top: 50%; transform: translateY(-50%);
width: 4px; height: 24px;
background: var(--fg);
border-radius: 0 3px 3px 0;
}
.rail-chatlist { display: flex; flex-direction: column; }
.rail-chatlist .chat-items { flex: 1; }
.rail-user {
padding: 10px 12px;
display: flex; align-items: center; gap: 10px;
flex-shrink: 0;
}
.variant-clean.layout-rail .icon-rail { background: var(--bg-2); border-right: 1px solid var(--line); }
.variant-clean.layout-rail .rail-chatlist { background: var(--bg-3); border-right: 1px solid var(--line); }
.variant-clean.layout-rail .rail-user { background: var(--bg-2); border-top: 1px solid var(--line); }
.variant-clean.layout-rail .rail-brand { background: var(--accent); color: #fff; }
+461
View File
@@ -0,0 +1,461 @@
/* ================= VARIANT 1: CLEAN MINIMAL (Light) ================= */
.variant-clean {
--bg: #fafaf9;
--bg-2: #f4f4f2;
--bg-3: #ffffff;
--fg: #0a0a0f;
--fg-muted: #737380;
--line: rgba(10,10,15,0.08);
--accent: #4F46E5;
--accent-fg: #ffffff;
background: var(--bg);
color: var(--fg);
font-family: 'Inter', system-ui, sans-serif;
}
.variant-clean .nav-brand { font-family: 'Outfit', 'Inter', sans-serif; font-weight: 700; letter-spacing: -0.02em; }
/* Dark mode for Clean */
.variant-clean.dark {
--bg: #050507;
--bg-2: #111118;
--bg-3: #0A0A0F;
--fg: #f4f4f5;
--fg-muted: #8a8a99;
--line: rgba(255,255,255,0.07);
--accent: #6D73FF;
--accent-fg: #ffffff;
}
.variant-clean.dark .app-window { background: var(--bg-3); box-shadow: 0 30px 80px rgba(0,0,0,0.5), 0 0 0 1px var(--line); }
.variant-clean.dark .avatar { background: #1A1A24; color: #DDE0FF; }
.variant-clean.dark .avatar[data-color="violet"] { background: #312E81; color: #C4B5FD; }
.variant-clean.dark .avatar[data-color="amber"] { background: #422e05; color: #fde68a; }
.variant-clean.dark .avatar[data-color="rose"] { background: #4a1d29; color: #fecdd3; }
.variant-clean.dark .avatar[data-color="teal"] { background: #134e4a; color: #99f6e4; }
.variant-clean.dark .bubble.them { border-color: rgba(255,255,255,0.1); }
.variant-clean.dark .bubble.me { background: var(--accent); color: #fff; }
.variant-clean.dark .nav-tab.active { background: var(--accent); }
.variant-clean.dark .reaction.mine { background: var(--accent); }
.variant-clean.dark .composer-btn { background: var(--accent); }
.variant-clean .app-window { background: var(--bg-3); box-shadow: 0 30px 80px rgba(0,0,0,0.08), 0 0 0 1px var(--line); }
.variant-clean .window-bar { background: var(--bg-2); border-bottom: 1px solid var(--line); }
.variant-clean .window-bar .title { color: var(--fg-muted); font-weight: 500; }
.variant-clean .top-nav { border-bottom: 1px solid var(--line); background: var(--bg-3); }
.variant-clean .nav-brand svg { color: #0a0a0a; }
.variant-clean .nav-tab { color: var(--fg-muted); }
.variant-clean .nav-tab:hover { background: var(--bg-2); color: var(--fg); }
.variant-clean .nav-tab.active { background: var(--accent); color: var(--accent-fg); }
.variant-clean .nav-user { border: 1px solid var(--line); }
.variant-clean .chat-list { border-right: 1px solid var(--line); background: var(--bg-3); }
.variant-clean .chat-list-header { border-bottom: 1px solid var(--line); }
.variant-clean .chat-search { background: var(--bg-2); color: var(--fg); }
.variant-clean .chat-item:hover { background: var(--bg-2); }
.variant-clean .chat-item.active { background: var(--bg-2); }
.variant-clean .avatar { background: #e5e5e5; color: #0a0a0a; }
.variant-clean .avatar[data-color="violet"] { background: #ddd6fe; color: #5b21b6; }
.variant-clean .avatar[data-color="amber"] { background: #fde68a; color: #78350f; }
.variant-clean .avatar[data-color="rose"] { background: #fecdd3; color: #881337; }
.variant-clean .avatar[data-color="teal"] { background: #99f6e4; color: #134e4a; }
.variant-clean .chat-header { border-bottom: 1px solid var(--line); }
.variant-clean .icon-btn { color: var(--fg-muted); }
.variant-clean .icon-btn:hover { background: var(--bg-2); color: var(--fg); }
.variant-clean .bubble.me { background: var(--accent); color: var(--accent-fg); border-radius: 18px 18px 4px 18px; }
.variant-clean .bubble.them { background: transparent; color: var(--fg); border: 1px solid var(--line); border-radius: 18px 18px 18px 4px; }
.variant-clean .reaction { background: var(--bg-2); border: 1px solid var(--line); }
.variant-clean .reaction.mine { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.variant-clean .event-pill { background: var(--bg-2); color: var(--fg-muted); }
.variant-clean .composer { border-top: 1px solid var(--line); }
.variant-clean .composer-box { background: var(--bg-2); }
.variant-clean .composer-btn { background: var(--accent); color: var(--accent-fg); }
.variant-clean .presence { border-color: var(--bg-3); }
/* ================= VARIANT 2: PLAYFUL DISCORD-VIBES ================= */
.variant-playful {
--bg: #1a1625;
--bg-2: #2a2338;
--bg-3: #221b30;
--fg: #f5f3ff;
--fg-muted: #9691b3;
--accent: #a78bfa;
--accent-2: #f472b6;
--accent-3: #60a5fa;
background: radial-gradient(ellipse at top left, #3d1a54 0%, #1a1625 50%);
color: var(--fg);
font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
}
.variant-playful .app-window { background: var(--bg-3); }
.variant-playful .window-bar { background: rgba(0,0,0,0.25); }
.variant-playful .window-bar .title { color: #fff; font-weight: 700; font-size: 13px; }
.variant-playful .top-nav { background: linear-gradient(90deg, #2a1a48 0%, #1a1625 100%); border-bottom: 1px solid rgba(255,255,255,0.05); }
.variant-playful .nav-brand { font-size: 18px; background: linear-gradient(135deg, #f472b6, #a78bfa); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.variant-playful .nav-tab { color: var(--fg-muted); font-weight: 600; }
.variant-playful .nav-tab:hover { background: rgba(255,255,255,0.06); color: #fff; }
.variant-playful .nav-tab.active { background: linear-gradient(135deg, #a78bfa, #f472b6); color: #fff; box-shadow: 0 4px 14px rgba(167,139,250,0.4); }
.variant-playful .nav-user { background: rgba(255,255,255,0.05); }
.variant-playful .chat-list { background: rgba(0,0,0,0.15); border-right: 1px solid rgba(255,255,255,0.04); }
.variant-playful .chat-search { background: rgba(0,0,0,0.3); color: #fff; }
.variant-playful .chat-item:hover { background: rgba(255,255,255,0.04); }
.variant-playful .chat-item.active { background: linear-gradient(90deg, rgba(167,139,250,0.2), rgba(244,114,182,0.1)); }
.variant-playful .avatar { background: linear-gradient(135deg, #a78bfa, #f472b6); color: #fff; font-weight: 800; }
.variant-playful .avatar[data-color="teal"] { background: linear-gradient(135deg, #34d399, #60a5fa); }
.variant-playful .avatar[data-color="amber"] { background: linear-gradient(135deg, #fbbf24, #f472b6); }
.variant-playful .avatar[data-color="rose"] { background: linear-gradient(135deg, #fb7185, #a78bfa); }
.variant-playful .avatar[data-color="violet"] { background: linear-gradient(135deg, #a78bfa, #60a5fa); }
.variant-playful .chat-header { background: rgba(0,0,0,0.2); border-bottom: 1px solid rgba(255,255,255,0.05); }
.variant-playful .icon-btn:hover { background: rgba(255,255,255,0.08); }
.variant-playful .messages { background: radial-gradient(ellipse at bottom right, rgba(244,114,182,0.06), transparent 50%); }
.variant-playful .bubble.me { background: linear-gradient(135deg, #a78bfa, #8b5cf6); color: #fff; border-radius: 20px 20px 4px 20px; box-shadow: 0 4px 14px rgba(167,139,250,0.25); }
.variant-playful .bubble.them { background: rgba(255,255,255,0.06); color: #fff; border-radius: 20px 20px 20px 4px; backdrop-filter: blur(10px); }
.variant-playful .reaction { background: rgba(255,255,255,0.08); }
.variant-playful .reaction.mine { background: rgba(167,139,250,0.3); border: 1px solid #a78bfa; }
.variant-playful .event-pill { background: rgba(52,211,153,0.15); color: #34d399; }
.variant-playful .event-pill.rejected { background: rgba(251,113,133,0.15); color: #fb7185; }
.variant-playful .composer { background: rgba(0,0,0,0.2); }
.variant-playful .composer-box { background: rgba(255,255,255,0.06); }
.variant-playful .composer-btn { background: linear-gradient(135deg, #a78bfa, #f472b6); color: #fff; box-shadow: 0 4px 14px rgba(167,139,250,0.4); }
.variant-playful .presence { border-color: var(--bg-3); }
/* ================= VARIANT 3: Y2K GLASSMORPHISM ================= */
.variant-y2k {
--bg: #0a0a1f;
--fg: #f8fafc;
--fg-muted: rgba(248,250,252,0.6);
--accent: #c7d2fe;
color: var(--fg);
font-family: 'Space Grotesk', 'Inter', sans-serif;
background:
radial-gradient(ellipse 80% 50% at 20% 20%, rgba(168,85,247,0.4), transparent),
radial-gradient(ellipse 60% 40% at 80% 80%, rgba(59,130,246,0.35), transparent),
radial-gradient(ellipse 70% 60% at 50% 50%, rgba(236,72,153,0.2), transparent),
#0a0a1f;
}
.variant-y2k .app-window {
background: rgba(255,255,255,0.04);
backdrop-filter: blur(30px);
-webkit-backdrop-filter: blur(30px);
border: 1px solid rgba(255,255,255,0.12);
box-shadow: 0 30px 80px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}
.variant-y2k .window-bar { background: rgba(255,255,255,0.04); border-bottom: 1px solid rgba(255,255,255,0.08); }
.variant-y2k .window-bar .title { color: rgba(255,255,255,0.7); font-weight: 500; letter-spacing: 0.08em; font-size: 11px; text-transform: uppercase; }
.variant-y2k .top-nav { background: rgba(255,255,255,0.02); border-bottom: 1px solid rgba(255,255,255,0.08); }
.variant-y2k .nav-brand { font-weight: 700; letter-spacing: -0.03em; font-size: 18px; }
.variant-y2k .nav-tab {
color: var(--fg-muted);
font-weight: 500;
border: 1px solid transparent;
}
.variant-y2k .nav-tab:hover { background: rgba(255,255,255,0.06); color: #fff; border-color: rgba(255,255,255,0.1); }
.variant-y2k .nav-tab.active {
background: rgba(255,255,255,0.15);
color: #fff;
border-color: rgba(255,255,255,0.25);
backdrop-filter: blur(10px);
box-shadow: inset 0 1px 0 rgba(255,255,255,0.2);
}
.variant-y2k .nav-user { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); }
.variant-y2k .chat-list { background: rgba(255,255,255,0.02); border-right: 1px solid rgba(255,255,255,0.08); }
.variant-y2k .chat-search { background: rgba(255,255,255,0.06); color: #fff; border: 1px solid rgba(255,255,255,0.08); }
.variant-y2k .chat-item:hover { background: rgba(255,255,255,0.05); }
.variant-y2k .chat-item.active {
background: rgba(255,255,255,0.1);
border: 1px solid rgba(255,255,255,0.15);
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.variant-y2k .avatar {
background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
color: #312e81;
border: 1px solid rgba(255,255,255,0.3);
}
.variant-y2k .avatar[data-color="violet"] { background: linear-gradient(135deg, #e9d5ff, #c4b5fd); color: #4c1d95; }
.variant-y2k .avatar[data-color="rose"] { background: linear-gradient(135deg, #fecdd3, #f9a8d4); color: #831843; }
.variant-y2k .avatar[data-color="teal"] { background: linear-gradient(135deg, #a7f3d0, #7dd3fc); color: #064e3b; }
.variant-y2k .avatar[data-color="amber"] { background: linear-gradient(135deg, #fde68a, #fdba74); color: #7c2d12; }
.variant-y2k .chat-header { background: rgba(255,255,255,0.02); border-bottom: 1px solid rgba(255,255,255,0.08); }
.variant-y2k .icon-btn:hover { background: rgba(255,255,255,0.08); }
.variant-y2k .bubble.me {
background: linear-gradient(135deg, rgba(199,210,254,0.9), rgba(196,181,253,0.8));
color: #1e1b4b;
border-radius: 20px 20px 6px 20px;
backdrop-filter: blur(10px);
border: 1px solid rgba(255,255,255,0.3);
box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 4px 14px rgba(124,58,237,0.2);
}
.variant-y2k .bubble.them {
background: rgba(255,255,255,0.08);
color: #fff;
border: 1px solid rgba(255,255,255,0.12);
border-radius: 20px 20px 20px 6px;
backdrop-filter: blur(20px);
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.variant-y2k .reaction { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.1); backdrop-filter: blur(10px); }
.variant-y2k .reaction.mine { background: rgba(199,210,254,0.25); border-color: rgba(199,210,254,0.5); }
.variant-y2k .event-pill { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.8); border: 1px solid rgba(255,255,255,0.1); backdrop-filter: blur(10px); }
.variant-y2k .event-pill.rejected { background: rgba(251,113,133,0.15); color: #fda4af; border-color: rgba(251,113,133,0.3); }
.variant-y2k .composer { background: rgba(255,255,255,0.02); border-top: 1px solid rgba(255,255,255,0.08); }
.variant-y2k .composer-box { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); backdrop-filter: blur(10px); }
.variant-y2k .composer-btn { background: linear-gradient(135deg, #e0e7ff, #c4b5fd); color: #312e81; border: 1px solid rgba(255,255,255,0.3); box-shadow: inset 0 1px 0 rgba(255,255,255,0.4); }
.variant-y2k .presence { border-color: #0a0a1f; }
/* ================= VARIANT 4: CYBERPUNK NEON ================= */
.variant-cyber {
--bg: #05050a;
--fg: #e0e0e8;
--fg-muted: #6b7280;
--neon-cyan: #00f0ff;
--neon-magenta: #ff00aa;
--neon-lime: #b6ff3d;
color: var(--fg);
font-family: 'JetBrains Mono', 'Courier New', monospace;
background:
repeating-linear-gradient(0deg, transparent 0, transparent 2px, rgba(0,240,255,0.015) 2px, rgba(0,240,255,0.015) 4px),
radial-gradient(ellipse at center, #0c0c18 0%, #05050a 70%);
}
.variant-cyber .app-window {
background: #08080f;
border: 1px solid rgba(0,240,255,0.2);
box-shadow: 0 0 40px rgba(255,0,170,0.15), 0 0 80px rgba(0,240,255,0.08);
}
.variant-cyber .window-bar { background: #05050a; border-bottom: 1px solid rgba(0,240,255,0.15); }
.variant-cyber .window-bar .title { color: var(--neon-cyan); font-size: 11px; letter-spacing: 0.15em; text-transform: uppercase; }
.variant-cyber .window-bar .title::before { content: "// "; opacity: 0.5; }
.variant-cyber .top-nav { background: #05050a; border-bottom: 1px solid rgba(0,240,255,0.15); }
.variant-cyber .nav-brand { color: var(--neon-cyan); text-transform: uppercase; letter-spacing: 0.1em; font-size: 13px; text-shadow: 0 0 10px rgba(0,240,255,0.5); }
.variant-cyber .nav-tab { color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.1em; font-size: 11px; font-weight: 500; border: 1px solid transparent; }
.variant-cyber .nav-tab:hover { color: var(--neon-cyan); border-color: rgba(0,240,255,0.2); }
.variant-cyber .nav-tab.active { color: var(--neon-lime); border-color: var(--neon-lime); background: rgba(182,255,61,0.05); box-shadow: 0 0 10px rgba(182,255,61,0.2); }
.variant-cyber .nav-tab.active::before { content: "> "; }
.variant-cyber .nav-user { border: 1px solid rgba(0,240,255,0.15); }
.variant-cyber .chat-list { background: #05050a; border-right: 1px solid rgba(0,240,255,0.15); }
.variant-cyber .chat-list-title { color: var(--neon-cyan); text-transform: uppercase; letter-spacing: 0.15em; font-size: 11px; }
.variant-cyber .chat-list-title::before { content: "[ "; opacity: 0.5; }
.variant-cyber .chat-list-title::after { content: " ]"; opacity: 0.5; }
.variant-cyber .chat-search { background: #0c0c18; border: 1px solid rgba(0,240,255,0.15); color: var(--fg); }
.variant-cyber .chat-item:hover { background: rgba(0,240,255,0.04); }
.variant-cyber .chat-item.active { background: rgba(0,240,255,0.06); border-left: 2px solid var(--neon-cyan); padding-left: 10px; }
.variant-cyber .chat-item-name { color: var(--fg); }
.variant-cyber .avatar {
background: #0c0c18;
border: 1px solid var(--neon-cyan);
color: var(--neon-cyan);
border-radius: 4px;
font-family: 'JetBrains Mono', monospace;
text-shadow: 0 0 8px rgba(0,240,255,0.5);
}
.variant-cyber .avatar[data-color="violet"] { border-color: var(--neon-magenta); color: var(--neon-magenta); text-shadow: 0 0 8px rgba(255,0,170,0.5); }
.variant-cyber .avatar[data-color="amber"] { border-color: var(--neon-lime); color: var(--neon-lime); text-shadow: 0 0 8px rgba(182,255,61,0.5); }
.variant-cyber .avatar[data-color="rose"] { border-color: #ff5500; color: #ff5500; text-shadow: 0 0 8px rgba(255,85,0,0.5); }
.variant-cyber .avatar[data-color="teal"] { border-color: var(--neon-cyan); color: var(--neon-cyan); }
.variant-cyber .chat-header { background: #05050a; border-bottom: 1px solid rgba(0,240,255,0.15); }
.variant-cyber .chat-header-name { color: var(--neon-cyan); font-family: 'JetBrains Mono', monospace; }
.variant-cyber .chat-header-name::before { content: "@"; opacity: 0.5; }
.variant-cyber .icon-btn { color: var(--neon-cyan); }
.variant-cyber .icon-btn:hover { background: rgba(0,240,255,0.1); }
.variant-cyber .bubble.me {
background: transparent;
color: var(--neon-magenta);
border: 1px solid var(--neon-magenta);
border-radius: 4px;
box-shadow: 0 0 15px rgba(255,0,170,0.15), inset 0 0 15px rgba(255,0,170,0.05);
font-family: 'JetBrains Mono', monospace;
font-size: 13px;
}
.variant-cyber .bubble.them {
background: transparent;
color: var(--neon-cyan);
border: 1px solid var(--neon-cyan);
border-radius: 4px;
box-shadow: 0 0 15px rgba(0,240,255,0.15), inset 0 0 15px rgba(0,240,255,0.05);
font-family: 'JetBrains Mono', monospace;
font-size: 13px;
}
.variant-cyber .bubble .ts { color: rgba(255,255,255,0.4); font-size: 9px; letter-spacing: 0.1em; }
.variant-cyber .reaction { background: #0c0c18; border: 1px solid rgba(0,240,255,0.2); border-radius: 2px; color: var(--neon-lime); }
.variant-cyber .reaction.mine { border-color: var(--neon-lime); box-shadow: 0 0 10px rgba(182,255,61,0.2); }
.variant-cyber .event-pill { background: transparent; border: 1px dashed var(--neon-lime); color: var(--neon-lime); border-radius: 2px; text-transform: uppercase; letter-spacing: 0.1em; font-size: 10px; }
.variant-cyber .event-pill.rejected { border-color: var(--neon-magenta); color: var(--neon-magenta); }
.variant-cyber .composer { background: #05050a; border-top: 1px solid rgba(0,240,255,0.15); }
.variant-cyber .composer-box { background: #0c0c18; border: 1px solid rgba(0,240,255,0.2); border-radius: 4px; }
.variant-cyber .composer-box::before { content: ">"; color: var(--neon-lime); margin-right: 6px; font-weight: bold; }
.variant-cyber .composer-btn { background: var(--neon-lime); color: #05050a; border-radius: 4px; box-shadow: 0 0 15px rgba(182,255,61,0.3); }
.variant-cyber .presence { border-color: #08080f; }
/* ================= VARIANT 5: WARM SOFT ================= */
.variant-warm {
--bg: #f7f2e9;
--bg-2: #efe6d4;
--bg-3: #fdfaf3;
--fg: #3d2e1f;
--fg-muted: #8a7560;
--accent: #c75d3a;
--accent-2: #e8a87c;
--line: rgba(61,46,31,0.1);
background: var(--bg);
color: var(--fg);
font-family: 'Inter', sans-serif;
}
.variant-warm .nav-brand { font-family: 'Fraunces', 'Playfair Display', serif; font-weight: 700; font-size: 20px; letter-spacing: -0.02em; }
.variant-warm .chat-header-name { font-family: 'Fraunces', 'Playfair Display', serif; font-size: 17px; }
.variant-warm .chat-list-title { font-family: 'Fraunces', serif; font-size: 16px; font-weight: 600; }
.variant-warm .app-window { background: var(--bg-3); box-shadow: 0 20px 60px rgba(61,46,31,0.12); border: 1px solid var(--line); }
.variant-warm .window-bar { background: var(--bg-2); border-bottom: 1px solid var(--line); }
.variant-warm .window-bar .title { color: var(--fg-muted); font-weight: 500; }
.variant-warm .top-nav { background: var(--bg-3); border-bottom: 1px solid var(--line); }
.variant-warm .nav-tab { color: var(--fg-muted); font-weight: 500; border-radius: 999px; }
.variant-warm .nav-tab:hover { background: var(--bg-2); color: var(--fg); }
.variant-warm .nav-tab.active { background: var(--accent); color: #fff; }
.variant-warm .nav-user { background: var(--bg-2); border-radius: 999px; }
.variant-warm .chat-list { background: var(--bg-2); }
.variant-warm .chat-search { background: var(--bg-3); border: 1px solid var(--line); color: var(--fg); border-radius: 999px; }
.variant-warm .chat-item { border-radius: 14px; }
.variant-warm .chat-item:hover { background: rgba(255,255,255,0.5); }
.variant-warm .chat-item.active { background: var(--bg-3); box-shadow: 0 2px 8px rgba(61,46,31,0.06); }
.variant-warm .avatar { background: #e8a87c; color: #7c3a1e; font-family: 'Fraunces', serif; font-weight: 700; }
.variant-warm .avatar[data-color="violet"] { background: #bfa4c9; color: #4a2a5c; }
.variant-warm .avatar[data-color="amber"] { background: #e8c87c; color: #5c3e1a; }
.variant-warm .avatar[data-color="rose"] { background: #e8a4a4; color: #5c1e1e; }
.variant-warm .avatar[data-color="teal"] { background: #a4c9bf; color: #1e4a3e; }
.variant-warm .chat-header { background: var(--bg-3); border-bottom: 1px solid var(--line); }
.variant-warm .icon-btn:hover { background: var(--bg-2); }
.variant-warm .messages { background: var(--bg-3); }
.variant-warm .bubble.me { background: var(--accent); color: #fff; border-radius: 20px 20px 6px 20px; }
.variant-warm .bubble.them { background: var(--bg-2); color: var(--fg); border-radius: 20px 20px 20px 6px; }
.variant-warm .reaction { background: var(--bg-2); border: 1px solid var(--line); }
.variant-warm .reaction.mine { background: var(--accent); color: #fff; }
.variant-warm .event-pill { background: var(--bg-2); color: var(--fg-muted); border: 1px solid var(--line); }
.variant-warm .event-pill.rejected { background: rgba(199,93,58,0.1); color: var(--accent); }
.variant-warm .composer { background: var(--bg-3); border-top: 1px solid var(--line); }
.variant-warm .composer-box { background: var(--bg-2); border-radius: 999px; padding-left: 16px; }
.variant-warm .composer-btn { background: var(--accent); color: #fff; border-radius: 50%; }
.variant-warm .presence { border-color: var(--bg-3); }
/* ================= VARIANT 6: BRUTAL GAMING ================= */
.variant-brutal {
--bg: #0d0d0d;
--bg-2: #161616;
--bg-3: #1a1a1a;
--fg: #ffffff;
--fg-muted: #808080;
--lime: #d4ff3d;
--line: #2a2a2a;
background: var(--bg);
color: var(--fg);
font-family: 'Inter', sans-serif;
}
.variant-brutal .nav-brand {
font-family: 'Archivo Black', 'Inter', sans-serif;
font-weight: 900;
font-size: 22px;
text-transform: uppercase;
letter-spacing: -0.03em;
}
.variant-brutal .chat-header-name { font-weight: 800; font-size: 16px; text-transform: uppercase; letter-spacing: -0.01em; }
.variant-brutal .chat-list-title { font-weight: 900; font-size: 18px; text-transform: uppercase; letter-spacing: -0.02em; }
.variant-brutal .app-window { background: var(--bg); border: 2px solid var(--lime); border-radius: 0; box-shadow: 12px 12px 0 var(--lime); }
.variant-brutal .window-bar { background: var(--bg); border-bottom: 2px solid var(--lime); }
.variant-brutal .window-bar .title { color: var(--lime); font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; font-size: 11px; }
.variant-brutal .top-nav { background: var(--bg); border-bottom: 2px solid var(--line); }
.variant-brutal .nav-tab { color: var(--fg-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; font-size: 12px; border-radius: 0; border: 2px solid transparent; }
.variant-brutal .nav-tab:hover { color: var(--fg); background: var(--bg-2); }
.variant-brutal .nav-tab.active { background: var(--lime); color: #000; }
.variant-brutal .nav-user { background: var(--bg-2); border: 2px solid var(--line); border-radius: 0; }
.variant-brutal .chat-list { background: var(--bg); border-right: 2px solid var(--line); }
.variant-brutal .chat-search { background: var(--bg-2); border: 2px solid var(--line); color: var(--fg); border-radius: 0; font-weight: 500; }
.variant-brutal .chat-item { border-radius: 0; border-left: 4px solid transparent; }
.variant-brutal .chat-item:hover { background: var(--bg-2); }
.variant-brutal .chat-item.active { background: var(--bg-2); border-left-color: var(--lime); }
.variant-brutal .chat-item-name { font-weight: 800; text-transform: uppercase; font-size: 13px; letter-spacing: -0.01em; }
.variant-brutal .avatar { background: var(--lime); color: #000; border-radius: 0; font-weight: 900; font-family: 'Archivo Black', sans-serif; }
.variant-brutal .avatar[data-color="violet"] { background: #a78bfa; }
.variant-brutal .avatar[data-color="amber"] { background: #fbbf24; }
.variant-brutal .avatar[data-color="rose"] { background: #fb7185; }
.variant-brutal .avatar[data-color="teal"] { background: #2dd4bf; }
.variant-brutal .chat-header { background: var(--bg); border-bottom: 2px solid var(--line); }
.variant-brutal .icon-btn { border-radius: 0; border: 2px solid var(--line); }
.variant-brutal .icon-btn:hover { background: var(--lime); color: #000; border-color: var(--lime); }
.variant-brutal .bubble.me { background: var(--lime); color: #000; border-radius: 0; font-weight: 600; border: 2px solid #000; box-shadow: 4px 4px 0 #fff; }
.variant-brutal .bubble.them { background: var(--fg); color: #000; border-radius: 0; font-weight: 600; border: 2px solid var(--fg); box-shadow: 4px 4px 0 var(--lime); }
.variant-brutal .bubble .ts { color: rgba(0,0,0,0.6); font-weight: 700; font-size: 10px; text-transform: uppercase; }
.variant-brutal .reaction { background: var(--bg-2); border: 2px solid var(--line); border-radius: 0; font-weight: 700; }
.variant-brutal .reaction.mine { background: var(--lime); color: #000; border-color: var(--lime); }
.variant-brutal .event-pill { background: var(--bg-2); border: 2px solid var(--line); border-radius: 0; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 800; font-size: 11px; }
.variant-brutal .event-pill.rejected { border-color: #fb7185; color: #fb7185; }
.variant-brutal .composer { background: var(--bg); border-top: 2px solid var(--line); }
.variant-brutal .composer-box { background: var(--bg-2); border: 2px solid var(--line); border-radius: 0; }
.variant-brutal .composer-btn { background: var(--lime); color: #000; border-radius: 0; font-weight: 900; }
.variant-brutal .presence { border-color: var(--bg); border-width: 3px; }
/* Profile card & call overlay — inherit from variant */
.variant-clean .profile-card { background: #fff; border: 1px solid var(--line); }
.variant-clean .profile-card-banner { background: linear-gradient(135deg, #e5e5e5, #d4d4d4); }
.variant-clean .profile-card-avatar { border-color: #fff; }
.variant-clean .profile-card-meta { border-top-color: var(--line); color: var(--fg-muted); }
.variant-clean .call-overlay { background: #fff; border: 1px solid var(--line); color: var(--fg); }
.variant-playful .profile-card { background: linear-gradient(180deg, #2a1a48, #1a1625); border: 1px solid rgba(255,255,255,0.08); }
.variant-playful .profile-card-banner { background: linear-gradient(135deg, #a78bfa, #f472b6); }
.variant-playful .profile-card-avatar { border-color: #2a1a48; }
.variant-playful .call-overlay { background: linear-gradient(135deg, #2a1a48, #1a1625); border: 1px solid rgba(167,139,250,0.3); }
.variant-y2k .profile-card { background: rgba(255,255,255,0.08); backdrop-filter: blur(30px); border: 1px solid rgba(255,255,255,0.15); }
.variant-y2k .profile-card-banner { background: linear-gradient(135deg, #c4b5fd, #f9a8d4); }
.variant-y2k .profile-card-avatar { border-color: #1a1a2e; }
.variant-y2k .call-overlay { background: rgba(255,255,255,0.08); backdrop-filter: blur(30px); border: 1px solid rgba(255,255,255,0.15); }
.variant-cyber .profile-card { background: #0c0c18; border: 1px solid var(--neon-cyan); box-shadow: 0 0 30px rgba(0,240,255,0.2); }
.variant-cyber .profile-card-banner { background: repeating-linear-gradient(90deg, #00f0ff, #00f0ff 2px, transparent 2px, transparent 8px), linear-gradient(135deg, #ff00aa 0%, #00f0ff 100%); }
.variant-cyber .profile-card-avatar { border-color: #0c0c18; border-radius: 4px; }
.variant-cyber .call-overlay { background: #0c0c18; border: 1px solid var(--neon-lime); box-shadow: 0 0 30px rgba(182,255,61,0.2); }
.variant-warm .profile-card { background: var(--bg-3); border: 1px solid var(--line); color: var(--fg); }
.variant-warm .profile-card-banner { background: linear-gradient(135deg, #e8a87c, #c75d3a); }
.variant-warm .profile-card-avatar { border-color: var(--bg-3); }
.variant-warm .profile-card-meta { border-top-color: var(--line); }
.variant-warm .call-overlay { background: var(--bg-3); border: 1px solid var(--line); color: var(--fg); }
.variant-brutal .profile-card { background: var(--bg); border: 2px solid var(--lime); border-radius: 0; box-shadow: 8px 8px 0 var(--lime); }
.variant-brutal .profile-card-banner { background: var(--lime); }
.variant-brutal .profile-card-avatar { border-color: var(--bg); border-radius: 0; border-width: 3px; }
.variant-brutal .profile-card-meta { border-top-color: var(--line); }
.variant-brutal .call-overlay { background: var(--bg); border: 2px solid var(--lime); border-radius: 0; box-shadow: 6px 6px 0 var(--lime); }
/* Typing indicator */
.typing { display: inline-flex; gap: 3px; padding: 4px 2px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.4; animation: typingDot 1.3s infinite; }
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingDot {
0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
30% { transform: translateY(-4px); opacity: 1; }
}
/* Tweaks panel */
.tweaks-panel {
position: fixed;
bottom: 20px;
right: 20px;
width: 280px;
background: rgba(20,20,24,0.95);
backdrop-filter: blur(20px);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 14px;
padding: 16px;
z-index: 200;
color: #fff;
font-family: 'Inter', system-ui, sans-serif;
box-shadow: 0 20px 50px rgba(0,0,0,0.5);
display: none;
}
.tweaks-panel.open { display: block; }
.tweaks-panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.7; margin-bottom: 14px; font-weight: 600; }
.tweaks-row { margin-bottom: 12px; }
.tweaks-row label { display: block; font-size: 11px; opacity: 0.6; margin-bottom: 6px; }
.tweaks-row input[type="color"] { width: 100%; height: 34px; border-radius: 8px; background: transparent; border: 1px solid rgba(255,255,255,0.1); cursor: pointer; }
.tweaks-row input[type="range"] { width: 100%; }
.tweaks-row select { width: 100%; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); color: #fff; padding: 8px; border-radius: 8px; font-size: 12px; }
+50
View File
@@ -152,6 +152,56 @@ export async function saveDevicePrivateKey(
await secretStore.setSecret(privateKeySecretName(userId, deviceId), privateKey); await secretStore.setSecret(privateKeySecretName(userId, deviceId), privateKey);
} }
// Restores a device record from a backup by re-seeding the local private key
// store for an EXISTING server-side device row. Does NOT insert a new row —
// the original row is kept intact so conversation-key bundles stay valid.
// Throws when the server-side device was removed (the backup is then unusable;
// user must provision a fresh device and get conv-keys shared from another
// live device).
export async function restoreDeviceFromServerRecord(params: {
client: AppSupabaseClient;
secretStore: SecretStore;
userId: string;
deviceId: string;
privateKey: Uint8Array;
}): Promise<DeviceRecord> {
const { data: session } = await params.client.auth.getUser();
if (!session.user) throw new Error('not authenticated');
if (session.user.id !== params.userId) {
throw new Error(
'Backup is for a different account — sign in as the owner before restoring.',
);
}
const { data: row, error } = await params.client
.from('devices')
.select('id, name, platform, public_key, last_seen_at')
.eq('id', params.deviceId)
.eq('user_id', params.userId)
.maybeSingle();
if (error) throw error;
if (!row) {
throw new Error(
'Device record not found on server — it was removed. Backup is no longer valid; register a new device instead.',
);
}
await saveDevicePrivateKey(
params.secretStore,
params.userId,
params.deviceId,
params.privateKey,
);
return {
id: row.id,
name: row.name,
platform: row.platform,
publicKey: pgHexToBytes(row.public_key),
lastSeenAt: row.last_seen_at,
};
}
// Lightweight helpers for platforms that want to cache their current device id // Lightweight helpers for platforms that want to cache their current device id
// in JSON storage (separate from the secret store, which only holds raw bytes). // in JSON storage (separate from the secret store, which only holds raw bytes).
export const DEVICE_ID_STORAGE_KEY_PREFIX = 'chatapp.device_id'; export const DEVICE_ID_STORAGE_KEY_PREFIX = 'chatapp.device_id';
+5 -2
View File
@@ -3,7 +3,8 @@ import type { AppSupabaseClient } from '../supabase/client.js';
export interface SignupParams { export interface SignupParams {
email: string; email: string;
// Login handle. Lowercased server-side; must match ^[a-z0-9_]{3,32}$ once lowercased. // Login handle. Stored with original casing but uniqueness is case-insensitive
// (citext). Must match ^[A-Za-z0-9_]{3,32}$.
username: string; username: string;
// Optional human-readable name. Defaults to username server-side if omitted. // Optional human-readable name. Defaults to username server-side if omitted.
displayName?: string; displayName?: string;
@@ -29,7 +30,9 @@ export async function signUpWithMagicLink(
shouldCreateUser: true, shouldCreateUser: true,
data: { data: {
invite_code: params.inviteCode, invite_code: params.inviteCode,
username: params.username.toLowerCase(), // Preserve case. `profiles.username` is citext so uniqueness + lookups
// stay case-insensitive regardless of stored casing.
username: params.username.trim(),
display_name: params.displayName ?? params.username, display_name: params.displayName ?? params.username,
...(params.locale ? { locale: params.locale } : {}), ...(params.locale ? { locale: params.locale } : {}),
}, },
+4 -2
View File
@@ -72,7 +72,8 @@ export async function getProfileByUsername(
const { data, error } = await client const { data, error } = await client
.from('profiles') .from('profiles')
.select(PROFILE_COLS) .select(PROFILE_COLS)
.eq('username', username.toLowerCase()) // citext column compares CI server-side — send raw input, don't force case.
.eq('username', username.trim())
.maybeSingle(); .maybeSingle();
if (error) throw error; if (error) throw error;
return data ? mapProfile(data as unknown as ProfileRow) : null; return data ? mapProfile(data as unknown as ProfileRow) : null;
@@ -85,7 +86,8 @@ export async function isUsernameAvailable(
const { count, error } = await client const { count, error } = await client
.from('profiles') .from('profiles')
.select('user_id', { count: 'exact', head: true }) .select('user_id', { count: 'exact', head: true })
.eq('username', username.toLowerCase()); // citext compares CI — no manual normalization needed.
.eq('username', username.trim());
if (error) throw error; if (error) throw error;
return (count ?? 0) === 0; return (count ?? 0) === 0;
} }
+34 -32
View File
@@ -126,9 +126,17 @@ async function fetchKeyBundle(
}; };
} }
// Strips the leading `\x` postgres bytea hex prefix so the RPC's
// `decode(text, 'hex')` accepts it.
function hexNoPrefix(bytes: Uint8Array): string {
return bytesToPgHex(bytes).slice(2);
}
// Bootstraps a brand-new conv-key, wrapping it for every member device that // Bootstraps a brand-new conv-key, wrapping it for every member device that
// currently exists (including the caller's own devices). Used the first time // currently exists (including the caller's own devices). Used the first time
// a conversation needs a key, or when rotation is requested. // a conversation needs a key, or when rotation is requested. All inserts go
// through `share_conv_keys` (SECURITY DEFINER) — silently skips invalid
// recipients, no per-row 403 console spam.
export async function bootstrapConvKey( export async function bootstrapConvKey(
client: AppSupabaseClient, client: AppSupabaseClient,
conversationId: string, conversationId: string,
@@ -141,29 +149,23 @@ export async function bootstrapConvKey(
throw new Error('cannot bootstrap conv key — no recipient devices'); throw new Error('cannot bootstrap conv key — no recipient devices');
} }
const rows: Array<{ const bundles: Array<{ recipient_device_id: string; encrypted_key: string; nonce: string }> = [];
conversation_id: string;
recipient_device_id: string;
key_version: number;
sender_device_id: string;
encrypted_key: string;
nonce: string;
}> = [];
for (const r of recipients) { for (const r of recipients) {
const wrapped = await wrapConvKeyForRecipient(convKey, r.publicKey, own.privateKey); const wrapped = await wrapConvKeyForRecipient(convKey, r.publicKey, own.privateKey);
rows.push({ bundles.push({
conversation_id: conversationId,
recipient_device_id: r.deviceId, recipient_device_id: r.deviceId,
key_version: keyVersion, encrypted_key: hexNoPrefix(wrapped.ciphertext),
sender_device_id: own.deviceId, nonce: hexNoPrefix(wrapped.nonce),
encrypted_key: bytesToPgHex(wrapped.ciphertext),
nonce: bytesToPgHex(wrapped.nonce),
}); });
} }
const { error } = await rawFrom(client, 'conversation_keys').upsert(rows, { // eslint-disable-next-line @typescript-eslint/no-explicit-any
onConflict: 'conversation_id,recipient_device_id,key_version', const rpc = (client as unknown as { rpc: (n: string, p: object) => Promise<{ error: any }> }).rpc;
ignoreDuplicates: true, const { error } = await rpc.call(client, 'share_conv_keys', {
p_conv_id: conversationId,
p_sender_device_id: own.deviceId,
p_key_version: keyVersion,
p_bundles: bundles,
}); });
if (error) throw error; if (error) throw error;
@@ -265,20 +267,20 @@ export async function shareConvKeyToDevice(
recipientPublicKey, recipientPublicKey,
own.privateKey, own.privateKey,
); );
const { error } = await rawFrom(client, 'conversation_keys').upsert( // eslint-disable-next-line @typescript-eslint/no-explicit-any
{ const rpc = (client as unknown as { rpc: (n: string, p: object) => Promise<{ error: any }> }).rpc;
conversation_id: conversationId, const { error } = await rpc.call(client, 'share_conv_keys', {
recipient_device_id: recipientDeviceId, p_conv_id: conversationId,
key_version: version, p_sender_device_id: own.deviceId,
sender_device_id: own.deviceId, p_key_version: version,
encrypted_key: bytesToPgHex(wrapped.ciphertext), p_bundles: [
nonce: bytesToPgHex(wrapped.nonce), {
}, recipient_device_id: recipientDeviceId,
{ encrypted_key: hexNoPrefix(wrapped.ciphertext),
onConflict: 'conversation_id,recipient_device_id,key_version', nonce: hexNoPrefix(wrapped.nonce),
ignoreDuplicates: true, },
}, ],
); });
if (error) throw error; if (error) throw error;
} }
+62 -5
View File
@@ -28,13 +28,21 @@ async function currentUserId(client: AppSupabaseClient): Promise<string> {
export async function listConversations(client: AppSupabaseClient): Promise<ConversationSummary[]> { export async function listConversations(client: AppSupabaseClient): Promise<ConversationSummary[]> {
const myId = await currentUserId(client); const myId = await currentUserId(client);
// 1. Caller's memberships // 1. Caller's memberships. `archived` / `muted_until` live on the members
// row (see migration 20260420000001). db-types snapshot predates them so
// cast the select to bypass typing.
const { data: myMembers, error: mErr } = await client const { data: myMembers, error: mErr } = await client
.from('conversation_members') .from('conversation_members')
.select('conversation_id, role, accepted') .select('conversation_id, role, accepted, archived, muted_until' as '*')
.eq('user_id', myId); .eq('user_id', myId);
if (mErr) throw mErr; if (mErr) throw mErr;
const myMembersList = myMembers ?? []; const myMembersList = (myMembers ?? []) as unknown as Array<{
conversation_id: string;
role: string;
accepted: boolean;
archived: boolean | null;
muted_until: string | null;
}>;
if (myMembersList.length === 0) return []; if (myMembersList.length === 0) return [];
const convIds = myMembersList.map((m) => m.conversation_id); const convIds = myMembersList.map((m) => m.conversation_id);
@@ -103,6 +111,9 @@ export async function listConversations(client: AppSupabaseClient): Promise<Conv
c.type === 'dm' c.type === 'dm'
? (members.find((m) => m.userId !== myId)?.profile ?? null) ? (members.find((m) => m.userId !== myId)?.profile ?? null)
: null; : null;
const mineRow = mine as
| { accepted: boolean; role: string; archived?: boolean; muted_until?: string | null }
| undefined;
return { return {
id: c.id, id: c.id,
type: c.type, type: c.type,
@@ -110,10 +121,56 @@ export async function listConversations(client: AppSupabaseClient): Promise<Conv
avatarUrl: c.avatar_url, avatarUrl: c.avatar_url,
createdAt: c.created_at, createdAt: c.created_at,
peer, peer,
acceptedByMe: mine?.accepted ?? false, acceptedByMe: mineRow?.accepted ?? false,
myRole: mine?.role ?? 'member', myRole: (mineRow?.role ?? 'member') as ConversationSummary['myRole'],
members, members,
lastMessageAt: lastSeen.get(c.id) ?? null, lastMessageAt: lastSeen.get(c.id) ?? null,
archived: mineRow?.archived ?? false,
mutedUntil: mineRow?.muted_until ?? null,
}; };
}); });
} }
// Toggle archive flag on the caller's own conversation_members row.
export async function setConversationArchived(
client: AppSupabaseClient,
conversationId: string,
archived: boolean,
): Promise<void> {
const myId = await currentUserId(client);
const { error } = await client
.from('conversation_members')
.update({ archived } as never)
.eq('conversation_id', conversationId)
.eq('user_id', myId);
if (error) throw error;
}
// Set mute until a specific ISO timestamp (null clears the mute). A
// far-future timestamp is the "muted forever" representation.
export async function setConversationMutedUntil(
client: AppSupabaseClient,
conversationId: string,
until: string | null,
): Promise<void> {
const myId = await currentUserId(client);
const { error } = await client
.from('conversation_members')
.update({ muted_until: until } as never)
.eq('conversation_id', conversationId)
.eq('user_id', myId);
if (error) throw error;
}
// Convenience: `null` unmutes, number means minutes from now. For "forever"
// pass a very large number (e.g. 100 years worth of minutes).
export function muteDurationToIso(minutes: number | null): string | null {
if (minutes === null) return null;
return new Date(Date.now() + minutes * 60 * 1000).toISOString();
}
// True iff the member is currently muted (mutedUntil present and > now).
export function isConversationMuted(mutedUntil: string | null): boolean {
if (!mutedUntil) return false;
return new Date(mutedUntil).getTime() > Date.now();
}
+5
View File
@@ -23,6 +23,11 @@ export interface ConversationSummary {
members: ConversationMember[]; members: ConversationMember[];
// Latest message timestamp (server can't see content, only metadata). // Latest message timestamp (server can't see content, only metadata).
lastMessageAt: string | null; lastMessageAt: string | null;
// Caller's per-member preferences.
archived: boolean;
// ISO timestamp. null = not muted. Past timestamp = expired mute (treat as
// not muted — the server row is kept for history until the next toggle).
mutedUntil: string | null;
} }
export interface ChatMessage { export interface ChatMessage {
+1 -1
View File
@@ -55,7 +55,7 @@ export async function searchProfiles(
query: string, query: string,
limit = 10, limit = 10,
): Promise<ProfileBrief[]> { ): Promise<ProfileBrief[]> {
const trimmed = query.trim().toLowerCase(); const trimmed = query.trim();
if (trimmed.length < 2) return []; if (trimmed.length < 2) return [];
const myId = await currentUserId(client); const myId = await currentUserId(client);
+31 -1
View File
@@ -33,7 +33,37 @@
"call_incoming": "Eingehender Anruf", "call_incoming": "Eingehender Anruf",
"call_missed": "Verpasster Anruf", "call_missed": "Verpasster Anruf",
"call_no_answer": "Keine Antwort", "call_no_answer": "Keine Antwort",
"call_declined": "Anruf abgelehnt" "call_declined": "Anruf abgelehnt",
"you": "Du",
"attachment": "Anhang",
"reply": "Antworten",
"forward": "Weiterleiten",
"replying_to": "Antwort an {{name}}",
"quote_unavailable": "Nachricht nicht verfügbar",
"search_in_conv": "In Unterhaltung suchen…",
"search_none": "Keine Treffer",
"forward_preview": "Vorschau",
"forward_attachments_dropped": "Anhänge werden nicht mit weitergeleitet.",
"forward_no_targets": "Keine anderen Unterhaltungen verfügbar.",
"forward_done": "Gesendet",
"forward_send": "An {{count}} senden",
"forward_attachments_count_one": "{{count}} Anhang wird mit weitergeleitet",
"forward_attachments_count_other": "{{count}} Anhänge werden mit weitergeleitet",
"archive": "Archivieren",
"unarchive": "Entarchivieren",
"archived_title": "Archiv",
"show_archived": "Archiv anzeigen",
"show_active": "Aktive anzeigen",
"archived_empty_title": "Nichts archiviert",
"archived_empty_subtitle": "Archivierte Unterhaltungen erscheinen hier.",
"mute": "Stummschalten",
"unmute": "Stummschaltung aufheben",
"mute_1h": "1 Stunde",
"mute_8h": "8 Stunden",
"mute_24h": "24 Stunden",
"mute_1w": "1 Woche",
"mute_forever": "Bis auf Weiteres",
"row_menu": "Aktionen"
}, },
"call": { "call": {
"start_audio": "Sprachanruf", "start_audio": "Sprachanruf",
@@ -30,8 +30,8 @@
"email_placeholder": "du@beispiel.de", "email_placeholder": "du@beispiel.de",
"username": "Benutzername", "username": "Benutzername",
"username_placeholder": "dennis", "username_placeholder": "dennis",
"username_hint": "Damit meldest du dich an. Nur Kleinbuchstaben.", "username_hint": "Damit meldest du dich an. Groß-/Kleinschreibung bleibt, ist aber nicht unterscheidbar (dennis = Dennis).",
"username_invalid": "Kleinbuchstaben az, Ziffern, Unterstrich · 332 Zeichen.", "username_invalid": "Buchstaben, Ziffern oder Unterstrich · 332 Zeichen.",
"invite_code": "Einladungscode", "invite_code": "Einladungscode",
"invite_hint": "Pflichtfeld · Zugang nur auf Einladung." "invite_hint": "Pflichtfeld · Zugang nur auf Einladung."
}, },
@@ -3,7 +3,7 @@
"network": "Netzwerkfehler. Prüfe deine Verbindung.", "network": "Netzwerkfehler. Prüfe deine Verbindung.",
"ERR_NOT_AUTH": "Du bist nicht angemeldet.", "ERR_NOT_AUTH": "Du bist nicht angemeldet.",
"ERR_INVITE_CODE_REQUIRED": "Einladungscode ist erforderlich.", "ERR_INVITE_CODE_REQUIRED": "Einladungscode ist erforderlich.",
"ERR_USERNAME_INVALID": "Benutzername muss aus Kleinbuchstaben az, Ziffern oder Unterstrich bestehen (332 Zeichen).", "ERR_USERNAME_INVALID": "Benutzername darf nur aus Buchstaben (AZ, az), Ziffern oder Unterstrich bestehen (332 Zeichen).",
"ERR_INVITES_DISABLED": "Registrierungen sind derzeit vom Admin deaktiviert.", "ERR_INVITES_DISABLED": "Registrierungen sind derzeit vom Admin deaktiviert.",
"ERR_INVITE_NOT_FOUND": "Einladungscode nicht gefunden.", "ERR_INVITE_NOT_FOUND": "Einladungscode nicht gefunden.",
"ERR_INVITE_DISABLED": "Diese Einladung wurde deaktiviert.", "ERR_INVITE_DISABLED": "Diese Einladung wurde deaktiviert.",
+31 -1
View File
@@ -33,7 +33,37 @@
"call_incoming": "Incoming call", "call_incoming": "Incoming call",
"call_missed": "Missed call", "call_missed": "Missed call",
"call_no_answer": "No answer", "call_no_answer": "No answer",
"call_declined": "Call declined" "call_declined": "Call declined",
"you": "You",
"attachment": "Attachment",
"reply": "Reply",
"forward": "Forward",
"replying_to": "Replying to {{name}}",
"quote_unavailable": "Message not available",
"search_in_conv": "Search in conversation…",
"search_none": "No matches",
"forward_preview": "Preview",
"forward_attachments_dropped": "Attachments are not forwarded.",
"forward_no_targets": "No other conversations available.",
"forward_done": "Sent",
"forward_send": "Send to {{count}}",
"forward_attachments_count_one": "{{count}} attachment forwarded",
"forward_attachments_count_other": "{{count}} attachments forwarded",
"archive": "Archive",
"unarchive": "Unarchive",
"archived_title": "Archive",
"show_archived": "Show archive",
"show_active": "Show active",
"archived_empty_title": "Nothing archived",
"archived_empty_subtitle": "Archived conversations appear here.",
"mute": "Mute",
"unmute": "Unmute",
"mute_1h": "1 hour",
"mute_8h": "8 hours",
"mute_24h": "24 hours",
"mute_1w": "1 week",
"mute_forever": "Until further notice",
"row_menu": "Actions"
}, },
"call": { "call": {
"start_audio": "Voice call", "start_audio": "Voice call",
@@ -30,8 +30,8 @@
"email_placeholder": "you@example.com", "email_placeholder": "you@example.com",
"username": "Username", "username": "Username",
"username_placeholder": "dennis", "username_placeholder": "dennis",
"username_hint": "You log in with this. Lowercase only.", "username_hint": "You log in with this. Case is preserved but not unique (dennis = Dennis).",
"username_invalid": "Lowercase az, digits, underscore · 332 chars.", "username_invalid": "Letters, digits, or underscore · 332 chars.",
"invite_code": "Invite code", "invite_code": "Invite code",
"invite_hint": "Required · invite-only access." "invite_hint": "Required · invite-only access."
}, },
@@ -3,7 +3,7 @@
"network": "Network error. Check your connection.", "network": "Network error. Check your connection.",
"ERR_NOT_AUTH": "You are not signed in.", "ERR_NOT_AUTH": "You are not signed in.",
"ERR_INVITE_CODE_REQUIRED": "Invite code is required.", "ERR_INVITE_CODE_REQUIRED": "Invite code is required.",
"ERR_USERNAME_INVALID": "Username must be lowercase az, digits, underscore, 332 chars.", "ERR_USERNAME_INVALID": "Username must be letters (AZ, az), digits, or underscore, 332 chars.",
"ERR_INVITES_DISABLED": "Signups are currently disabled by the admin.", "ERR_INVITES_DISABLED": "Signups are currently disabled by the admin.",
"ERR_INVITE_NOT_FOUND": "Invite code not found.", "ERR_INVITE_NOT_FOUND": "Invite code not found.",
"ERR_INVITE_DISABLED": "This invite has been disabled.", "ERR_INVITE_DISABLED": "This invite has been disabled.",
+24 -1
View File
@@ -86,7 +86,7 @@ importers:
i18next: i18next:
specifier: ^23.16.4 specifier: ^23.16.4
version: 23.16.8 version: 23.16.8
libsodium-wrappers: libsodium-wrappers-sumo:
specifier: 0.7.15 specifier: 0.7.15
version: 0.7.15 version: 0.7.15
livekit-client: livekit-client:
@@ -114,6 +114,9 @@ importers:
'@types/libsodium-wrappers': '@types/libsodium-wrappers':
specifier: ^0.7.14 specifier: ^0.7.14
version: 0.7.14 version: 0.7.14
'@types/libsodium-wrappers-sumo':
specifier: ^0.8.2
version: 0.8.2
'@types/react': '@types/react':
specifier: ^18.3.12 specifier: ^18.3.12
version: 18.3.28 version: 18.3.28
@@ -1853,6 +1856,10 @@ packages:
'@types/json5@0.0.29': '@types/json5@0.0.29':
resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==}
'@types/libsodium-wrappers-sumo@0.8.2':
resolution: {integrity: sha512-uFOBpg/r21hExVlh2ty8YpDfSR+Yy3Jn8XS4+SSjitbhTxdYq+pBz/49XRxyUFe8SzqujHf/Wu0/O4d+FUtNfQ==}
deprecated: This is a stub types definition. libsodium-wrappers-sumo provides its own type definitions, so you do not need this installed.
'@types/libsodium-wrappers@0.7.14': '@types/libsodium-wrappers@0.7.14':
resolution: {integrity: sha512-5Kv68fXuXK0iDuUir1WPGw2R9fOZUlYlSAa0ztMcL0s0BfIDTqg9GXz8K30VJpPP3sxWhbolnQma2x+/TfkzDQ==} resolution: {integrity: sha512-5Kv68fXuXK0iDuUir1WPGw2R9fOZUlYlSAa0ztMcL0s0BfIDTqg9GXz8K30VJpPP3sxWhbolnQma2x+/TfkzDQ==}
@@ -3642,9 +3649,15 @@ packages:
resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==}
engines: {node: '>= 0.8.0'} engines: {node: '>= 0.8.0'}
libsodium-sumo@0.7.16:
resolution: {integrity: sha512-x6atrz2AdXCJg6G709x9W9TTJRI6/0NcL5dD0l5GGVqNE48UJmDsjO4RUWYTeyXXUpg+NXZ2SHECaZnFRYzwGA==}
libsodium-sumo@0.8.3: libsodium-sumo@0.8.3:
resolution: {integrity: sha512-z5CLkGJqilCXpfYxrXWh8fHVv2C8lpnIVxsZAHkxbEFyS+zZtL8VyM8FjtAmuDYP/rHgw8ftdwxSV8Efhzb8GQ==} resolution: {integrity: sha512-z5CLkGJqilCXpfYxrXWh8fHVv2C8lpnIVxsZAHkxbEFyS+zZtL8VyM8FjtAmuDYP/rHgw8ftdwxSV8Efhzb8GQ==}
libsodium-wrappers-sumo@0.7.15:
resolution: {integrity: sha512-aSWY8wKDZh5TC7rMvEdTHoyppVq/1dTSAeAR7H6pzd6QRT3vQWcT5pGwCotLcpPEOLXX6VvqihSPkpEhYAjANA==}
libsodium-wrappers-sumo@0.8.3: libsodium-wrappers-sumo@0.8.3:
resolution: {integrity: sha512-EfLSlxKJ7RUGVospOlvbvse0suAAVPR+CkZfFcFjPzPtTEgVfvIaZUPsWndVjxYp/om2HDc0iLeR5wLF8YbHZg==} resolution: {integrity: sha512-EfLSlxKJ7RUGVospOlvbvse0suAAVPR+CkZfFcFjPzPtTEgVfvIaZUPsWndVjxYp/om2HDc0iLeR5wLF8YbHZg==}
@@ -7492,6 +7505,10 @@ snapshots:
'@types/json5@0.0.29': {} '@types/json5@0.0.29': {}
'@types/libsodium-wrappers-sumo@0.8.2':
dependencies:
libsodium-wrappers-sumo: 0.7.15
'@types/libsodium-wrappers@0.7.14': {} '@types/libsodium-wrappers@0.7.14': {}
'@types/node-forge@1.3.14': '@types/node-forge@1.3.14':
@@ -9591,8 +9608,14 @@ snapshots:
prelude-ls: 1.2.1 prelude-ls: 1.2.1
type-check: 0.4.0 type-check: 0.4.0
libsodium-sumo@0.7.16: {}
libsodium-sumo@0.8.3: {} libsodium-sumo@0.8.3: {}
libsodium-wrappers-sumo@0.7.15:
dependencies:
libsodium-sumo: 0.7.16
libsodium-wrappers-sumo@0.8.3: libsodium-wrappers-sumo@0.8.3:
dependencies: dependencies:
libsodium-sumo: 0.8.3 libsodium-sumo: 0.8.3
@@ -0,0 +1,109 @@
-- 1) Test-Daten-Wipe: alle conversation/message Daten weg, User+Devices+
-- Friendships+Invites bleiben erhalten so dass bestehende Logins weiter
-- funktionieren. Cascade räumt mitlaufende rows (envelopes, attachments,
-- reactions, reads, conversation_keys, conversation_members).
truncate
public.message_reactions,
public.message_reads,
public.message_attachments,
public.messages,
public.conversation_keys,
public.conversation_members,
public.conversations
restart identity cascade;
-- 2) RPC: share conv-key bundles to multiple recipients atomically.
-- Runs as SECURITY DEFINER so RLS doesn't reject individual rows. The
-- function itself enforces the same invariants as the policy. This avoids
-- the per-row 403 console spam we got with direct inserts.
create or replace function public.share_conv_keys(
p_conv_id uuid,
p_sender_device_id uuid,
p_key_version int,
p_bundles jsonb
) returns int
language plpgsql
security definer
set search_path = public
as $$
declare
caller uuid := auth.uid();
bundle jsonb;
recipient_user_id uuid;
inserted int := 0;
recipient_did uuid;
enc_key_hex text;
nonce_hex text;
begin
if caller is null then
raise exception 'not authenticated';
end if;
-- Caller must be an accepted member of the conversation.
if not exists (
select 1
from public.conversation_members
where conversation_id = p_conv_id
and user_id = caller
and accepted = true
) then
raise exception 'caller is not an accepted member of %', p_conv_id;
end if;
-- Sender device must belong to the caller.
if not exists (
select 1
from public.devices
where id = p_sender_device_id
and user_id = caller
) then
raise exception 'sender_device % not owned by caller', p_sender_device_id;
end if;
-- Iterate bundles and only insert ones whose recipient is a current
-- accepted member. Silently skip otherwise (no error → no 403 noise).
for bundle in
select * from jsonb_array_elements(p_bundles)
loop
recipient_did := (bundle->>'recipient_device_id')::uuid;
enc_key_hex := bundle->>'encrypted_key';
nonce_hex := bundle->>'nonce';
select user_id
into recipient_user_id
from public.devices
where id = recipient_did;
if recipient_user_id is null then continue; end if;
if not exists (
select 1
from public.conversation_members
where conversation_id = p_conv_id
and user_id = recipient_user_id
and accepted = true
) then continue; end if;
insert into public.conversation_keys
(conversation_id, recipient_device_id, key_version,
sender_device_id, encrypted_key, nonce)
values
(p_conv_id, recipient_did, p_key_version,
p_sender_device_id,
decode(enc_key_hex, 'hex'),
decode(nonce_hex, 'hex'))
on conflict (conversation_id, recipient_device_id, key_version)
do nothing;
if found then
inserted := inserted + 1;
end if;
end loop;
return inserted;
end;
$$;
revoke execute on function public.share_conv_keys(uuid, uuid, int, jsonb) from public, anon;
grant execute on function public.share_conv_keys(uuid, uuid, int, jsonb) to authenticated;
@@ -0,0 +1,54 @@
-- Profile-Avatar storage bucket.
--
-- Layout: <user_id>/<filename>.webp
-- Public read so peers can see each other's avatar without auth roundtrip
-- (avatars are non-sensitive). Write/update/delete restricted to the owning
-- user via path prefix matching their auth.uid().
insert into storage.buckets (id, name, public)
values ('profile-avatars', 'profile-avatars', true)
on conflict (id) do nothing;
-- Read: anyone authenticated can view any avatar (public bucket also lets
-- unauth fetch by URL but our RLS keeps the table-level policy explicit).
drop policy if exists profile_avatars_select on storage.objects;
create policy profile_avatars_select
on storage.objects
for select
to authenticated, anon
using (bucket_id = 'profile-avatars');
-- Write only into your own folder (first path segment must equal auth.uid()).
drop policy if exists profile_avatars_insert_own on storage.objects;
create policy profile_avatars_insert_own
on storage.objects
for insert
to authenticated
with check (
bucket_id = 'profile-avatars'
and (storage.foldername(name))[1] = auth.uid()::text
);
drop policy if exists profile_avatars_update_own on storage.objects;
create policy profile_avatars_update_own
on storage.objects
for update
to authenticated
using (
bucket_id = 'profile-avatars'
and (storage.foldername(name))[1] = auth.uid()::text
)
with check (
bucket_id = 'profile-avatars'
and (storage.foldername(name))[1] = auth.uid()::text
);
drop policy if exists profile_avatars_delete_own on storage.objects;
create policy profile_avatars_delete_own
on storage.objects
for delete
to authenticated
using (
bucket_id = 'profile-avatars'
and (storage.foldername(name))[1] = auth.uid()::text
);
@@ -0,0 +1,16 @@
-- Per-member conversation preferences: archive + mute.
--
-- Both live on `conversation_members` because they are per-user state, not
-- shared across the conversation. Archive hides the conversation from the
-- main list until explicitly unarchived. Mute silences notifications until
-- `muted_until` (null = not muted, a far-future timestamp = muted forever).
alter table public.conversation_members
add column if not exists archived boolean not null default false,
add column if not exists muted_until timestamptz null;
-- Update policy on conversation_members already allows self-updates via
-- `members_update_self_or_admin`. No additional policy needed — users can
-- toggle their own archive / mute flags.
-- Realtime publication already includes `conversation_members`.
@@ -0,0 +1,71 @@
-- Keep raw casing on usernames at signup.
--
-- `profiles.username` is already `citext` so unique + lookup checks are
-- case-insensitive regardless of stored casing. Previously the signup
-- trigger force-lowercased via `lower(trim(...))`, losing the user's
-- preferred display case. Drop the lower(), widen the validation regex to
-- accept A-Z, keep trim() + uniqueness semantics.
create or replace function public.handle_new_user()
returns trigger language plpgsql security definer set search_path = public as $$
declare
v_invite_code text;
v_username text;
v_display_name text;
v_locale text;
v_invite public.invites%rowtype;
begin
v_invite_code := new.raw_user_meta_data->>'invite_code';
v_username := trim(new.raw_user_meta_data->>'username');
v_display_name := nullif(trim(new.raw_user_meta_data->>'display_name'), '');
v_locale := lower(trim(new.raw_user_meta_data->>'locale'));
if v_display_name is null then
v_display_name := v_username;
end if;
if v_locale is null or v_locale not in ('en', 'de') then
v_locale := 'en';
end if;
if v_invite_code is null or length(v_invite_code) = 0 then
raise exception 'ERR_INVITE_CODE_REQUIRED';
end if;
if v_username is null or v_username !~ '^[A-Za-z0-9_]{3,32}$' then
raise exception 'ERR_USERNAME_INVALID';
end if;
if not coalesce((select (value)::boolean from public.admin_settings where key = 'invites_enabled'), true) then
raise exception 'ERR_INVITES_DISABLED';
end if;
select * into v_invite from public.invites
where code = v_invite_code
for update;
if not found then
raise exception 'ERR_INVITE_NOT_FOUND';
end if;
if v_invite.disabled then
raise exception 'ERR_INVITE_DISABLED';
end if;
if v_invite.expires_at is not null and v_invite.expires_at < now() then
raise exception 'ERR_INVITE_EXPIRED';
end if;
if v_invite.uses_limit is not null and v_invite.uses_count >= v_invite.uses_limit then
raise exception 'ERR_INVITE_EXHAUSTED';
end if;
update public.invites
set uses_count = uses_count + 1
where code = v_invite.code;
insert into public.profiles (user_id, username, display_name, locale)
values (new.id, v_username, v_display_name, v_locale);
return new;
end;
$$;