From e9b1fb6577a7b28939a8d883d401563804ec6b7b Mon Sep 17 00:00:00 2001 From: Kobe Date: Tue, 27 May 2025 16:06:59 +0200 Subject: [PATCH] socketio changes --- __pycache__/extensions.cpython-313.pyc | Bin 493 -> 493 bytes .../__pycache__/conversations.cpython-313.pyc | Bin 21950 -> 21967 bytes routes/conversations.py | 7 +++++-- templates/conversations/conversation.html | 16 ++++++---------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/__pycache__/extensions.cpython-313.pyc b/__pycache__/extensions.cpython-313.pyc index ac913ccabdb2be3c97e49c01d0c73929082ec116..587c43f7774152c17b82003b56212418efdc6030 100644 GIT binary patch delta 20 acmaFM{Fa&fGcPX}0}!|!G~LMkh!Frll?C1a delta 20 acmaFM{Fa&fGcPX}0}$vYnQY{K#0UUArv+sI diff --git a/routes/__pycache__/conversations.cpython-313.pyc b/routes/__pycache__/conversations.cpython-313.pyc index 79199420f6b9be5eee0bdf6b856534a8d72d085c..e1787f47a29b66d43555c74728072afd7b6b7606 100644 GIT binary patch delta 196 zcmdnDn(_Q$9FzC+Dox(NDKgnW)_8NB=?->wo>2Z^ zMLnj?*0%2%IW?Jznt(cr4sX`6=VD^YV4i$OT4wTDV~NS}{^FaP9a)%FZwQOu5SIVQ z$}Gb6nSq&y{R0CtEBnvS;w%!@#cV*m=Zq`^BsMQ`31w!C-2BU3i=DlIk%6K386(W7 k&GG)XSY`Yf8QDKGGcZYl2mufg$oPQ`B>Ev~a%gBK0G60JkpKVy delta 171 zcmX@VnsMK1M&8f7yj%=Gpt;L5-FZl_qcC6q#%wYrMJ6bO$@DVla;Z z<7Qji_l)dCO(50AlMVeeHz(WQVPs6$?BE!{EIYw-M#%+XmCM|!7g$t(eimnuur6i; zDm`ap86duSt4k;|W7uYH4=r}~Tt)_l;%AJL9UZ+lxBDMvmGNO@RQt@#z$6JG1VBU} P;|Dg7=!cleX`z__D7rEv 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) {