diff --git a/AGENTS.md b/AGENTS.md index 09a9f24..845eb37 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,6 +19,7 @@ This project is a Nostr client application built with React 18.x, TailwindCSS 3. - `/src/components/`: UI components including NostrProvider for Nostr integration - `/src/components/ui/`: shadcn/ui components (48+ components available) - `/src/components/auth/`: Authentication-related components (LoginArea, LoginDialog, etc.) + - `/src/components/dm/`: Direct messaging UI components (DMMessagingInterface, DMConversationList, DMChatArea) - Zap components: `ZapButton`, `ZapDialog`, `WalletModal` for Lightning payments - `/src/hooks/`: Custom hooks including: - `useNostr`: Core Nostr protocol integration @@ -38,11 +39,11 @@ This project is a Nostr client application built with React 18.x, TailwindCSS 3. - `useNWC`: Nostr Wallet Connect connection management - `useNWCContext`: Access NWC context provider - `useShakespeare`: AI chat completions with Shakespeare AI API - - `useDMContext`: Direct messaging system (NIP-04 & NIP-17) - - `useConversationMessages`: Paginated messages for specific conversations - `/src/pages/`: Page components used by React Router (Index, NotFound) - `/src/lib/`: Utility functions and shared logic - `/src/contexts/`: React context providers (AppContext, NWCContext, DMContext) + - `useDMContext`: Hook exported from DMContext for direct messaging (NIP-04 & NIP-17) + - `useConversationMessages`: Hook exported from DMContext for paginated messages - `/src/test/`: Testing utilities including TestApp component - `/public/`: Static assets - `App.tsx`: Main app component with provider setup @@ -750,7 +751,7 @@ The `EditProfileForm` component displays just the form. It requires no props, an ### Direct Messaging (NIP-04 & NIP-17) -The project includes a complete direct messaging system with real-time updates, encrypted storage, and support for both NIP-04 (legacy) and NIP-17 (modern private messaging) protocols. +The project includes a complete direct messaging system with real-time updates, encrypted storage, and support for both NIP-04 (legacy) and NIP-17 (modern private messaging) protocols. **The system is disabled by default** - enable it by passing `enabled: true` in the config. **Quick Setup:** @@ -758,8 +759,11 @@ The project includes a complete direct messaging system with real-time updates, import { DMProvider } from '@/contexts/DMContext'; import { PROTOCOL_MODE } from '@/lib/dmConstants'; -// Wrap your app with DMProvider - +// Enable messaging in your app + {children} ``` @@ -816,6 +820,38 @@ const { messages, hasMoreMessages, loadEarlierMessages } = useConversationMessag For complete implementation details, file attachments, and advanced features, see **`docs/NOSTR_DIRECT_MESSAGES.md`**. +### Direct Messaging UI Component + +To include a complete messaging interface in your app, use the `DMMessagingInterface` component: + +```tsx +import { DMMessagingInterface } from "@/components/dm/DMMessagingInterface"; + +function MessagesPage() { + return ( +
+ +
+ ); +} +``` + +The `DMMessagingInterface` component provides a complete messaging UI with: +- Conversation list with Active/Requests tabs +- Message thread view with pagination +- Compose area with file upload support +- Real-time message updates +- Mobile-responsive layout (shows one panel at a time on mobile) + +It requires no props and works automatically when wrapped in `DMProvider`. + +**For custom layouts**, individual components are available: +- `DMConversationList` - Conversation sidebar with tabs +- `DMChatArea` - Message thread and compose area +- `DMStatusInfo` - Debug/status panel + +See `docs/NOSTR_DIRECT_MESSAGES.md` for custom layout examples. + ### Uploading Files on Nostr Use the `useUploadFile` hook to upload files. This hook uses Blossom servers for file storage and returns NIP-94 compatible tags. diff --git a/docs/NOSTR_DIRECT_MESSAGES.md b/docs/NOSTR_DIRECT_MESSAGES.md index a75092c..07e9ec0 100644 --- a/docs/NOSTR_DIRECT_MESSAGES.md +++ b/docs/NOSTR_DIRECT_MESSAGES.md @@ -4,7 +4,9 @@ This project includes a complete direct messaging system supporting both NIP-04 ## Quick Start -### 1. Wrap Your App with DMProvider +### 1. Enable Direct Messaging + +The `DMProvider` is already added to your app, but **disabled by default**. To enable messaging, pass `enabled: true` in the config: ```tsx import { DMProvider } from '@/contexts/DMContext'; @@ -12,17 +14,24 @@ import { PROTOCOL_MODE } from '@/lib/dmConstants'; function App() { return ( - + {/* Your app components */} ); } ``` -**Protocol Modes:** -- `PROTOCOL_MODE.NIP04_ONLY` - Legacy encryption only -- `PROTOCOL_MODE.NIP17_ONLY` - Modern private messages (recommended) -- `PROTOCOL_MODE.BOTH` - Support both protocols +**Config Options:** +- `enabled` (boolean, default: `false`) - Enable/disable entire DM system. When false, no messages are loaded, stored, or processed. +- `protocolMode` (ProtocolMode, default: `PROTOCOL_MODE.NIP17_ONLY`) - Which protocols to support: + - `PROTOCOL_MODE.NIP04_ONLY` - Legacy encryption only + - `PROTOCOL_MODE.NIP17_ONLY` - Modern private messages (recommended) + - `PROTOCOL_MODE.BOTH` - Support both protocols (for backwards compatibility) + +**Note**: The DM system uses domain-based IndexedDB naming (`nostr-dm-store-${hostname}`) to prevent conflicts between multiple apps on the same domain. ### 2. Send Messages @@ -327,4 +336,76 @@ function SettingsButton() { - **Local Encryption**: IndexedDB storage encrypted with user's NIP-44 key - **Ephemeral Keys**: Random keys for NIP-17 gift wraps (sender anonymity) - **No Plaintext**: Decrypted content never persisted unencrypted +- **Domain Isolation**: IndexedDB databases are namespaced by hostname to prevent data conflicts + +## Building Custom Messaging UIs + +For advanced use cases, you can use the individual DM components to build custom layouts: + +### Available Components + +**`DMConversationList`** - Conversation sidebar with tabs +```tsx +import { DMConversationList } from '@/components/dm/DMConversationList'; + + setSelectedPubkey(pubkey)} + onStatusClick={() => setShowStatus(true)} // optional + className="h-full" +/> +``` + +**`DMChatArea`** - Message thread and compose area +```tsx +import { DMChatArea } from '@/components/dm/DMChatArea'; + + setSelectedPubkey(null)} // optional, for mobile back button + className="h-full" +/> +``` + +**`DMStatusInfo`** - Debug/status panel +```tsx +import { DMStatusInfo } from '@/components/dm/DMStatusInfo'; + + +``` + +### Custom Layout Example + +```tsx +import { useState } from 'react'; +import { DMConversationList } from '@/components/dm/DMConversationList'; +import { DMChatArea } from '@/components/dm/DMChatArea'; + +function CustomMessagingLayout() { + const [selectedPubkey, setSelectedPubkey] = useState(null); + + return ( +
+ {/* Custom sidebar */} + + + {/* Custom main area */} +
+ {selectedPubkey ? ( + + ) : ( +
+

Select a conversation to start messaging

+
+ )} +
+
+ ); +} +```