Enhance ChatService to process market messages in chat
- Updated ChatService to forward market messages to the chat interface, ensuring they are displayed alongside regular chat messages. - Improved message formatting for payment requests and order status updates, providing clearer user notifications. - Deprecated the previous order updates subscription method in useMarket, redirecting functionality to the chat service for better integration. These changes improve the user experience by consolidating message handling and enhancing clarity in communication.
This commit is contained in:
parent
c7e11a7c01
commit
5a899d1501
2 changed files with 32 additions and 36 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue