mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 04:25:21 +00:00
- Complete implementation guide - Test checklist with expected logs - Explanation of how ephemeral peer IDs are handled - Visual indicator reference
66 lines
2.6 KiB
Markdown
66 lines
2.6 KiB
Markdown
# 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
|
|
1. Alice sends message to Bob
|
|
2. Message shows gray circle (○) - "sending"
|
|
3. Message is transmitted and shows gray checkmark (✓) - "sent"
|
|
4. Bob receives and sends ACK
|
|
5. Alice sees green double checkmarks (✓✓) - "delivered"
|
|
|
|
### Reading Messages
|
|
1. When Bob opens/views the chat with Alice
|
|
2. System checks all messages from Alice with "delivered" status
|
|
3. Sends read receipts for those messages
|
|
4. Alice sees blue double checkmarks (✓✓) - "read"
|
|
|
|
### Key Code Components
|
|
- `DeliveryTracker.swift` - Manages delivery confirmations and timeouts
|
|
- `BitchatProtocol.swift` - Defines delivery status enum and ACK/receipt structures
|
|
- `BluetoothMeshService.swift` - Handles sending/receiving ACKs and receipts
|
|
- `ChatViewModel.swift` - Updates UI and manages read receipt logic
|
|
- `ContentView.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
|
|
1. Send a message between two devices
|
|
2. Watch status progression on sender's device
|
|
3. Open chat on receiver's device
|
|
4. Sender should see blue checkmarks
|
|
5. Works even if receiver was offline when message was sent |