mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 00:37:23 +00:00
wip kind 14/15 within nip17 seal for attachments
This commit is contained in:
1 parent
5d8a4d4ace
commit
7a52562926
3 files changed
+47
-3
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 { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
||||||
import { ArrowLeft, Send, Loader2, AlertTriangle } from 'lucide-react';
|
import { ArrowLeft, Send, Loader2, AlertTriangle } from 'lucide-react';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
import { NoteContent } from '@/components/NoteContent';
|
||||||
|
import type { NostrEvent } from '@nostrify/nostrify';
|
||||||
|
|
||||||
interface DMChatAreaProps {
|
interface DMChatAreaProps {
|
||||||
pubkey: string | null;
|
pubkey: string | null;
|
||||||
@@ -32,7 +34,9 @@ const MessageBubble = memo(({
|
|||||||
}: {
|
}: {
|
||||||
message: {
|
message: {
|
||||||
id: string;
|
id: string;
|
||||||
|
pubkey: string;
|
||||||
kind: number;
|
kind: number;
|
||||||
|
tags: string[][];
|
||||||
decryptedContent?: string;
|
decryptedContent?: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
created_at: number;
|
created_at: number;
|
||||||
@@ -41,6 +45,18 @@ const MessageBubble = memo(({
|
|||||||
isFromCurrentUser: boolean;
|
isFromCurrentUser: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const isNIP4Message = message.kind === 4;
|
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 (
|
return (
|
||||||
<div className={cn("flex mb-4", isFromCurrentUser ? "justify-end" : "justify-start")}>
|
<div className={cn("flex mb-4", isFromCurrentUser ? "justify-end" : "justify-start")}>
|
||||||
@@ -52,7 +68,13 @@ const MessageBubble = memo(({
|
|||||||
)}>
|
)}>
|
||||||
{message.error ? (
|
{message.error ? (
|
||||||
<p className="text-sm italic opacity-70">🔒 Failed to decrypt</p>
|
<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">
|
<p className="text-sm whitespace-pre-wrap break-words">
|
||||||
{message.decryptedContent}
|
{message.decryptedContent}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -704,6 +704,10 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
|
|||||||
const sealEvent = JSON.parse(sealContent) as NostrEvent;
|
const sealEvent = JSON.parse(sealContent) as NostrEvent;
|
||||||
|
|
||||||
if (sealEvent.kind !== 13) {
|
if (sealEvent.kind !== 13) {
|
||||||
|
console.log(`[DM] ⚠️ NIP-17 INVALID SEAL - expected kind 13, got ${sealEvent.kind}`, {
|
||||||
|
giftWrapId: event.id,
|
||||||
|
sealKind: sealEvent.kind,
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
processedMessage: {
|
processedMessage: {
|
||||||
...event,
|
...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 messageContent = await user.signer.nip44.decrypt(sealEvent.pubkey, sealEvent.content);
|
||||||
const messageEvent = JSON.parse(messageContent) as NostrEvent;
|
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 {
|
return {
|
||||||
processedMessage: {
|
processedMessage: {
|
||||||
...event,
|
...event,
|
||||||
content: '',
|
content: '',
|
||||||
decryptedContent: '',
|
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,
|
conversationPartner: event.pubkey,
|
||||||
};
|
};
|
||||||
@@ -750,6 +762,13 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY,
|
|||||||
conversationPartner = sealEvent.pubkey;
|
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 {
|
return {
|
||||||
processedMessage: {
|
processedMessage: {
|
||||||
...messageEvent,
|
...messageEvent,
|
||||||
|
|||||||
@@ -151,8 +151,11 @@ export function useSendDM(): UseSendDMReturn {
|
|||||||
...createImetaTags(attachments)
|
...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'> = {
|
const privateMessage: Omit<NostrEvent, 'id' | 'sig'> = {
|
||||||
kind: 14,
|
kind: messageKind,
|
||||||
pubkey: user.pubkey,
|
pubkey: user.pubkey,
|
||||||
created_at: now,
|
created_at: now,
|
||||||
tags,
|
tags,
|
||||||
|
|||||||
Reference in new issue
Block a user