diff --git a/src/modules/chat/services/chat-service.ts b/src/modules/chat/services/chat-service.ts index b1f839b..29919db 100644 --- a/src/modules/chat/services/chat-service.ts +++ b/src/modules/chat/services/chat-service.ts @@ -722,6 +722,7 @@ export class ChatService extends BaseService { // Forward to market handler if (this.marketMessageHandler) { await this.marketMessageHandler(event) + console.log('💬 Market message forwarded to market handler and will also be added to chat') } else { console.warn('Market message handler not available, message will be treated as chat') } @@ -730,12 +731,36 @@ export class ChatService extends BaseService { // Not JSON or not a market message, treat as regular chat } - // Only process as chat message if it's not a market message - if (!isMarketMessage) { + // Process as chat message regardless (market messages should also appear in chat) + { + // Format the content for display based on whether it's a market message + let displayContent = decryptedContent + + if (isMarketMessage) { + try { + const parsedContent = JSON.parse(decryptedContent) + if (parsedContent.type === 1) { + // Payment request + displayContent = `💰 Payment Request for Order ${parsedContent.id}\n${parsedContent.message || 'Please pay to proceed with your order'}` + } else if (parsedContent.type === 2) { + // Order status update + const status = [] + if (parsedContent.paid === true) status.push('✅ Paid') + else if (parsedContent.paid === false) status.push('⏳ Payment Pending') + if (parsedContent.shipped === true) status.push('📦 Shipped') + else if (parsedContent.shipped === false) status.push('🔄 Processing') + + displayContent = `📋 Order Update: ${parsedContent.id}\n${status.join(' | ')}\n${parsedContent.message || ''}` + } + } catch (e) { + // Fallback to raw content if parsing fails + } + } + // Create a chat message const message: ChatMessage = { id: event.id, - content: decryptedContent, + content: displayContent, created_at: event.created_at, sent: false, pubkey: senderPubkey diff --git a/src/modules/market/composables/useMarket.ts b/src/modules/market/composables/useMarket.ts index b9cce29..2321a70 100644 --- a/src/modules/market/composables/useMarket.ts +++ b/src/modules/market/composables/useMarket.ts @@ -344,40 +344,11 @@ export function useMarket() { } } - // Subscribe to order-related DMs (payment requests, status updates) + // Note: Order DMs are now handled by the chat service forwarding mechanism + // This method is deprecated and should not be called const subscribeToOrderUpdates = (): (() => void) | null => { - try { - const userPubkey = authService.user.value?.pubkey - if (!userPubkey) { - console.warn('Cannot subscribe to order updates: no user pubkey available', { - authServicePubkey: authService.user.value?.pubkey, - isAuthenticated: authService.isAuthenticated.value - }) - return null - } - - console.log('🔔 Setting up order updates subscription for user:', userPubkey.slice(0, 8)) - - // Subscribe to encrypted DMs directed to this user (payment requests, status updates) - const unsubscribe = relayHub.subscribe({ - id: `order-updates-${userPubkey}`, - filters: [ - { - kinds: [4], // Encrypted DMs - '#p': [userPubkey], // Messages directed to this user - since: Math.floor(Date.now() / 1000) - 3600 // Last hour to avoid old messages - } - ], - onEvent: async (event: any) => { - await handleOrderDM(event) - } - }) - - return unsubscribe - } catch (error) { - console.error('Failed to subscribe to order updates:', error) - return null - } + console.log('🔔 Order updates are now handled by chat service forwarding') + return null } // Handle incoming order DMs (payment requests, status updates)