diff --git a/__pycache__/extensions.cpython-313.pyc b/__pycache__/extensions.cpython-313.pyc index ac913cc..587c43f 100644 Binary files a/__pycache__/extensions.cpython-313.pyc and b/__pycache__/extensions.cpython-313.pyc differ diff --git a/routes/__pycache__/conversations.cpython-313.pyc b/routes/__pycache__/conversations.cpython-313.pyc index 7919942..e1787f4 100644 Binary files a/routes/__pycache__/conversations.cpython-313.pyc and b/routes/__pycache__/conversations.cpython-313.pyc differ diff --git a/routes/conversations.py b/routes/conversations.py index c9c0427..c5e0554 100644 --- a/routes/conversations.py +++ b/routes/conversations.py @@ -336,8 +336,11 @@ def send_message(conversation_id): # Emit the message to all users in the conversation room socketio.emit('new_message', message_data, room=f'conversation_{conversation_id}') - # Return minimal response since the message will be received through WebSocket - return jsonify({'success': True}) + # Return response with message data + return jsonify({ + 'success': True, + 'message': message_data + }) @conversations_bp.route('/messages//attachment/') @login_required diff --git a/templates/conversations/conversation.html b/templates/conversations/conversation.html index a2be209..555d832 100644 --- a/templates/conversations/conversation.html +++ b/templates/conversations/conversation.html @@ -665,23 +665,19 @@ $(document).ready(function() { response: response, socketId: socket.id }); - if (response.success && response.message) { + if (response.success) { messageInput.val(''); fileInput.value = ''; $('#selectedFiles').text(''); // If socket is disconnected, append message directly - if (!state.connectionState.isConnected) { - try { - appendMessage(response.message); - } catch (error) { - console.error('Error appending message:', error); - // Refresh the page to show the new message - window.location.reload(); - } + if (!state.connectionState.isConnected && response.message) { + console.log('Socket disconnected, appending message directly'); + appendMessage(response.message); } } else { - console.error('Invalid response format:', response); + console.error('Message send failed:', response); + alert('Failed to send message. Please try again.'); } }, error: function(xhr, status, error) {