ConversationRow.svelte (1632B)
1 <script lang="ts"> 2 import Button from './primitives/Button.svelte'; 3 import { 4 inboxConversationRow, 5 type InboxView 6 } from '../messaging/inbox-view.ts'; 7 import type { InboxListRow } from '../messaging/inbox-list.ts'; 8 let { 9 controller, 10 row, 11 onopen 12 }: { 13 controller: InboxView; 14 row: InboxListRow; 15 onopen?: (peer: string) => void; 16 } = $props(); 17 // A detached row is only an invalidation/peer selection hint. Its body, unread 18 // and role are never rendered without the same current genuine controller. 19 const current = $derived( 20 row ? inboxConversationRow(controller, row.peer) : undefined 21 ); 22 const preview = $derived( 23 current 24 ? Array.from(current.latest.content).slice(0, 160).join('') + 25 (Array.from(current.latest.content).length > 160 ? '…' : '') 26 : '' 27 ); 28 const time = $derived( 29 current ? new Date(current.latest.createdAt * 1000) : undefined 30 ); 31 </script> 32 33 {#if current} 34 <article class="stack" aria-label="Local conversation"> 35 <div class="cluster"> 36 <span class="key" 37 >Peer {current.peer.slice(0, 8)}…{current.peer.slice(-8)}</span 38 >{#if current.unread > 0}<span>New</span>{/if}<span class="text-small" 39 >{time && !Number.isNaN(time.getTime()) 40 ? time.toLocaleString() 41 : 'Time unavailable'}</span 42 > 43 </div> 44 <p>{current.latest.role === 'self_archive' ? 'You: ' : ''}{preview}</p> 45 <Button 46 label={'Open conversation with ' + current.peer} 47 disabled={!onopen} 48 onclick={() => { 49 if (current) onopen?.(current.peer); 50 }} 51 /> 52 </article> 53 {/if}