23 changed files with 249 additions and 1745 deletions
@ -1,194 +0,0 @@ |
|||||||
<script lang="ts"> |
|
||||||
interface Props { |
|
||||||
open: boolean; |
|
||||||
onClose: () => void; |
|
||||||
} |
|
||||||
|
|
||||||
let { open, onClose }: Props = $props(); |
|
||||||
|
|
||||||
const shortcuts = [ |
|
||||||
{ key: '/', description: 'Open search' }, |
|
||||||
{ key: '?', description: 'Show keyboard shortcuts' }, |
|
||||||
{ key: 'j', description: 'Next post/thread' }, |
|
||||||
{ key: 'k', description: 'Previous post/thread' }, |
|
||||||
{ key: 'r', description: 'Reply to selected post' }, |
|
||||||
{ key: 'z', description: 'Zap selected post' }, |
|
||||||
{ key: 'Esc', description: 'Close modal' } |
|
||||||
]; |
|
||||||
</script> |
|
||||||
|
|
||||||
{#if open} |
|
||||||
<div |
|
||||||
class="modal-overlay" |
|
||||||
onclick={(e) => { |
|
||||||
if (e.target === e.currentTarget) onClose(); |
|
||||||
}} |
|
||||||
onkeydown={(e) => { |
|
||||||
if (e.key === 'Escape') { |
|
||||||
e.preventDefault(); |
|
||||||
onClose(); |
|
||||||
} |
|
||||||
}} |
|
||||||
role="dialog" |
|
||||||
aria-modal="true" |
|
||||||
aria-labelledby="shortcuts-title" |
|
||||||
tabindex="-1" |
|
||||||
> |
|
||||||
<div class="modal"> |
|
||||||
<div class="modal-header"> |
|
||||||
<h2 id="shortcuts-title" class="text-xl font-bold">Keyboard Shortcuts</h2> |
|
||||||
<button |
|
||||||
onclick={onClose} |
|
||||||
class="close-button" |
|
||||||
aria-label="Close" |
|
||||||
> |
|
||||||
× |
|
||||||
</button> |
|
||||||
</div> |
|
||||||
|
|
||||||
<div class="shortcuts-list"> |
|
||||||
{#each shortcuts as shortcut} |
|
||||||
<div class="shortcut-item"> |
|
||||||
<kbd class="shortcut-key">{shortcut.key}</kbd> |
|
||||||
<span class="shortcut-description">{shortcut.description}</span> |
|
||||||
</div> |
|
||||||
{/each} |
|
||||||
</div> |
|
||||||
|
|
||||||
<div class="modal-footer"> |
|
||||||
<button |
|
||||||
onclick={onClose} |
|
||||||
class="close-footer-button" |
|
||||||
> |
|
||||||
Close |
|
||||||
</button> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
{/if} |
|
||||||
|
|
||||||
<style> |
|
||||||
.modal-overlay { |
|
||||||
position: fixed; |
|
||||||
top: 0; |
|
||||||
left: 0; |
|
||||||
right: 0; |
|
||||||
bottom: 0; |
|
||||||
background: rgba(0, 0, 0, 0.5); |
|
||||||
display: flex; |
|
||||||
align-items: center; |
|
||||||
justify-content: center; |
|
||||||
z-index: 1000; |
|
||||||
padding: 2rem; |
|
||||||
} |
|
||||||
|
|
||||||
.modal { |
|
||||||
background: var(--fog-post, #ffffff); |
|
||||||
border-radius: 0.5rem; |
|
||||||
padding: 1.5rem; |
|
||||||
width: 100%; |
|
||||||
max-width: 500px; |
|
||||||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .modal { |
|
||||||
background: var(--fog-dark-post, #1f2937); |
|
||||||
} |
|
||||||
|
|
||||||
.modal-header { |
|
||||||
display: flex; |
|
||||||
justify-content: space-between; |
|
||||||
align-items: center; |
|
||||||
margin-bottom: 1.5rem; |
|
||||||
} |
|
||||||
|
|
||||||
.close-button { |
|
||||||
background: none; |
|
||||||
border: none; |
|
||||||
font-size: 2rem; |
|
||||||
line-height: 1; |
|
||||||
cursor: pointer; |
|
||||||
color: var(--fog-text, #1f2937); |
|
||||||
padding: 0; |
|
||||||
width: 2rem; |
|
||||||
height: 2rem; |
|
||||||
display: flex; |
|
||||||
align-items: center; |
|
||||||
justify-content: center; |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .close-button { |
|
||||||
color: var(--fog-dark-text, #f9fafb); |
|
||||||
} |
|
||||||
|
|
||||||
.close-button:hover { |
|
||||||
opacity: 0.7; |
|
||||||
} |
|
||||||
|
|
||||||
.shortcuts-list { |
|
||||||
display: flex; |
|
||||||
flex-direction: column; |
|
||||||
gap: 1rem; |
|
||||||
margin-bottom: 1.5rem; |
|
||||||
} |
|
||||||
|
|
||||||
.shortcut-item { |
|
||||||
display: flex; |
|
||||||
justify-content: space-between; |
|
||||||
align-items: center; |
|
||||||
padding: 0.75rem; |
|
||||||
border: 1px solid var(--fog-border, #e5e7eb); |
|
||||||
border-radius: 0.25rem; |
|
||||||
background: var(--fog-post, #ffffff); |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .shortcut-item { |
|
||||||
background: var(--fog-dark-post, #1f2937); |
|
||||||
border-color: var(--fog-dark-border, #374151); |
|
||||||
} |
|
||||||
|
|
||||||
.shortcut-key { |
|
||||||
padding: 0.25rem 0.5rem; |
|
||||||
background: var(--fog-highlight, #f3f4f6); |
|
||||||
border: 1px solid var(--fog-border, #e5e7eb); |
|
||||||
border-radius: 0.25rem; |
|
||||||
font-family: monospace; |
|
||||||
font-size: 0.875rem; |
|
||||||
font-weight: 600; |
|
||||||
color: var(--fog-text, #1f2937); |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .shortcut-key { |
|
||||||
background: var(--fog-dark-highlight, #374151); |
|
||||||
border-color: var(--fog-dark-border, #374151); |
|
||||||
color: var(--fog-dark-text, #f9fafb); |
|
||||||
} |
|
||||||
|
|
||||||
.shortcut-description { |
|
||||||
color: var(--fog-text, #1f2937); |
|
||||||
font-size: 0.875rem; |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .shortcut-description { |
|
||||||
color: var(--fog-dark-text, #f9fafb); |
|
||||||
} |
|
||||||
|
|
||||||
.modal-footer { |
|
||||||
display: flex; |
|
||||||
justify-content: flex-end; |
|
||||||
} |
|
||||||
|
|
||||||
.close-footer-button { |
|
||||||
padding: 0.5rem 1rem; |
|
||||||
background: var(--fog-accent, #64748b); |
|
||||||
color: white; |
|
||||||
border: none; |
|
||||||
border-radius: 0.25rem; |
|
||||||
cursor: pointer; |
|
||||||
font-size: 0.875rem; |
|
||||||
} |
|
||||||
|
|
||||||
.close-footer-button:hover { |
|
||||||
opacity: 0.9; |
|
||||||
} |
|
||||||
</style> |
|
||||||
@ -1,370 +0,0 @@ |
|||||||
<script lang="ts"> |
|
||||||
import { searchEvents } from '../../services/cache/search-index.js'; |
|
||||||
import { getEvent } from '../../services/cache/event-cache.js'; |
|
||||||
import { nostrClient } from '../../services/nostr/nostr-client.js'; |
|
||||||
import { relayManager } from '../../services/nostr/relay-manager.js'; |
|
||||||
import { goto } from '$app/navigation'; |
|
||||||
import type { NostrEvent } from '../../types/nostr.js'; |
|
||||||
|
|
||||||
interface Props { |
|
||||||
open: boolean; |
|
||||||
onClose: () => void; |
|
||||||
} |
|
||||||
|
|
||||||
let { open, onClose }: Props = $props(); |
|
||||||
|
|
||||||
let query = $state(''); |
|
||||||
let results = $state<NostrEvent[]>([]); |
|
||||||
let loading = $state(false); |
|
||||||
let searchInput: HTMLInputElement | null = $state(null); |
|
||||||
|
|
||||||
$effect(() => { |
|
||||||
if (open && searchInput) { |
|
||||||
// Focus input when modal opens |
|
||||||
setTimeout(() => searchInput?.focus(), 100); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
async function handleSearch() { |
|
||||||
if (!query.trim()) { |
|
||||||
results = []; |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
loading = true; |
|
||||||
try { |
|
||||||
// Search in index |
|
||||||
const eventIds = await searchEvents(query.trim(), 20); |
|
||||||
|
|
||||||
// Fetch events |
|
||||||
const events: NostrEvent[] = []; |
|
||||||
for (const id of eventIds) { |
|
||||||
try { |
|
||||||
const cached = await getEvent(id); |
|
||||||
if (cached) { |
|
||||||
events.push(cached.event); |
|
||||||
} else { |
|
||||||
// Try to fetch from relays |
|
||||||
const relays = relayManager.getThreadReadRelays(); |
|
||||||
const event = await nostrClient.getEventById(id, relays); |
|
||||||
if (event) { |
|
||||||
events.push(event); |
|
||||||
} |
|
||||||
} |
|
||||||
} catch { |
|
||||||
// Skip if event not found |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
results = events.sort((a, b) => b.created_at - a.created_at); |
|
||||||
} catch (error) { |
|
||||||
console.error('Error searching:', error); |
|
||||||
results = []; |
|
||||||
} finally { |
|
||||||
loading = false; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
function handleKeydown(e: KeyboardEvent) { |
|
||||||
if (e.key === 'Enter') { |
|
||||||
e.preventDefault(); |
|
||||||
handleSearch(); |
|
||||||
} else if (e.key === 'Escape') { |
|
||||||
e.preventDefault(); |
|
||||||
onClose(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
function handleResultClick(event: NostrEvent) { |
|
||||||
// Navigate to thread if kind 11, or show event |
|
||||||
if (event.kind === 11) { |
|
||||||
goto(`/thread/${event.id}`); |
|
||||||
} else if (event.kind === 1) { |
|
||||||
// Could navigate to feed and highlight, or show in modal |
|
||||||
goto(`/feed`); |
|
||||||
} |
|
||||||
onClose(); |
|
||||||
} |
|
||||||
|
|
||||||
function getEventPreview(event: NostrEvent): string { |
|
||||||
const content = event.content || ''; |
|
||||||
const preview = content.slice(0, 150); |
|
||||||
return preview + (content.length > 150 ? '...' : ''); |
|
||||||
} |
|
||||||
|
|
||||||
function getEventType(event: NostrEvent): string { |
|
||||||
switch (event.kind) { |
|
||||||
case 1: |
|
||||||
return 'Post'; |
|
||||||
case 11: |
|
||||||
return 'Thread'; |
|
||||||
case 1111: |
|
||||||
return 'Comment'; |
|
||||||
default: |
|
||||||
return 'Event'; |
|
||||||
} |
|
||||||
} |
|
||||||
</script> |
|
||||||
|
|
||||||
{#if open} |
|
||||||
<div |
|
||||||
class="search-modal-overlay" |
|
||||||
onclick={(e) => { |
|
||||||
if (e.target === e.currentTarget) onClose(); |
|
||||||
}} |
|
||||||
onkeydown={(e) => { |
|
||||||
if (e.key === 'Escape') { |
|
||||||
e.preventDefault(); |
|
||||||
onClose(); |
|
||||||
} |
|
||||||
}} |
|
||||||
role="dialog" |
|
||||||
aria-modal="true" |
|
||||||
aria-labelledby="search-title" |
|
||||||
tabindex="-1" |
|
||||||
> |
|
||||||
<div class="search-modal"> |
|
||||||
<div class="search-header"> |
|
||||||
<h2 id="search-title" class="text-xl font-bold mb-4">Search</h2> |
|
||||||
<button |
|
||||||
onclick={onClose} |
|
||||||
class="close-button" |
|
||||||
aria-label="Close search" |
|
||||||
> |
|
||||||
× |
|
||||||
</button> |
|
||||||
</div> |
|
||||||
|
|
||||||
<div class="search-input-container"> |
|
||||||
<input |
|
||||||
bind:this={searchInput} |
|
||||||
type="text" |
|
||||||
bind:value={query} |
|
||||||
onkeydown={handleKeydown} |
|
||||||
placeholder="Search posts, threads, comments..." |
|
||||||
class="search-input" |
|
||||||
aria-label="Search query" |
|
||||||
/> |
|
||||||
<button |
|
||||||
onclick={handleSearch} |
|
||||||
class="search-button" |
|
||||||
disabled={loading || !query.trim()} |
|
||||||
> |
|
||||||
{loading ? 'Searching...' : 'Search'} |
|
||||||
</button> |
|
||||||
</div> |
|
||||||
|
|
||||||
{#if loading} |
|
||||||
<div class="search-results"> |
|
||||||
<p class="text-center text-fog-text-light dark:text-fog-dark-text-light py-4"> |
|
||||||
Searching... |
|
||||||
</p> |
|
||||||
</div> |
|
||||||
{:else if results.length > 0} |
|
||||||
<div class="search-results"> |
|
||||||
<p class="text-sm text-fog-text-light dark:text-fog-dark-text-light mb-2"> |
|
||||||
Found {results.length} {results.length === 1 ? 'result' : 'results'} |
|
||||||
</p> |
|
||||||
<div class="results-list"> |
|
||||||
{#each results as event (event.id)} |
|
||||||
<button |
|
||||||
onclick={() => handleResultClick(event)} |
|
||||||
class="result-item" |
|
||||||
> |
|
||||||
<div class="result-header"> |
|
||||||
<span class="result-type">{getEventType(event)}</span> |
|
||||||
<span class="result-time"> |
|
||||||
{new Date(event.created_at * 1000).toLocaleDateString()} |
|
||||||
</span> |
|
||||||
</div> |
|
||||||
<div class="result-content"> |
|
||||||
{getEventPreview(event)} |
|
||||||
</div> |
|
||||||
</button> |
|
||||||
{/each} |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
{:else if query.trim() && !loading} |
|
||||||
<div class="search-results"> |
|
||||||
<p class="text-center text-fog-text-light dark:text-fog-dark-text-light py-4"> |
|
||||||
No results found |
|
||||||
</p> |
|
||||||
</div> |
|
||||||
{/if} |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
{/if} |
|
||||||
|
|
||||||
<style> |
|
||||||
.search-modal-overlay { |
|
||||||
position: fixed; |
|
||||||
top: 0; |
|
||||||
left: 0; |
|
||||||
right: 0; |
|
||||||
bottom: 0; |
|
||||||
background: rgba(0, 0, 0, 0.5); |
|
||||||
display: flex; |
|
||||||
align-items: flex-start; |
|
||||||
justify-content: center; |
|
||||||
padding: 2rem; |
|
||||||
z-index: 1000; |
|
||||||
overflow-y: auto; |
|
||||||
} |
|
||||||
|
|
||||||
.search-modal { |
|
||||||
background: var(--fog-post, #ffffff); |
|
||||||
border-radius: 0.5rem; |
|
||||||
padding: 1.5rem; |
|
||||||
width: 100%; |
|
||||||
max-width: 600px; |
|
||||||
margin-top: 5vh; |
|
||||||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .search-modal { |
|
||||||
background: var(--fog-dark-post, #1f2937); |
|
||||||
} |
|
||||||
|
|
||||||
.search-header { |
|
||||||
display: flex; |
|
||||||
justify-content: space-between; |
|
||||||
align-items: center; |
|
||||||
margin-bottom: 1rem; |
|
||||||
} |
|
||||||
|
|
||||||
.close-button { |
|
||||||
background: none; |
|
||||||
border: none; |
|
||||||
font-size: 2rem; |
|
||||||
line-height: 1; |
|
||||||
cursor: pointer; |
|
||||||
color: var(--fog-text, #1f2937); |
|
||||||
padding: 0; |
|
||||||
width: 2rem; |
|
||||||
height: 2rem; |
|
||||||
display: flex; |
|
||||||
align-items: center; |
|
||||||
justify-content: center; |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .close-button { |
|
||||||
color: var(--fog-dark-text, #f9fafb); |
|
||||||
} |
|
||||||
|
|
||||||
.close-button:hover { |
|
||||||
opacity: 0.7; |
|
||||||
} |
|
||||||
|
|
||||||
.search-input-container { |
|
||||||
display: flex; |
|
||||||
gap: 0.5rem; |
|
||||||
margin-bottom: 1rem; |
|
||||||
} |
|
||||||
|
|
||||||
.search-input { |
|
||||||
flex: 1; |
|
||||||
padding: 0.75rem; |
|
||||||
border: 1px solid var(--fog-border, #e5e7eb); |
|
||||||
border-radius: 0.25rem; |
|
||||||
background: var(--fog-post, #ffffff); |
|
||||||
color: var(--fog-text, #1f2937); |
|
||||||
font-size: 1rem; |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .search-input { |
|
||||||
background: var(--fog-dark-post, #1f2937); |
|
||||||
border-color: var(--fog-dark-border, #374151); |
|
||||||
color: var(--fog-dark-text, #f9fafb); |
|
||||||
} |
|
||||||
|
|
||||||
.search-input:focus { |
|
||||||
outline: none; |
|
||||||
border-color: var(--fog-accent, #64748b); |
|
||||||
} |
|
||||||
|
|
||||||
.search-button { |
|
||||||
padding: 0.75rem 1.5rem; |
|
||||||
background: var(--fog-accent, #64748b); |
|
||||||
color: white; |
|
||||||
border: none; |
|
||||||
border-radius: 0.25rem; |
|
||||||
cursor: pointer; |
|
||||||
font-size: 1rem; |
|
||||||
} |
|
||||||
|
|
||||||
.search-button:hover:not(:disabled) { |
|
||||||
opacity: 0.9; |
|
||||||
} |
|
||||||
|
|
||||||
.search-button:disabled { |
|
||||||
opacity: 0.5; |
|
||||||
cursor: not-allowed; |
|
||||||
} |
|
||||||
|
|
||||||
.search-results { |
|
||||||
max-height: 60vh; |
|
||||||
overflow-y: auto; |
|
||||||
} |
|
||||||
|
|
||||||
.results-list { |
|
||||||
display: flex; |
|
||||||
flex-direction: column; |
|
||||||
gap: 0.5rem; |
|
||||||
} |
|
||||||
|
|
||||||
.result-item { |
|
||||||
text-align: left; |
|
||||||
padding: 1rem; |
|
||||||
border: 1px solid var(--fog-border, #e5e7eb); |
|
||||||
border-radius: 0.25rem; |
|
||||||
background: var(--fog-post, #ffffff); |
|
||||||
cursor: pointer; |
|
||||||
transition: background 0.2s; |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .result-item { |
|
||||||
background: var(--fog-dark-post, #1f2937); |
|
||||||
border-color: var(--fog-dark-border, #374151); |
|
||||||
} |
|
||||||
|
|
||||||
.result-item:hover { |
|
||||||
background: var(--fog-highlight, #f3f4f6); |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .result-item:hover { |
|
||||||
background: var(--fog-dark-highlight, #374151); |
|
||||||
} |
|
||||||
|
|
||||||
.result-header { |
|
||||||
display: flex; |
|
||||||
justify-content: space-between; |
|
||||||
align-items: center; |
|
||||||
margin-bottom: 0.5rem; |
|
||||||
} |
|
||||||
|
|
||||||
.result-type { |
|
||||||
font-size: 0.75rem; |
|
||||||
font-weight: 600; |
|
||||||
color: var(--fog-accent, #64748b); |
|
||||||
text-transform: uppercase; |
|
||||||
} |
|
||||||
|
|
||||||
.result-time { |
|
||||||
font-size: 0.75rem; |
|
||||||
color: var(--fog-text-light, #6b7280); |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .result-time { |
|
||||||
color: var(--fog-dark-text-light, #9ca3af); |
|
||||||
} |
|
||||||
|
|
||||||
.result-content { |
|
||||||
color: var(--fog-text, #1f2937); |
|
||||||
font-size: 0.875rem; |
|
||||||
line-height: 1.5; |
|
||||||
} |
|
||||||
|
|
||||||
:global(.dark) .result-content { |
|
||||||
color: var(--fog-dark-text, #f9fafb); |
|
||||||
} |
|
||||||
</style> |
|
||||||
@ -1,148 +0,0 @@ |
|||||||
<script lang="ts"> |
|
||||||
import { sessionManager } from '../../services/auth/session-manager.js'; |
|
||||||
import { signAndPublish } from '../../services/nostr/auth-handler.js'; |
|
||||||
import { relayManager } from '../../services/nostr/relay-manager.js'; |
|
||||||
import type { NostrEvent } from '../../types/nostr.js'; |
|
||||||
|
|
||||||
interface Props { |
|
||||||
parentEvent?: NostrEvent; // If replying to a post |
|
||||||
onPublished?: () => void; |
|
||||||
onCancel?: () => void; |
|
||||||
} |
|
||||||
|
|
||||||
let { parentEvent, onPublished, onCancel }: Props = $props(); |
|
||||||
|
|
||||||
let content = $state(''); |
|
||||||
let publishing = $state(false); |
|
||||||
let includeClientTag = $state(true); |
|
||||||
|
|
||||||
async function publish() { |
|
||||||
if (!sessionManager.isLoggedIn()) { |
|
||||||
alert('Please log in to post'); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if (!content.trim()) { |
|
||||||
alert('Post cannot be empty'); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
publishing = true; |
|
||||||
|
|
||||||
try { |
|
||||||
const tags: string[][] = []; |
|
||||||
|
|
||||||
// If replying, add NIP-10 threading tags |
|
||||||
if (parentEvent) { |
|
||||||
const rootTag = parentEvent.tags.find((t) => t[0] === 'root'); |
|
||||||
const rootId = rootTag?.[1] || parentEvent.id; |
|
||||||
|
|
||||||
tags.push(['e', parentEvent.id, '', 'reply']); |
|
||||||
tags.push(['p', parentEvent.pubkey]); |
|
||||||
tags.push(['root', rootId]); |
|
||||||
} |
|
||||||
|
|
||||||
if (includeClientTag) { |
|
||||||
tags.push(['client', 'Aitherboard']); |
|
||||||
} |
|
||||||
|
|
||||||
const event: Omit<NostrEvent, 'id' | 'sig'> = { |
|
||||||
kind: 1, |
|
||||||
pubkey: sessionManager.getCurrentPubkey()!, |
|
||||||
created_at: Math.floor(Date.now() / 1000), |
|
||||||
tags, |
|
||||||
content: content.trim() |
|
||||||
}; |
|
||||||
|
|
||||||
// Get target inbox if replying |
|
||||||
let targetInbox: string[] | undefined; |
|
||||||
if (parentEvent) { |
|
||||||
// Try to get target's inbox from their relay list |
|
||||||
try { |
|
||||||
const { fetchRelayLists } = await import('../../services/auth/relay-list-fetcher.js'); |
|
||||||
const { inbox } = await fetchRelayLists(parentEvent.pubkey); |
|
||||||
targetInbox = inbox; |
|
||||||
} catch { |
|
||||||
// Ignore errors, just use default relays |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
const relays = relayManager.getFeedPublishRelays(targetInbox); |
|
||||||
const result = await signAndPublish(event, relays); |
|
||||||
|
|
||||||
if (result.success.length > 0) { |
|
||||||
content = ''; |
|
||||||
onPublished?.(); |
|
||||||
} else { |
|
||||||
alert('Failed to publish post'); |
|
||||||
} |
|
||||||
} catch (error) { |
|
||||||
console.error('Error publishing post:', error); |
|
||||||
alert('Error publishing post'); |
|
||||||
} finally { |
|
||||||
publishing = false; |
|
||||||
} |
|
||||||
} |
|
||||||
</script> |
|
||||||
|
|
||||||
<div class="create-Feed-form"> |
|
||||||
{#if parentEvent} |
|
||||||
<div class="reply-context mb-2 p-2 bg-fog-highlight dark:bg-fog-dark-highlight rounded text-sm"> |
|
||||||
Replying to: {parentEvent.content.slice(0, 100)}... |
|
||||||
</div> |
|
||||||
{/if} |
|
||||||
|
|
||||||
<textarea |
|
||||||
bind:value={content} |
|
||||||
placeholder={parentEvent ? 'Write a reply...' : 'What\'s on your mind?'} |
|
||||||
class="w-full p-3 border border-fog-border dark:border-fog-dark-border rounded bg-fog-post dark:bg-fog-dark-post text-fog-text dark:text-fog-dark-text" |
|
||||||
rows="6" |
|
||||||
disabled={publishing} |
|
||||||
></textarea> |
|
||||||
|
|
||||||
<div class="flex items-center justify-between mt-2"> |
|
||||||
<label class="flex items-center gap-2 text-sm text-fog-text dark:text-fog-dark-text"> |
|
||||||
<input |
|
||||||
type="checkbox" |
|
||||||
bind:checked={includeClientTag} |
|
||||||
class="rounded" |
|
||||||
/> |
|
||||||
Include client tag |
|
||||||
</label> |
|
||||||
|
|
||||||
<div class="flex gap-2"> |
|
||||||
{#if onCancel} |
|
||||||
<button |
|
||||||
onclick={onCancel} |
|
||||||
class="px-4 py-2 text-sm border border-fog-border dark:border-fog-dark-border rounded hover:bg-fog-highlight dark:hover:bg-fog-dark-highlight" |
|
||||||
disabled={publishing} |
|
||||||
> |
|
||||||
Cancel |
|
||||||
</button> |
|
||||||
{/if} |
|
||||||
<button |
|
||||||
onclick={publish} |
|
||||||
class="px-4 py-2 text-sm bg-fog-accent dark:bg-fog-dark-accent text-white rounded hover:opacity-90 disabled:opacity-50" |
|
||||||
disabled={publishing || !content.trim()} |
|
||||||
> |
|
||||||
{publishing ? 'Publishing...' : parentEvent ? 'Reply' : 'Post'} |
|
||||||
</button> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
|
|
||||||
<style> |
|
||||||
.create-Feed-form { |
|
||||||
margin-bottom: 1rem; |
|
||||||
} |
|
||||||
|
|
||||||
textarea { |
|
||||||
resize: vertical; |
|
||||||
min-height: 120px; |
|
||||||
} |
|
||||||
|
|
||||||
textarea:focus { |
|
||||||
outline: none; |
|
||||||
border-color: var(--fog-accent, #64748b); |
|
||||||
} |
|
||||||
</style> |
|
||||||
@ -1,141 +0,0 @@ |
|||||||
<script lang="ts"> |
|
||||||
import { sessionManager } from '../../services/auth/session-manager.js'; |
|
||||||
import { signAndPublish } from '../../services/nostr/auth-handler.js'; |
|
||||||
import { relayManager } from '../../services/nostr/relay-manager.js'; |
|
||||||
import type { NostrEvent } from '../../types/nostr.js'; |
|
||||||
|
|
||||||
interface Props { |
|
||||||
parentEvent: NostrEvent; // The event to reply to |
|
||||||
onPublished?: () => void; |
|
||||||
onCancel?: () => void; |
|
||||||
} |
|
||||||
|
|
||||||
let { parentEvent, onPublished, onCancel }: Props = $props(); |
|
||||||
|
|
||||||
let content = $state(''); |
|
||||||
let publishing = $state(false); |
|
||||||
let includeClientTag = $state(true); |
|
||||||
|
|
||||||
async function publish() { |
|
||||||
if (!sessionManager.isLoggedIn()) { |
|
||||||
alert('Please log in to reply'); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if (!content.trim()) { |
|
||||||
alert('Reply cannot be empty'); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
publishing = true; |
|
||||||
|
|
||||||
try { |
|
||||||
const tags: string[][] = []; |
|
||||||
|
|
||||||
// Add NIP-10 threading tags for reply |
|
||||||
const rootTag = parentEvent.tags.find((t) => t[0] === 'root'); |
|
||||||
const rootId = rootTag?.[1] || parentEvent.id; |
|
||||||
|
|
||||||
tags.push(['e', parentEvent.id, '', 'reply']); |
|
||||||
tags.push(['p', parentEvent.pubkey]); |
|
||||||
tags.push(['root', rootId]); |
|
||||||
|
|
||||||
if (includeClientTag) { |
|
||||||
tags.push(['client', 'Aitherboard']); |
|
||||||
} |
|
||||||
|
|
||||||
const event: Omit<NostrEvent, 'id' | 'sig'> = { |
|
||||||
kind: 1, |
|
||||||
pubkey: sessionManager.getCurrentPubkey()!, |
|
||||||
created_at: Math.floor(Date.now() / 1000), |
|
||||||
tags, |
|
||||||
content: content.trim() |
|
||||||
}; |
|
||||||
|
|
||||||
// Get target inbox if replying |
|
||||||
let targetInbox: string[] | undefined; |
|
||||||
try { |
|
||||||
const { fetchRelayLists } = await import('../../services/user-data.js'); |
|
||||||
const { inbox } = await fetchRelayLists(parentEvent.pubkey); |
|
||||||
targetInbox = inbox; |
|
||||||
} catch { |
|
||||||
// Ignore errors, just use default relays |
|
||||||
} |
|
||||||
|
|
||||||
const relays = relayManager.getFeedPublishRelays(targetInbox); |
|
||||||
const result = await signAndPublish(event, relays); |
|
||||||
|
|
||||||
if (result.success.length > 0) { |
|
||||||
content = ''; |
|
||||||
onPublished?.(); |
|
||||||
} else { |
|
||||||
alert('Failed to publish reply'); |
|
||||||
} |
|
||||||
} catch (error) { |
|
||||||
console.error('Error publishing reply:', error); |
|
||||||
alert('Error publishing reply'); |
|
||||||
} finally { |
|
||||||
publishing = false; |
|
||||||
} |
|
||||||
} |
|
||||||
</script> |
|
||||||
|
|
||||||
<div class="reply-to-Feed-form"> |
|
||||||
<div class="reply-context mb-2 p-2 bg-fog-highlight dark:bg-fog-dark-highlight rounded text-sm"> |
|
||||||
<span class="font-semibold">Replying to:</span> {parentEvent.content.slice(0, 100)}... |
|
||||||
</div> |
|
||||||
|
|
||||||
<textarea |
|
||||||
bind:value={content} |
|
||||||
placeholder="Write a reply..." |
|
||||||
class="w-full p-3 border border-fog-border dark:border-fog-dark-border rounded bg-fog-post dark:bg-fog-dark-post text-fog-text dark:text-fog-dark-text" |
|
||||||
rows="6" |
|
||||||
disabled={publishing} |
|
||||||
></textarea> |
|
||||||
|
|
||||||
<div class="flex items-center justify-between mt-2"> |
|
||||||
<label class="flex items-center gap-2 text-sm text-fog-text dark:text-fog-dark-text"> |
|
||||||
<input |
|
||||||
type="checkbox" |
|
||||||
bind:checked={includeClientTag} |
|
||||||
class="rounded" |
|
||||||
/> |
|
||||||
Include client tag |
|
||||||
</label> |
|
||||||
|
|
||||||
<div class="flex gap-2"> |
|
||||||
{#if onCancel} |
|
||||||
<button |
|
||||||
onclick={onCancel} |
|
||||||
class="px-4 py-2 text-sm border border-fog-border dark:border-fog-dark-border rounded hover:bg-fog-highlight dark:hover:bg-fog-dark-highlight" |
|
||||||
disabled={publishing} |
|
||||||
> |
|
||||||
Cancel |
|
||||||
</button> |
|
||||||
{/if} |
|
||||||
<button |
|
||||||
onclick={publish} |
|
||||||
class="px-4 py-2 text-sm bg-fog-accent dark:bg-fog-dark-accent text-white rounded hover:opacity-90 disabled:opacity-50" |
|
||||||
disabled={publishing || !content.trim()} |
|
||||||
> |
|
||||||
{publishing ? 'Publishing...' : 'Reply'} |
|
||||||
</button> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
|
|
||||||
<style> |
|
||||||
.reply-to-Feed-form { |
|
||||||
margin-bottom: 1rem; |
|
||||||
} |
|
||||||
|
|
||||||
textarea { |
|
||||||
resize: vertical; |
|
||||||
min-height: 120px; |
|
||||||
} |
|
||||||
|
|
||||||
textarea:focus { |
|
||||||
outline: none; |
|
||||||
border-color: var(--fog-accent, #64748b); |
|
||||||
} |
|
||||||
</style> |
|
||||||
@ -1,184 +0,0 @@ |
|||||||
<script lang="ts"> |
|
||||||
import { sessionManager } from '../../services/auth/session-manager.js'; |
|
||||||
import { nostrClient } from '../../services/nostr/nostr-client.js'; |
|
||||||
import { relayManager } from '../../services/nostr/relay-manager.js'; |
|
||||||
import PublicationStatusModal from '../../components/modals/PublicationStatusModal.svelte'; |
|
||||||
import type { NostrEvent } from '../../types/nostr.js'; |
|
||||||
|
|
||||||
let title = $state(''); |
|
||||||
let content = $state(''); |
|
||||||
let topics = $state<string[]>([]); |
|
||||||
let topicInput = $state(''); |
|
||||||
let includeClientTag = $state(true); |
|
||||||
let publishing = $state(false); |
|
||||||
let showPublicationModal = $state(false); |
|
||||||
let publicationResults = $state<{ success: string[]; failed: Array<{ relay: string; error: string }> } | null>(null); |
|
||||||
let selectedRelays = $state<Set<string>>(new Set()); |
|
||||||
|
|
||||||
$effect(() => { |
|
||||||
// Initialize selected relays with thread publish relays |
|
||||||
const defaultRelays = relayManager.getThreadPublishRelays(); |
|
||||||
selectedRelays = new Set(defaultRelays); |
|
||||||
}); |
|
||||||
|
|
||||||
function addTopic() { |
|
||||||
if (topicInput.trim() && topics.length < 3) { |
|
||||||
topics = [...topics, topicInput.trim()]; |
|
||||||
topicInput = ''; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
function removeTopic(index: number) { |
|
||||||
topics = topics.filter((_, i) => i !== index); |
|
||||||
} |
|
||||||
|
|
||||||
async function publish() { |
|
||||||
if (!sessionManager.isLoggedIn()) { |
|
||||||
alert('Please log in to create a thread'); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if (!title.trim() || !content.trim()) { |
|
||||||
alert('Title and content are required'); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
publishing = true; |
|
||||||
|
|
||||||
try { |
|
||||||
const tags: string[][] = [['title', title]]; |
|
||||||
topics.forEach((topic) => tags.push(['t', topic])); |
|
||||||
if (includeClientTag) { |
|
||||||
tags.push(['client', 'Aitherboard']); |
|
||||||
} |
|
||||||
|
|
||||||
const event: Omit<NostrEvent, 'id' | 'sig'> = { |
|
||||||
kind: 11, |
|
||||||
pubkey: sessionManager.getCurrentPubkey()!, |
|
||||||
created_at: Math.floor(Date.now() / 1000), |
|
||||||
tags, |
|
||||||
content |
|
||||||
}; |
|
||||||
|
|
||||||
const signed = await sessionManager.signEvent(event); |
|
||||||
const result = await nostrClient.publish(signed, { |
|
||||||
relays: Array.from(selectedRelays) |
|
||||||
}); |
|
||||||
|
|
||||||
// Show publication status modal |
|
||||||
publicationResults = result; |
|
||||||
showPublicationModal = true; |
|
||||||
|
|
||||||
if (result.success.length > 0) { |
|
||||||
// Reset form on success |
|
||||||
title = ''; |
|
||||||
content = ''; |
|
||||||
topics = []; |
|
||||||
} |
|
||||||
} catch (error) { |
|
||||||
console.error('Error publishing thread:', error); |
|
||||||
alert('Error publishing thread'); |
|
||||||
} finally { |
|
||||||
publishing = false; |
|
||||||
} |
|
||||||
} |
|
||||||
</script> |
|
||||||
|
|
||||||
<form onsubmit={(e) => { e.preventDefault(); publish(); }} class="create-thread-form"> |
|
||||||
<div class="mb-4"> |
|
||||||
<label for="title" class="block mb-2 text-fog-text dark:text-fog-dark-text">Title</label> |
|
||||||
<input |
|
||||||
id="title" |
|
||||||
type="text" |
|
||||||
bind:value={title} |
|
||||||
class="w-full p-2 border border-fog-border dark:border-fog-dark-border bg-fog-post dark:bg-fog-dark-post text-fog-text dark:text-fog-dark-text" |
|
||||||
required |
|
||||||
/> |
|
||||||
</div> |
|
||||||
|
|
||||||
<div class="mb-4"> |
|
||||||
<label for="content" class="block mb-2 text-fog-text dark:text-fog-dark-text">Content</label> |
|
||||||
<textarea |
|
||||||
id="content" |
|
||||||
bind:value={content} |
|
||||||
class="w-full p-2 border border-fog-border dark:border-fog-dark-border bg-fog-post dark:bg-fog-dark-post text-fog-text dark:text-fog-dark-text" |
|
||||||
rows="10" |
|
||||||
required |
|
||||||
></textarea> |
|
||||||
</div> |
|
||||||
|
|
||||||
<div class="mb-4"> |
|
||||||
<label for="topics" class="block mb-2 text-fog-text dark:text-fog-dark-text">Topics (max 3)</label> |
|
||||||
<div class="flex gap-2 mb-2"> |
|
||||||
<input |
|
||||||
id="topics" |
|
||||||
type="text" |
|
||||||
bind:value={topicInput} |
|
||||||
onkeydown={(e) => e.key === 'Enter' && (e.preventDefault(), addTopic())} |
|
||||||
class="flex-1 p-2 border border-fog-border bg-fog-post text-fog-text" |
|
||||||
disabled={topics.length >= 3} |
|
||||||
/> |
|
||||||
<button type="button" onclick={addTopic} disabled={topics.length >= 3}> |
|
||||||
Add |
|
||||||
</button> |
|
||||||
</div> |
|
||||||
<div class="flex gap-2 flex-wrap"> |
|
||||||
{#each topics as topic, i} |
|
||||||
<span class="bg-fog-highlight dark:bg-fog-dark-highlight text-fog-text dark:text-fog-dark-text px-2 py-1 rounded"> |
|
||||||
{topic} |
|
||||||
<button type="button" onclick={() => removeTopic(i)} class="ml-2">×</button> |
|
||||||
</span> |
|
||||||
{/each} |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
|
|
||||||
<div class="mb-4"> |
|
||||||
<label> |
|
||||||
<input type="checkbox" bind:checked={includeClientTag} /> |
|
||||||
Include client tag |
|
||||||
</label> |
|
||||||
</div> |
|
||||||
|
|
||||||
<div class="mb-4"> |
|
||||||
<h3 class="block mb-2 text-fog-text dark:text-fog-dark-text font-semibold">Target Relays</h3> |
|
||||||
<div |
|
||||||
class="border border-fog-border dark:border-fog-dark-border rounded p-3 bg-fog-post dark:bg-fog-dark-post max-h-48 overflow-y-auto" |
|
||||||
role="group" |
|
||||||
aria-label="Target Relays" |
|
||||||
> |
|
||||||
{#each Array.from(selectedRelays) as relay} |
|
||||||
<label class="flex items-center gap-2 mb-2"> |
|
||||||
<input |
|
||||||
type="checkbox" |
|
||||||
checked={true} |
|
||||||
onchange={(e) => { |
|
||||||
if (!e.currentTarget.checked) { |
|
||||||
const newSet = new Set(selectedRelays); |
|
||||||
newSet.delete(relay); |
|
||||||
selectedRelays = newSet; |
|
||||||
} |
|
||||||
}} |
|
||||||
/> |
|
||||||
<span class="text-sm text-fog-text dark:text-fog-dark-text">{relay}</span> |
|
||||||
</label> |
|
||||||
{/each} |
|
||||||
{#if selectedRelays.size === 0} |
|
||||||
<p class="text-sm text-fog-text-light dark:text-fog-dark-text-light">No relays selected. At least one relay is required.</p> |
|
||||||
{/if} |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
|
|
||||||
<button type="submit" disabled={publishing || selectedRelays.size === 0} class="px-4 py-2 bg-fog-accent dark:bg-fog-dark-accent text-white hover:opacity-90 disabled:opacity-50 transition-colors rounded"> |
|
||||||
{publishing ? 'Publishing...' : 'Create Thread'} |
|
||||||
</button> |
|
||||||
</form> |
|
||||||
|
|
||||||
<PublicationStatusModal bind:open={showPublicationModal} bind:results={publicationResults} /> |
|
||||||
|
|
||||||
<style> |
|
||||||
.create-thread-form { |
|
||||||
max-width: var(--content-width); |
|
||||||
margin: 0 auto; |
|
||||||
padding: 1rem; |
|
||||||
} |
|
||||||
</style> |
|
||||||
@ -1,46 +0,0 @@ |
|||||||
/** |
|
||||||
* Full-text search index (deferred implementation) |
|
||||||
*/ |
|
||||||
|
|
||||||
import { getDB } from './indexeddb-store.js'; |
|
||||||
|
|
||||||
/** |
|
||||||
* Index event content for search |
|
||||||
*/ |
|
||||||
export async function indexEvent(eventId: string, content: string): Promise<void> { |
|
||||||
// Placeholder - full implementation would:
|
|
||||||
// 1. Tokenize content
|
|
||||||
// 2. Create inverted index
|
|
||||||
// 3. Store in IndexedDB
|
|
||||||
const db = await getDB(); |
|
||||||
await db.put('search', { |
|
||||||
id: eventId, |
|
||||||
content: content.toLowerCase() |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Search events by query |
|
||||||
*/ |
|
||||||
export async function searchEvents(query: string, limit: number = 50): Promise<string[]> { |
|
||||||
// Placeholder - full implementation would:
|
|
||||||
// 1. Tokenize query
|
|
||||||
// 2. Look up in inverted index
|
|
||||||
// 3. Rank results
|
|
||||||
// 4. Return event IDs
|
|
||||||
const db = await getDB(); |
|
||||||
const results: string[] = []; |
|
||||||
const lowerQuery = query.toLowerCase(); |
|
||||||
const tx = db.transaction('search', 'readonly'); |
|
||||||
|
|
||||||
for await (const cursor of tx.store.iterate()) { |
|
||||||
if (results.length >= limit) break; |
|
||||||
const content = (cursor.value as { content: string }).content; |
|
||||||
if (content.includes(lowerQuery)) { |
|
||||||
results.push(cursor.key as string); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
await tx.done; |
|
||||||
return results; |
|
||||||
} |
|
||||||
@ -1,126 +0,0 @@ |
|||||||
/** |
|
||||||
* Global keyboard shortcuts handler |
|
||||||
* Handles j/k navigation, r reply, z zap, / search, etc. |
|
||||||
*/ |
|
||||||
|
|
||||||
export interface KeyboardShortcut { |
|
||||||
key: string; |
|
||||||
ctrl?: boolean; |
|
||||||
shift?: boolean; |
|
||||||
alt?: boolean; |
|
||||||
meta?: boolean; |
|
||||||
handler: (e: KeyboardEvent) => void; |
|
||||||
description?: string; |
|
||||||
} |
|
||||||
|
|
||||||
class KeyboardShortcutsManager { |
|
||||||
private shortcuts: Map<string, KeyboardShortcut> = new Map(); |
|
||||||
private enabled = true; |
|
||||||
|
|
||||||
/** |
|
||||||
* Register a keyboard shortcut |
|
||||||
*/ |
|
||||||
register(shortcut: KeyboardShortcut): () => void { |
|
||||||
const key = this.getKeyString(shortcut); |
|
||||||
this.shortcuts.set(key, shortcut); |
|
||||||
|
|
||||||
// Return unregister function
|
|
||||||
return () => { |
|
||||||
this.shortcuts.delete(key); |
|
||||||
}; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Unregister a keyboard shortcut |
|
||||||
*/ |
|
||||||
unregister(key: string, modifiers?: { ctrl?: boolean; shift?: boolean; alt?: boolean; meta?: boolean }): void { |
|
||||||
const keyString = this.getKeyString({ key, ...modifiers, handler: () => {} }); |
|
||||||
this.shortcuts.delete(keyString); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Enable/disable shortcuts |
|
||||||
*/ |
|
||||||
setEnabled(enabled: boolean): void { |
|
||||||
this.enabled = enabled; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Check if shortcuts are enabled |
|
||||||
*/ |
|
||||||
isEnabled(): boolean { |
|
||||||
return this.enabled; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Handle keyboard event |
|
||||||
*/ |
|
||||||
handleKeydown(e: KeyboardEvent): void { |
|
||||||
if (!this.enabled) return; |
|
||||||
|
|
||||||
// Ignore if user is typing in an input, textarea, or contenteditable
|
|
||||||
const target = e.target as HTMLElement; |
|
||||||
if ( |
|
||||||
target.tagName === 'INPUT' || |
|
||||||
target.tagName === 'TEXTAREA' || |
|
||||||
target.isContentEditable |
|
||||||
) { |
|
||||||
// Allow / for search even in inputs
|
|
||||||
if (e.key === '/' && !e.ctrlKey && !e.metaKey) { |
|
||||||
// Let it through
|
|
||||||
} else { |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
const keyString = this.getKeyString({ |
|
||||||
key: e.key.toLowerCase(), |
|
||||||
ctrl: e.ctrlKey, |
|
||||||
shift: e.shiftKey, |
|
||||||
alt: e.altKey, |
|
||||||
meta: e.metaKey, |
|
||||||
handler: () => {} |
|
||||||
}); |
|
||||||
|
|
||||||
const shortcut = this.shortcuts.get(keyString); |
|
||||||
if (shortcut) { |
|
||||||
e.preventDefault(); |
|
||||||
e.stopPropagation(); |
|
||||||
shortcut.handler(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Get key string for shortcut lookup |
|
||||||
*/ |
|
||||||
private getKeyString(shortcut: KeyboardShortcut): string { |
|
||||||
const parts: string[] = []; |
|
||||||
if (shortcut.ctrl || shortcut.meta) parts.push('ctrl'); |
|
||||||
if (shortcut.shift) parts.push('shift'); |
|
||||||
if (shortcut.alt) parts.push('alt'); |
|
||||||
parts.push(shortcut.key.toLowerCase()); |
|
||||||
return parts.join('+'); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Initialize global keyboard handler |
|
||||||
*/ |
|
||||||
initialize(): void { |
|
||||||
if (typeof window === 'undefined') return; |
|
||||||
|
|
||||||
const handler = (e: KeyboardEvent) => this.handleKeydown(e); |
|
||||||
window.addEventListener('keydown', handler); |
|
||||||
|
|
||||||
// Return cleanup function
|
|
||||||
return () => { |
|
||||||
window.removeEventListener('keydown', handler); |
|
||||||
}; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
export const keyboardShortcuts = new KeyboardShortcutsManager(); |
|
||||||
|
|
||||||
// Initialize on module load (browser only)
|
|
||||||
if (typeof window !== 'undefined') { |
|
||||||
keyboardShortcuts.initialize(); |
|
||||||
} |
|
||||||
@ -1,50 +0,0 @@ |
|||||||
/** |
|
||||||
* Bech32 utilities for NIP-19 encoding/decoding |
|
||||||
*/ |
|
||||||
|
|
||||||
export interface DecodedBech32 { |
|
||||||
type: 'npub' | 'nsec' | 'note' | 'nevent' | 'naddr' | 'nprofile'; |
|
||||||
data: Uint8Array; |
|
||||||
relay?: string; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Decode a bech32 string (simplified - full implementation would use bech32 library) |
|
||||||
* This is a placeholder - in production, use a proper bech32 library |
|
||||||
*/ |
|
||||||
export function decodeBech32(bech32: string): DecodedBech32 | null { |
|
||||||
try { |
|
||||||
const prefix = bech32.split('1')[0]; |
|
||||||
if (!prefix) return null; |
|
||||||
|
|
||||||
// Basic validation - full implementation needed
|
|
||||||
if (prefix === 'npub' || prefix === 'nsec' || prefix === 'note') { |
|
||||||
return { |
|
||||||
type: prefix as 'npub' | 'nsec' | 'note', |
|
||||||
data: new Uint8Array(32) // Placeholder
|
|
||||||
}; |
|
||||||
} |
|
||||||
|
|
||||||
return null; |
|
||||||
} catch { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Encode data to bech32 format |
|
||||||
*/ |
|
||||||
export function encodeBech32(type: string, data: Uint8Array, relay?: string): string { |
|
||||||
// Placeholder - full implementation needed with bech32 library
|
|
||||||
// For now, return hex representation
|
|
||||||
return `${type}1${Array.from(data) |
|
||||||
.map((b) => b.toString(16).padStart(2, '0')) |
|
||||||
.join('')}`;
|
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Validate bech32 string format |
|
||||||
*/ |
|
||||||
export function isValidBech32(bech32: string): boolean { |
|
||||||
return /^(npub|nsec|note|nevent|naddr|nprofile)1[a-z0-9]+$/.test(bech32); |
|
||||||
} |
|
||||||
@ -1,55 +0,0 @@ |
|||||||
/** |
|
||||||
* Event validation utilities |
|
||||||
*/ |
|
||||||
|
|
||||||
import type { NostrEvent } from '../../types/nostr.js'; |
|
||||||
|
|
||||||
/** |
|
||||||
* Validate event structure |
|
||||||
*/ |
|
||||||
export function isValidEvent(event: unknown): event is NostrEvent { |
|
||||||
if (!event || typeof event !== 'object') return false; |
|
||||||
|
|
||||||
const e = event as Record<string, unknown>; |
|
||||||
|
|
||||||
return ( |
|
||||||
typeof e.kind === 'number' && |
|
||||||
typeof e.pubkey === 'string' && |
|
||||||
typeof e.created_at === 'number' && |
|
||||||
typeof e.content === 'string' && |
|
||||||
typeof e.id === 'string' && |
|
||||||
typeof e.sig === 'string' && |
|
||||||
Array.isArray(e.tags) && |
|
||||||
e.pubkey.length === 64 && |
|
||||||
e.id.length === 64 && |
|
||||||
e.sig.length === 128 |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Check if event has required tags for a kind |
|
||||||
*/ |
|
||||||
export function hasRequiredTags(event: NostrEvent, kind: number): boolean { |
|
||||||
switch (kind) { |
|
||||||
case 0: |
|
||||||
// Kind 0 can have tags or JSON content
|
|
||||||
return true; |
|
||||||
case 11: |
|
||||||
// Thread - should have title tag
|
|
||||||
return true; |
|
||||||
case 1111: |
|
||||||
// Comment - should have K and E tags
|
|
||||||
return event.tags.some((t) => t[0] === 'K' || t[0] === 'E'); |
|
||||||
default: |
|
||||||
return true; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Validate event signature (placeholder - would need crypto library) |
|
||||||
*/ |
|
||||||
export function isValidSignature(event: NostrEvent): boolean { |
|
||||||
// Placeholder - full implementation would verify signature
|
|
||||||
// using secp256k1 cryptography
|
|
||||||
return event.sig.length === 128; |
|
||||||
} |
|
||||||
Loading…
Reference in new issue