feat: file variety, user status, DND gate, drag-drop, mentions, link preview, emoji picker, soundboard, ringtone
Attachments
- Video: native <video controls>, decrypted blob, metadata preload
- PDF: collapsible <object> viewer with download + preview toggle
- Generic: file card with lazy decrypt, mime-to-extension map
- MessageBubble dispatch: audio/image/video/pdf/generic by mime
- Composer accept widened from image/* to any; AttachmentPreview renders
non-images as file cards
User status
- usePeerPresence returns { state, statusMessage } and tracks both fields
via realtime updates
- ConversationHeader subtitle shows custom status_message when peer is
online/idle/dnd (with message set); falls back to localized presence
label; always "Offline" when state === 'offline'
- UserBar: status_message input in dropdown (max 128 chars, save on
blur/Enter), subtitle uses same precedence as peer view
- AuthContext: auto-flip offline → online on session mount; best-effort
offline on beforeunload/pagehide; respects explicit idle/dnd/invisible
- i18n: presence.status_placeholder (DE + EN)
DND
- CallUI: incoming ring suppressed when own presence === 'dnd' (outgoing
rings stay audible — user-initiated)
- CallContext: presenceRef mirrors profile.presenceState, incoming-call
and missed-call OS notifications skipped under DND
- ConversationsContext already gated message tone + notify
Drag/drop + paste
- Page-root drag handlers feed ingestFiles; overlay shown while dragging
- Textarea onPaste extracts clipboard image items
@mentions in groups
- MentionAutocomplete: keyboard-driven dropdown, arrow/enter/tab/esc
- Composer onChange parses trailing @token, auto-open
- renderBodyWithMentions highlights @username tokens in bubbles
Link previews
- Migration 20260421000003_link_previews.sql (cache table, auth read,
service-role write via edge function)
- Edge function og-preview: POST {url}, fetches HTML (6s timeout, 1MB
cap), regex-parses OG/twitter/description, upserts cache
- useLinkPreview hook with in-memory cache + inflight dedup
- LinkPreviewCard rendered from first URL in message body
Emoji picker
- Built-in curated set (~250 emojis) across five categories
- Search by keyword/emoji char/category, recent list persisted in
localStorage
- Trigger button next to + and voice buttons in composer
Soundboard + ringtone + mic pipeline
- Pulled in (user-authored) SoundboardManagerDialog/Panel/Settings,
RingtoneSettings, mic pipeline + hotkeys + storage modules
- AuthContext imports updateOwnProfile for presence auto-flip
Fixes
- AttachmentAudio min-width so bubbles don't collapse to 0px on peer
side
- Focus flicker: visibility/online wake refresh throttled to 30s,
focus listener dropped, loading flag only on first fetch
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
// Looping WebAudio ringtones. Two patterns:
|
||||
// - outgoing: long calling tone, 3s cycle
|
||||
// - incoming: classic "ring ring" double beep, 2s cycle
|
||||
// Looping ringtones. Two patterns:
|
||||
// - outgoing: long calling tone, 3s cycle (oscillator only)
|
||||
// - incoming: classic "ring ring" double beep (oscillator), optionally
|
||||
// upgraded to a user-supplied audio file stored in ringtoneStorage
|
||||
//
|
||||
// The custom file plays immediately if we can load it; otherwise we fall
|
||||
// back to the generated oscillator pattern so ringing never misses an
|
||||
// incoming call due to an IO failure.
|
||||
|
||||
import { getIncomingRingtone } from './ringtoneStorage';
|
||||
|
||||
type Pattern = 'outgoing' | 'incoming';
|
||||
|
||||
@@ -9,15 +16,90 @@ class Ringtone {
|
||||
private interval: number | null = null;
|
||||
private pattern: Pattern | null = null;
|
||||
|
||||
// Custom-file playback path (incoming only).
|
||||
private audioEl: HTMLAudioElement | null = null;
|
||||
private customUrl: string | null = null;
|
||||
// Sequence token to ignore slow IO completing after user changed state.
|
||||
private startSeq = 0;
|
||||
|
||||
start(pattern: Pattern): void {
|
||||
if (this.pattern === pattern) return; // already playing this pattern
|
||||
this.stop();
|
||||
this.pattern = pattern;
|
||||
const seq = ++this.startSeq;
|
||||
|
||||
if (pattern === 'incoming') {
|
||||
// Kick off oscillator immediately so we never miss ringing feedback
|
||||
// while the custom file (if any) loads asynchronously. Once the blob
|
||||
// is ready we hand playback over to the <audio> element.
|
||||
this.startOscillator(pattern);
|
||||
void this.tryUpgradeToCustom(seq);
|
||||
} else {
|
||||
this.startOscillator(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
this.startSeq++;
|
||||
this.stopOscillator();
|
||||
this.stopCustom();
|
||||
this.pattern = null;
|
||||
}
|
||||
|
||||
// --- Custom file path (incoming only) ----------------------------------
|
||||
|
||||
private async tryUpgradeToCustom(seq: number): Promise<void> {
|
||||
let stored;
|
||||
try {
|
||||
stored = await getIncomingRingtone();
|
||||
} catch {
|
||||
return; // keep oscillator
|
||||
}
|
||||
// User stopped or switched patterns while we were loading.
|
||||
if (seq !== this.startSeq || this.pattern !== 'incoming' || !stored) return;
|
||||
|
||||
const url = URL.createObjectURL(stored.blob);
|
||||
const el = new Audio(url);
|
||||
el.loop = true;
|
||||
el.volume = 0.85;
|
||||
// Chrome/WKWebView autoplay policy: muted playback is always allowed,
|
||||
// but ringtones must be audible, so play() may reject the first time
|
||||
// before the user interacted. If it rejects, we keep the oscillator.
|
||||
el.play().catch(() => {
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
|
||||
this.audioEl = el;
|
||||
this.customUrl = url;
|
||||
// Only swap off the oscillator once the custom element is actually
|
||||
// wired — avoids a silent gap on transition.
|
||||
this.stopOscillator();
|
||||
}
|
||||
|
||||
private stopCustom(): void {
|
||||
if (this.audioEl) {
|
||||
try {
|
||||
this.audioEl.pause();
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
this.audioEl.src = '';
|
||||
this.audioEl = null;
|
||||
}
|
||||
if (this.customUrl) {
|
||||
URL.revokeObjectURL(this.customUrl);
|
||||
this.customUrl = null;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Oscillator fallback ----------------------------------------------
|
||||
|
||||
private startOscillator(pattern: Pattern): void {
|
||||
const AudioCtx =
|
||||
window.AudioContext ??
|
||||
(window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;
|
||||
if (!AudioCtx) return;
|
||||
this.ctx = new AudioCtx();
|
||||
this.pattern = pattern;
|
||||
|
||||
const play = pattern === 'outgoing' ? this.playOutgoing : this.playIncoming;
|
||||
play.call(this);
|
||||
@@ -27,7 +109,7 @@ class Ringtone {
|
||||
);
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
private stopOscillator(): void {
|
||||
if (this.interval !== null) {
|
||||
window.clearInterval(this.interval);
|
||||
this.interval = null;
|
||||
@@ -38,7 +120,6 @@ class Ringtone {
|
||||
});
|
||||
this.ctx = null;
|
||||
}
|
||||
this.pattern = null;
|
||||
}
|
||||
|
||||
private beep(freq: number, durationSec: number, delaySec: number, gain = 0.18): void {
|
||||
|
||||
Reference in New Issue
Block a user