mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-03 08:07:21 +00:00
wip kind 14/15 within nip17 seal for attachments
This commit is contained in:
1 parent
5d8a4d4ace
commit
7a52562926
3 files changed
+48
-4
No files matched your search
@@ -13,6 +13,8 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import { ArrowLeft, Send, Loader2, AlertTriangle } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { NoteContent } from '@/components/NoteContent';
|
||||
import type { NostrEvent } from '@nostrify/nostrify';
|
||||
|
||||
interface DMChatAreaProps {
|
||||
pubkey: string | null;
|
||||
@@ -26,13 +28,15 @@ const formatMessageTime = (timestamp: number) => {
|
||||
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
};
|
||||
|
||||
const MessageBubble = memo(({
|
||||
const MessageBubble = memo(({
|
||||
message,
|
||||
isFromCurrentUser
|
||||
}: {
|
||||
message: {
|
||||
id: string;
|
||||
pubkey: string;
|
||||
kind: number;
|
||||
tags: string[][];
|
||||
decryptedContent?: string;
|
||||
error?: string;
|
||||
created_at: number;
|
||||
@@ -41,6 +45,18 @@ const MessageBubble = memo(({
|
||||
isFromCurrentUser: boolean;
|
||||
}) => {
|
||||
const isNIP4Message = message.kind === 4;
|
||||
const isFileAttachment = message.kind === 15; // Kind 15 = files/attachments
|
||||
|
||||
// Create a NostrEvent object for NoteContent (only used for kind 15)
|
||||
const messageEvent: NostrEvent = {
|
||||
id: message.id,
|
||||
pubkey: message.pubkey,
|
||||
created_at: message.created_at,
|
||||
kind: message.kind,
|
||||
tags: message.tags,
|
||||
content: message.decryptedContent || '',
|
||||
sig: '', // Not needed for display
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn("flex mb-4", isFromCurrentUser ? "justify-end" : "justify-start")}>
|
||||
@@ -52,7 +68,13 @@ const MessageBubble = memo(({
|
||||
)}>
|
||||
{message.error ? (
|
||||
<p className="text-sm italic opacity-70">🔒 Failed to decrypt</p>
|
||||
) : isFileAttachment ? (
|
||||
// Kind 15: Use NoteContent to render files/media with imeta tags
|
||||
<div className="text-sm">
|
||||
<NoteContent event={messageEvent} className="whitespace-pre-wrap break-words" />
|
||||
</div>
|
||||
) : (
|
||||
// Kind 4 (NIP-04) and Kind 14 (NIP-17 text): Display plain text
|
||||
<p className="text-sm whitespace-pre-wrap break-words">
|
||||
{message.decryptedContent}
|
||||
</p>
|
||||
|
||||
@@ -704,6 +704,10 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
|
||||
const sealEvent = JSON.parse(sealContent) as NostrEvent;
|
||||
|
||||
if (sealEvent.kind !== 13) {
|
||||
console.log(`[DM] ⚠️ NIP-17 INVALID SEAL - expected kind 13, got ${sealEvent.kind}`, {
|
||||
giftWrapId: event.id,
|
||||
sealKind: sealEvent.kind,
|
||||
});
|
||||
return {
|
||||
processedMessage: {
|
||||
...event,
|
||||
@@ -718,13 +722,21 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
|
||||
const messageContent = await user.signer.nip44.decrypt(sealEvent.pubkey, sealEvent.content);
|
||||
const messageEvent = JSON.parse(messageContent) as NostrEvent;
|
||||
|
||||
if (messageEvent.kind !== 14) {
|
||||
// Accept both kind 14 (text) and kind 15 (files/attachments)
|
||||
if (messageEvent.kind !== 14 && messageEvent.kind !== 15) {
|
||||
console.log(`[DM] ⚠️ NIP-17 MESSAGE WITH UNSUPPORTED INNER EVENT KIND:`, {
|
||||
giftWrapId: event.id,
|
||||
innerKind: messageEvent.kind,
|
||||
expectedKinds: [14, 15],
|
||||
sealPubkey: sealEvent.pubkey,
|
||||
messageEvent: messageEvent,
|
||||
});
|
||||
return {
|
||||
processedMessage: {
|
||||
...event,
|
||||
content: '',
|
||||
decryptedContent: '',
|
||||
error: `Invalid message format - expected kind 14, got ${messageEvent.kind}`,
|
||||
error: `Invalid message format - expected kind 14 or 15, got ${messageEvent.kind}`,
|
||||
},
|
||||
conversationPartner: event.pubkey,
|
||||
};
|
||||
@@ -750,6 +762,13 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
|
||||
conversationPartner = sealEvent.pubkey;
|
||||
}
|
||||
|
||||
console.log(`[DM] ✅ NIP-17 message processed successfully`, {
|
||||
giftWrapId: event.id,
|
||||
innerKind: messageEvent.kind, // 14 for text, 15 for files
|
||||
messageId: messageEvent.id,
|
||||
conversationPartner,
|
||||
});
|
||||
|
||||
return {
|
||||
processedMessage: {
|
||||
...messageEvent,
|
||||
|
||||
@@ -151,8 +151,11 @@ export function useSendDM(): UseSendDMReturn {
|
||||
...createImetaTags(attachments)
|
||||
];
|
||||
|
||||
// Use kind 15 for messages with file attachments, kind 14 for text-only
|
||||
const messageKind = (attachments && attachments.length > 0) ? 15 : 14;
|
||||
|
||||
const privateMessage: Omit<NostrEvent, 'id' | 'sig'> = {
|
||||
kind: 14,
|
||||
kind: messageKind,
|
||||
pubkey: user.pubkey,
|
||||
created_at: now,
|
||||
tags,
|
||||
|
||||
Reference in new issue
Block a user