ConversationOptions.svelte (3898B)
1 <script lang="ts"> 2 import { onMount, untrack } from 'svelte'; 3 import { 4 subscribeInboxView, 5 blockInboxConversation, 6 type InboxView 7 } from '../messaging/inbox-view.ts'; 8 import { 9 conversationOptionsSnapshot, 10 requestConversationOption 11 } from '../messaging/cited-product.ts'; 12 import ReportPreview from './ReportPreview.svelte'; 13 import { 14 createConversationReport, 15 closeReportContext, 16 type ReportContext 17 } from '../support/report.ts'; 18 let { 19 controller, 20 conversationId, 21 onblock, 22 onreport 23 }: { 24 controller: InboxView; 25 conversationId: string; 26 onblock?: (peer: string) => void; 27 onreport?: (peer: string) => void; 28 } = $props(); 29 let revision = $state(0); 30 let report = $state.raw<ReportContext | undefined>(); 31 let reportOwner = $state.raw<{ view: InboxView; id: string } | undefined>(); 32 $effect(() => { 33 const view = controller, 34 id = conversationId; 35 untrack(() => { 36 if (reportOwner && (reportOwner.view !== view || reportOwner.id !== id)) { 37 if (report) closeReportContext(report); 38 report = undefined; 39 reportOwner = undefined; 40 } 41 }); 42 }); 43 let reviewing = $state(false), 44 busy = $state(false), 45 notice = $state<string | undefined>(); 46 async function confirmBlock() { 47 if (!reviewing || busy) return; 48 busy = true; 49 const result = await blockInboxConversation( 50 controller, 51 conversationId, 52 'reviewed_local_private_block' 53 ); 54 busy = false; 55 reviewing = false; 56 notice = 57 result.status === 'saved' || result.status === 'existing' 58 ? 'Person blocked in this browser.' 59 : 'Block was not confirmed. Existing local data has not been reset.'; 60 } 61 const actual = $derived.by(() => { 62 void revision; 63 return conversationOptionsSnapshot(controller, conversationId); 64 }); 65 onMount(() => { 66 const off = subscribeInboxView(controller, () => { 67 revision++; 68 }); 69 return () => { 70 off(); 71 if (report) closeReportContext(report); 72 }; 73 }); 74 </script> 75 76 {#if actual} 77 <details> 78 <summary>Identity and conversation options</summary> 79 <p>Authenticated conversation peer: {actual.peer}</p> 80 <button 81 type="button" 82 onclick={() => { 83 if (onblock) 84 requestConversationOption( 85 controller, 86 conversationId, 87 'block', 88 onblock, 89 'reviewed_conversation_option' 90 ); 91 else reviewing = true; 92 }}>Block person</button 93 > 94 {#if reviewing} 95 <p> 96 Blocking hides messages and previews for this account in this browser 97 and may discard unsaved private text. Encrypted evidence, delivery 98 receipts and remote copies remain. It sends no report or sender 99 notification and does not accept or reject an order. Undo is available 100 in Privacy. 101 </p> 102 <button type="button" disabled={busy} onclick={() => void confirmBlock()} 103 >Confirm local block</button 104 > 105 <button 106 type="button" 107 disabled={busy} 108 onclick={() => { 109 reviewing = false; 110 }}>Cancel</button 111 > 112 {/if} 113 {#if notice}<p role="status">{notice}</p>{/if} 114 <button 115 type="button" 116 onclick={() => { 117 if (onreport) 118 requestConversationOption( 119 controller, 120 conversationId, 121 'report', 122 onreport, 123 'reviewed_conversation_option' 124 ); 125 else { 126 if (report) closeReportContext(report); 127 report = createConversationReport(controller, conversationId); 128 reportOwner = report 129 ? { view: controller, id: conversationId } 130 : undefined; 131 } 132 }}>Report conversation</button 133 > 134 {#if report}{#key report}<ReportPreview context={report} />{/key}{/if} 135 </details> 136 {/if}