socketio changes

This commit is contained in:
2025-05-27 16:06:59 +02:00
parent 26572b740e
commit e9b1fb6577
4 changed files with 11 additions and 12 deletions

View File

@@ -336,8 +336,11 @@ def send_message(conversation_id):
# Emit the message to all users in the conversation room # Emit the message to all users in the conversation room
socketio.emit('new_message', message_data, room=f'conversation_{conversation_id}') socketio.emit('new_message', message_data, room=f'conversation_{conversation_id}')
# Return minimal response since the message will be received through WebSocket # Return response with message data
return jsonify({'success': True}) return jsonify({
'success': True,
'message': message_data
})
@conversations_bp.route('/messages/<int:message_id>/attachment/<int:attachment_index>') @conversations_bp.route('/messages/<int:message_id>/attachment/<int:attachment_index>')
@login_required @login_required

View File

@@ -665,23 +665,19 @@ $(document).ready(function() {
response: response, response: response,
socketId: socket.id socketId: socket.id
}); });
if (response.success && response.message) { if (response.success) {
messageInput.val(''); messageInput.val('');
fileInput.value = ''; fileInput.value = '';
$('#selectedFiles').text(''); $('#selectedFiles').text('');
// If socket is disconnected, append message directly // If socket is disconnected, append message directly
if (!state.connectionState.isConnected) { if (!state.connectionState.isConnected && response.message) {
try { console.log('Socket disconnected, appending message directly');
appendMessage(response.message); appendMessage(response.message);
} catch (error) {
console.error('Error appending message:', error);
// Refresh the page to show the new message
window.location.reload();
}
} }
} else { } 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) { error: function(xhr, status, error) {