Files
bitchat/DELIVERY_CONFIRMATION_SUMMARY.md
T
jack d162a89ac2 Add debugging and fix read receipts for messages without delivery status
- Add detailed logging to track read receipt generation
- Handle messages that don't have delivery status (older messages)
- Send read receipts for all unread messages when opening chat
2025-07-06 22:14:41 +02:00

2.5 KiB

Delivery Confirmation Feature Summary

Overview

This branch implements a complete delivery confirmation system for bitchat, providing visual feedback for message delivery status and read receipts.

Key Components Implemented

1. Delivery Status Tracking

  • DeliveryTracker.swift: Core service managing delivery confirmations
    • Tracks pending deliveries with timeouts (30s for private, 60s for rooms)
    • Handles retries for favorite peers (up to 3 attempts)
    • Thread-safe implementation with proper lock management

2. Protocol Updates

  • BitchatProtocol.swift:
    • Added DeliveryStatus enum with states: sending, sent, delivered, read, failed
    • Added DeliveryAck structure for acknowledgments
    • Added ReadReceipt structure for read confirmations
    • New message types: .deliveryAck and .readReceipt

3. UI Implementation

  • ContentView.swift:
    • Added DeliveryStatusView component showing:
      • Gray circle (○) for sending
      • Gray checkmark (✓) for sent
      • Green double checkmarks (✓✓) for delivered
      • Blue double checkmarks (✓✓) for read
      • Red triangle (⚠) for failed
    • Proper vertical alignment with message text

4. Message Flow

  • BluetoothMeshService.swift:
    • Added ACK generation and sending
    • Added read receipt generation when viewing chats
    • Encrypted ACKs for privacy
    • Proper message ID handling

5. Critical Bug Fixes

Deadlock Fix

  • Issue: macOS app freeze when sending private messages
  • Cause: Nested lock acquisition in DeliveryTracker
  • Fix: Restructured code to release locks before calling methods that acquire the same lock

Message ID Preservation

  • Issue: ACKs referenced wrong message IDs
  • Cause: BinaryProtocol was reading but discarding ID with let _ =
  • Fix: Changed to let id = and passed ID to BitchatMessage constructor

Technical Details

Privacy Considerations

  • ACKs and read receipts are encrypted end-to-end
  • Only the original sender can decrypt and process them
  • No message content is included in confirmations

Performance

  • Debounced UI updates (100ms)
  • Efficient lock usage to prevent deadlocks
  • Automatic cleanup of old delivery data

Error Handling

  • Graceful timeout handling
  • Retry logic for favorites
  • Clear failure messages

Testing

See test_delivery_confirmation.md for comprehensive test plan.

Future Enhancements

  • Group read receipts (show who read in rooms)
  • Delivery timestamps in UI
  • Persistent delivery status across app restarts
  • Network quality indicators