import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import dmService from '@/services/dm.service' import { TDirectMessage } from '@/types' import { Loader2, RefreshCw, Server } from 'lucide-react' import { useState } from 'react' import { useTranslation } from 'react-i18next' interface MessageInfoModalProps { message: TDirectMessage | null open: boolean onOpenChange: (open: boolean) => void onRelaysUpdated?: (relays: string[]) => void } export default function MessageInfoModal({ message, open, onOpenChange, onRelaysUpdated }: MessageInfoModalProps) { const { t } = useTranslation() const [isChecking, setIsChecking] = useState(false) const [additionalRelays, setAdditionalRelays] = useState([]) if (!message) return null const allRelays = [...(message.seenOnRelays || []), ...additionalRelays] const uniqueRelays = [...new Set(allRelays)] const handleCheckOtherRelays = async () => { setIsChecking(true) try { const foundRelays = await dmService.checkOtherRelaysForEvent( message.id, uniqueRelays ) if (foundRelays.length > 0) { const newRelays = [...additionalRelays, ...foundRelays] setAdditionalRelays(newRelays) onRelaysUpdated?.([...(message.seenOnRelays || []), ...newRelays]) } } catch (error) { console.error('Failed to check other relays:', error) } finally { setIsChecking(false) } } const formatRelayUrl = (url: string) => { try { const parsed = new URL(url) return parsed.hostname + (parsed.pathname !== '/' ? parsed.pathname : '') } catch { return url } } return ( {t('Message Info')}
{/* Protocol */}
{t('Encryption')}

{message.encryptionType === 'nip17' ? 'NIP-44 (Gift Wrap)' : 'NIP-04 (Legacy)'}

{/* Relays */}
{t('Seen on relays')} {uniqueRelays.length > 0 ? (
    {uniqueRelays.map((relay) => (
  • {formatRelayUrl(relay)}
  • ))}
) : (

{t('No relay information available')}

)}
{/* Check other relays button */}
) }