diff --git a/client/js/messages-page.js b/client/js/messages-page.js
index e0411d5..bf5f335 100644
--- a/client/js/messages-page.js
+++ b/client/js/messages-page.js
@@ -194,15 +194,20 @@ $(document).ready(function () {
},
success: function (message) {
$('#messageModal').remove();
-
- const canReply = currentUsername !== message.sender.username;
-
+
+ const canReply = type === 'inbox' || type === 'archive';
+
+ console.log('Received message:', message); // Add this line for debugging
+ console.log('Sender object:', message.sender);
+ console.log('Recipient object:', message.recipient);
+
+
const formattedMessage = `
- From: ${escapeHtml(message.sender.username)}
- Date: ${new Date(message.sentAt).toLocaleString()}
- ${escapeHtml(message.message).replace(/\n/g, '
')}
+ From: ${escapeHtml(message.sender && message.sender.username ? message.sender.username : 'Unknown')}
+ Date: ${new Date(message.sentAt).toLocaleString()}
+ ${escapeHtml(message.message).replace(/\n/g, '
')}
`;
-
+
const messageHtml = `
- + - From: ${escapeHtml(message.sender.username)} + From: ${escapeHtml(message.sender ? message.sender.username : 'Unknown')}
- + - To: ${escapeHtml(message.recipient.username)} + To: ${escapeHtml(message.recipient ? message.recipient.username : 'Unknown')}
Subject: ${escapeHtml(message.subject)}
Date: ${new Date(message.sentAt).toLocaleString()}
${formattedMessage}
- ${ - canReply - ? ` - - ` - : '' - }