mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 02:05:19 +00:00
- Complete implementation guide - Test checklist with expected logs - Explanation of how ephemeral peer IDs are handled - Visual indicator reference
2.6 KiB
2.6 KiB
Delivery Confirmation - Complete Implementation
The Journey
We implemented a full delivery confirmation system with read receipts. The feature went through several iterations to handle edge cases and the ephemeral nature of peer IDs.
Key Challenges Solved
1. Deadlock Issues
- Problem: Nested lock acquisition causing macOS app to freeze
- Solution: Restructured DeliveryTracker to release locks before calling methods that acquire the same lock
2. Message ID Preservation
- Problem: ACKs referenced wrong message IDs
- Solution: Fixed BinaryProtocol to properly preserve message IDs during decoding
3. Race Condition with Status Updates
- Problem: Read receipts would briefly show blue checkmarks, then revert to green when ACK arrived
- Solution: Added logic to prevent downgrading from 'read' to 'delivered' status
4. Ephemeral Peer IDs
- Problem: Peer IDs change between sessions, breaking read receipts for existing messages
- Solution:
- Match messages by sender nickname in addition to peer ID
- Send read receipts to the CURRENT peer ID, not the old one from the message
- Removed requirement for senderPeerID to exist
How It Works Now
Sending a Message
- Alice sends message to Bob
- Message shows gray circle (○) - "sending"
- Message is transmitted and shows gray checkmark (✓) - "sent"
- Bob receives and sends ACK
- Alice sees green double checkmarks (✓✓) - "delivered"
Reading Messages
- When Bob opens/views the chat with Alice
- System checks all messages from Alice with "delivered" status
- Sends read receipts for those messages
- Alice sees blue double checkmarks (✓✓) - "read"
Key Code Components
DeliveryTracker.swift- Manages delivery confirmations and timeoutsBitchatProtocol.swift- Defines delivery status enum and ACK/receipt structuresBluetoothMeshService.swift- Handles sending/receiving ACKs and receiptsChatViewModel.swift- Updates UI and manages read receipt logicContentView.swift- Displays delivery status indicators
Visual Indicators
- ○ Gray circle = Sending
- ✓ Gray single check = Sent
- ✓✓ Green double checks = Delivered
- ✓✓ Blue double checks (bold) = Read
- ⚠ Red triangle = Failed
Privacy Features
- All ACKs and read receipts are end-to-end encrypted
- Only the original sender can decrypt delivery confirmations
- No message content is included in confirmations
Testing the Feature
- Send a message between two devices
- Watch status progression on sender's device
- Open chat on receiver's device
- Sender should see blue checkmarks
- Works even if receiver was offline when message was sent