@@ -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 } ) ;
0 commit comments