/** * ChannelWelcomeSection — the "start of channel" header rendered above * the first message in any channel view. Two variants: * * - DM (1:1) → centred avatar + display name + "@username" handle + * "This is the beginning of your direct message history with Name." * - Text channel → "Welcome to #channel-name!" with the Hash icon * and a short description. * * Voice channels never reach the message list so they never need this. */ import { useMemo } from 'react'; import { useQuery } from 'convex/react'; import { Hash } from '@phosphor-icons/react'; import { Avatar } from '@discord-clone/ui'; import { api } from '../../../../../convex/_generated/api'; import { useOnlineUsers } from '../../contexts/PresenceContext'; import styles from './ChannelWelcomeSection.module.css'; interface ChannelWelcomeSectionProps { channelId: string; channelName?: string; channelType?: string; } function mapPresence( status: string | undefined, ): 'online' | 'idle' | 'dnd' | 'offline' { switch (status) { case 'online': return 'online'; case 'idle': return 'idle'; case 'dnd': return 'dnd'; default: return 'offline'; } } export function ChannelWelcomeSection({ channelId, channelName, channelType, }: ChannelWelcomeSectionProps) { if (channelType === 'dm') { return ; } const name = channelName || 'channel'; return (

Welcome to #{name}!

This is the start of the #{name} channel. All messages are end-to-end encrypted.

); } interface DmWelcomeProps { channelId: string; channelName?: string; } function DmWelcome({ channelId, channelName }: DmWelcomeProps) { const { resolveStatus } = useOnlineUsers(); const myUserId = typeof localStorage !== 'undefined' ? localStorage.getItem('userId') : null; const dmRows = useQuery( api.dms.listDMs, myUserId ? { userId: myUserId as any } : 'skip', ); const allUsers = useQuery(api.auth.getPublicKeys) ?? []; const other = useMemo(() => { if (!dmRows) return null; const row = (dmRows as any[]).find((r) => r.channel_id === channelId); if (!row) return null; const profile = allUsers.find((u) => u.id === row.other_user_id); const username = profile?.username || row.other_username || ''; return { userId: row.other_user_id as string, displayName: username || channelName || 'this user', username, avatarUrl: profile?.avatarUrl ?? row.other_user_avatar_url ?? null, status: (profile?.status as string | undefined) || (row.other_user_status as string | undefined) || 'offline', }; }, [dmRows, allUsers, channelId, channelName]); const presence = mapPresence( other ? resolveStatus(other.status, other.userId) : 'offline', ); const displayName = other?.displayName ?? channelName ?? 'this user'; return (

{displayName}

This is the beginning of your direct message history with{' '} {displayName}.

); }