diff --git a/src/App.tsx b/src/App.tsx index 2f33702..7aaf63e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -13,6 +13,7 @@ import { AppProvider } from '@/components/AppProvider'; import { NWCProvider } from '@/contexts/NWCContext'; import { DMProvider } from '@/contexts/DMContext'; import { AppConfig } from '@/contexts/AppContext'; +import { PROTOCOL_MODE } from '@/lib/dmConstants'; import AppRouter from './AppRouter'; const head = createHead({ @@ -44,7 +45,11 @@ const presetRelays = [ ]; const dmSettings = { - enableNIP17: true, + // Choose one: + // PROTOCOL_MODE.NIP04_ONLY - Force NIP-04 (legacy) only + // PROTOCOL_MODE.NIP17_ONLY - Force NIP-17 (private) only + // PROTOCOL_MODE.NIP04_OR_NIP17 - Allow users to choose between NIP-04 and NIP-17 (defaults to NIP-17) + protocolMode: PROTOCOL_MODE.NIP04_OR_NIP17, }; export function App() { @@ -55,7 +60,7 @@ export function App() { - + diff --git a/src/components/dm/ChatArea.tsx b/src/components/dm/ChatArea.tsx index 76a6f4f..cc69c04 100644 --- a/src/components/dm/ChatArea.tsx +++ b/src/components/dm/ChatArea.tsx @@ -3,13 +3,13 @@ import { useConversationMessages, useDMContext } from '@/contexts/DMContext'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useAuthor } from '@/hooks/useAuthor'; import { genUserName } from '@/lib/genUserName'; -import { MESSAGE_PROTOCOL } from '@/lib/dmConstants'; +import { MESSAGE_PROTOCOL, PROTOCOL_MODE, type MessageProtocol } from '@/lib/dmConstants'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Textarea } from '@/components/ui/textarea'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { Badge } from '@/components/ui/badge'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; import { ArrowLeft, Send, Loader2, AlertTriangle } from 'lucide-react'; import { cn } from '@/lib/utils'; @@ -137,12 +137,26 @@ const EmptyState = () => { export const ChatArea = ({ pubkey, onBack, className }: ChatAreaProps) => { const { user } = useCurrentUser(); - const { sendMessage, isNIP17Enabled } = useDMContext(); - const { messages, totalCount } = useConversationMessages(pubkey || ''); + const { sendMessage, protocolMode } = useDMContext(); + const { messages } = useConversationMessages(pubkey || ''); const [messageText, setMessageText] = useState(''); const [isSending, setIsSending] = useState(false); + + // Determine default protocol based on mode + const getDefaultProtocol = () => { + if (protocolMode === PROTOCOL_MODE.NIP04_ONLY) return MESSAGE_PROTOCOL.NIP04; + if (protocolMode === PROTOCOL_MODE.NIP17_ONLY) return MESSAGE_PROTOCOL.NIP17; + if (protocolMode === PROTOCOL_MODE.NIP04_OR_NIP17) return MESSAGE_PROTOCOL.NIP17; + // Fallback to NIP-17 for any unexpected mode + return MESSAGE_PROTOCOL.NIP17; + }; + + const [selectedProtocol, setSelectedProtocol] = useState(getDefaultProtocol()); const scrollAreaRef = useRef(null); + + // Determine if selection is allowed + const allowSelection = protocolMode === PROTOCOL_MODE.NIP04_OR_NIP17; // Auto-scroll to bottom when new messages arrive useEffect(() => { @@ -162,7 +176,7 @@ export const ChatArea = ({ pubkey, onBack, className }: ChatAreaProps) => { await sendMessage({ recipientPubkey: pubkey, content: messageText.trim(), - protocol: isNIP17Enabled ? MESSAGE_PROTOCOL.NIP17 : MESSAGE_PROTOCOL.NIP04, + protocol: selectedProtocol, }); setMessageText(''); } catch (error) { @@ -223,17 +237,6 @@ export const ChatArea = ({ pubkey, onBack, className }: ChatAreaProps) => {
-
- - {isNIP17Enabled ? "NIP-17 (Private)" : "NIP-04 (Legacy)"} - - {totalCount > 0 && ( - - {totalCount} message{totalCount !== 1 ? 's' : ''} - - )} -
-