import { useEffect } from 'react'; import { notify } from './osNotify'; import { supabase } from './supabase'; interface MentionRow { message_id: string; mentioned_user_id: string; conversation_id: string; } // Subscribes to my own message_mentions inserts and fires an OS notification // for each one. Bypasses per-conv mute (mentions override mute by design). // // We don't decrypt the body here — the notification just says "Du wurdest // erwähnt". The conv list highlight + the in-app navigation reveal context. export function useMentionNotifications(userId: string | undefined): void { useEffect(() => { if (!userId) return; const channel = supabase .channel('mentions:' + userId) .on( 'postgres_changes', { event: 'INSERT', schema: 'public', table: 'message_mentions', filter: 'mentioned_user_id=eq.' + userId, }, (payload) => { const row = payload.new as MentionRow | null; if (!row) return; void notify({ title: 'Du wurdest erwähnt', body: 'Tippe um die Nachricht zu lesen.', force: true, }); }, ) .subscribe(); return () => { void supabase.removeChannel(channel); }; }, [userId]); }