Skip to content

Commit 7f008ba

Browse files
authored
Merge pull request #24 from HitsukiMok/jim/improved-yancy-task
fix: found and fix the issue on the messaging system
2 parents cc30354 + ea7c914 commit 7f008ba

3 files changed

Lines changed: 2 additions & 12 deletions

File tree

backend/src/config/socket.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,14 @@ export const initializeSocket = (httpServer) => {
7474

7575
// ── send_message ───────────────────────────────────────────────────────────
7676
socket.on('send_message', async ({ conversationId, itemId, content }) => {
77-
console.log('[send_message] received', { conversationId, itemId, userId: socket.data.userId, contentLen: content?.length });
78-
7977
if (!conversationId || !itemId || !content?.trim()) {
80-
console.warn('[send_message] REJECTED — missing field', { conversationId: !!conversationId, itemId: !!itemId, hasContent: !!content?.trim() });
8178
socket.emit('error', { message: 'conversationId, itemId, and content are required' });
8279
return;
8380
}
8481

8582
try {
8683
const conversation = await Conversation.findById(conversationId);
8784
if (!conversation) {
88-
console.warn('[send_message] REJECTED — conversation not found:', conversationId);
8985
socket.emit('error', { message: 'Conversation not found' });
9086
return;
9187
}
@@ -95,10 +91,7 @@ export const initializeSocket = (httpServer) => {
9591
const isReporterSender = conversation.reporter.toString() === userId;
9692
const isFinderSender = conversation.finder.toString() === userId;
9793

98-
console.log('[send_message] auth check', { reporter: conversation.reporter.toString(), finder: conversation.finder.toString(), userId, isReporterSender, isFinderSender });
99-
10094
if (!isReporterSender && !isFinderSender) {
101-
console.warn('[send_message] REJECTED — not a participant');
10295
socket.emit('error', { message: 'Not authorized to send messages in this conversation' });
10396
return;
10497
}
@@ -133,15 +126,13 @@ export const initializeSocket = (httpServer) => {
133126
}
134127
}
135128

136-
console.log('[send_message] creating message', { conversationId, itemId, sender: userId, receiver: receiverId });
137129
const newMessage = await Message.create({
138130
conversation: conversationId,
139131
item: itemId,
140132
sender: userId,
141133
receiver: receiverId,
142134
content: content.trim(),
143135
});
144-
console.log('[send_message] message saved to DB:', newMessage._id.toString());
145136

146137
// Update conversation timestamp manually
147138
conversation.updatedAt = new Date();
@@ -168,7 +159,7 @@ export const initializeSocket = (httpServer) => {
168159
isMuted: conversation.mutedBy && conversation.mutedBy.some(id => id.toString() === receiverId)
169160
});
170161
} catch (err) {
171-
console.error(`[send_message] CAUGHT ERROR (room: ${conversationId}):`, err);
162+
console.error(`send_message error (room: ${conversationId}):`, err.message);
172163
socket.emit('error', { message: 'Failed to send message. Please try again.' });
173164
}
174165
});

frontend/src/ItemDetailPage/ChatPanel.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ export default function ChatPanel({ itemId, conversationId: initialConvId, curre
165165
socket.emit('stop_typing', { conversationId: activeConvId })
166166
}
167167

168-
console.log('[ChatPanel] emitting send_message', { conversationId: activeConvId, itemId, socketConnected: socket?.connected })
169168
socket.emit('send_message', {
170169
conversationId: activeConvId,
171170
itemId,

frontend/src/context/SocketContext.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { io } from 'socket.io-client';
33

44
const SocketContext = createContext(null);
55

6-
const SOCKET_URL = import.meta.env.VITE_SOCKET_URL || 'http://localhost:5000';
6+
const SOCKET_URL = import.meta.env.VITE_SOCKET_URL || import.meta.env.VITE_API_URL || 'http://localhost:5000';
77

88
function getStoredToken() {
99
return localStorage.getItem('kyurToken');

0 commit comments

Comments
 (0)