mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-03 08:07:21 +00:00
update docs regarding default enabled state, and with info on all messaging components so that there's a better base for custom UIs
This commit is contained in:
1 parent
1c23b6bafc
commit
dbacdbc8ac
2 files changed
+128
-11
No files matched your search
@@ -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
|
||||
<DMProvider config={{ protocolMode: PROTOCOL_MODE.NIP17_ONLY }}>
|
||||
// Enable messaging in your app
|
||||
<DMProvider config={{
|
||||
enabled: true, // System is disabled by default
|
||||
protocolMode: PROTOCOL_MODE.NIP17_ONLY
|
||||
}}>
|
||||
{children}
|
||||
</DMProvider>
|
||||
```
|
||||
@@ -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 (
|
||||
<div className="container mx-auto p-4 h-screen">
|
||||
<DMMessagingInterface />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
@@ -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 (
|
||||
<DMProvider config={{ protocolMode: PROTOCOL_MODE.NIP17_ONLY }}>
|
||||
<DMProvider config={{
|
||||
enabled: true, // Enable the DM system
|
||||
protocolMode: PROTOCOL_MODE.NIP17_ONLY
|
||||
}}>
|
||||
{/* Your app components */}
|
||||
</DMProvider>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
**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';
|
||||
|
||||
<DMConversationList
|
||||
selectedPubkey={selectedPubkey}
|
||||
onSelectConversation={(pubkey) => setSelectedPubkey(pubkey)}
|
||||
onStatusClick={() => setShowStatus(true)} // optional
|
||||
className="h-full"
|
||||
/>
|
||||
```
|
||||
|
||||
**`DMChatArea`** - Message thread and compose area
|
||||
```tsx
|
||||
import { DMChatArea } from '@/components/dm/DMChatArea';
|
||||
|
||||
<DMChatArea
|
||||
pubkey={selectedPubkey}
|
||||
onBack={() => setSelectedPubkey(null)} // optional, for mobile back button
|
||||
className="h-full"
|
||||
/>
|
||||
```
|
||||
|
||||
**`DMStatusInfo`** - Debug/status panel
|
||||
```tsx
|
||||
import { DMStatusInfo } from '@/components/dm/DMStatusInfo';
|
||||
|
||||
<DMStatusInfo clearCacheAndRefetch={clearCacheAndRefetch} />
|
||||
```
|
||||
|
||||
### 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<string | null>(null);
|
||||
|
||||
return (
|
||||
<div className="flex h-screen">
|
||||
{/* Custom sidebar */}
|
||||
<aside className="w-64 border-r">
|
||||
<DMConversationList
|
||||
selectedPubkey={selectedPubkey}
|
||||
onSelectConversation={setSelectedPubkey}
|
||||
/>
|
||||
</aside>
|
||||
|
||||
{/* Custom main area */}
|
||||
<main className="flex-1">
|
||||
{selectedPubkey ? (
|
||||
<DMChatArea pubkey={selectedPubkey} />
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-full">
|
||||
<p>Select a conversation to start messaging</p>
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user