feat: Enhance message sending feedback and improve reconnection logic with optimized delays

This commit is contained in:
Janez T
2025-10-15 14:59:00 +02:00
parent 829b8605eb
commit 61d0b831ab
3 changed files with 38 additions and 9 deletions

View File

@@ -522,10 +522,19 @@ class ConnectionProvider with ChangeNotifier {
// Channel messages are ephemeral (not persisted) - mark as "sent" immediately
// They don't have ACK/TAG mechanism like direct messages
if (messageId != null) {
print('✅ [Provider] Channel message sent successfully - marking as sent: $messageId');
print('✅ [ConnectionProvider] Channel message sent successfully');
print(' Message ID: $messageId');
print(' onMessageSent callback exists: ${onMessageSent != null}');
// Small delay to ensure the message is in the MessagesProvider list
// before we try to mark it as sent
await Future.delayed(const Duration(milliseconds: 50));
// Use a dummy ACK tag (0) and timeout (0) for channel messages
// This will trigger the callback to mark the message as "sent"
print(' Calling onMessageSent callback...');
onMessageSent?.call(messageId, 0, 0);
print(' onMessageSent callback completed');
}
} catch (e) {
_error = 'Failed to send channel message: $e';

View File

@@ -334,6 +334,12 @@ class MessagesProvider with ChangeNotifier {
/// Add a sent message with initial status
void addSentMessage(Message message) {
print('📝 [MessagesProvider] addSentMessage called');
print(' Message ID: ${message.id}');
print(' Message type: ${message.messageType}');
print(' Initial status: ${message.deliveryStatus}');
print(' Message text preview: ${message.text.substring(0, message.text.length > 30 ? 30 : message.text.length)}...');
// Always enhance message with SAR parser to detect SAR markers
final enhancedMessage = SarMessageParser.enhanceMessage(message);
@@ -348,6 +354,8 @@ class MessagesProvider with ChangeNotifier {
deliveryStatus: MessageDeliveryStatus.sending,
);
_messages.add(sendingMessage);
print(' ✅ Message added to list at index ${_messages.length - 1}');
print(' Total messages in list: ${_messages.length}');
// If it's a SAR marker message, extract and store the marker
if (sendingMessage.isSarMarker) {
@@ -359,6 +367,7 @@ class MessagesProvider with ChangeNotifier {
_persistMessages();
notifyListeners();
print(' ✅ notifyListeners() called - UI should update');
}
/// Update message status to sent with ACK tag