Fix read receipts for existing messages when opening chat

Critical fixes:
1. Match messages by sender nickname in addition to peer ID (since peer IDs change)
2. Send read receipts to CURRENT peer ID, not old senderPeerID from message
3. Remove requirement for senderPeerID to be non-nil (blocks older messages)
4. Add extensive logging to trace the flow

The core issue was that peer IDs are ephemeral and change between sessions:
- Rick sends message with peer ID A
- Later, Jack connects to Rick who now has peer ID B
- Read receipt needs to be sent to B, not A
- Messages need to be matched by nickname, not just peer ID
This commit is contained in:
jack
2025-07-06 22:55:51 +02:00
parent d892c790a7
commit 13d9be9082
3 changed files with 75 additions and 42 deletions
+37
View File
@@ -0,0 +1,37 @@
# Delivery Confirmation Feature - Current Status
## What's Working
1. ✅ Delivery confirmations (green double checkmarks) work correctly
2. ✅ Read receipts are sent and received properly
3. ✅ Blue checkmarks appear for messages that are read while both users are in the chat
4. ✅ Status updates are preserved (read status won't downgrade to delivered)
## Remaining Issue
When Jack opens a chat with Rick, the first message (that was already delivered before Jack opened the chat) doesn't get a read receipt sent. Only new messages that arrive while the chat is open get read receipts.
### Root Cause
The `markPrivateMessagesAsRead` function is being called when Jack opens the chat, but:
1. It looks for messages with status "sent" or "delivered"
2. Messages from Rick are stored with Rick's senderPeerID (which changes between sessions)
3. The peer ID mismatch might prevent finding the right messages
### Solution Needed
Jack needs to send read receipts for ALL unread messages from Rick when opening the chat, regardless of their current peer ID.
## Test Scenario
1. Rick sends message to Jack while Jack is offline/not in chat
2. Message shows green checkmarks (delivered) on Rick's side
3. Jack opens the chat with Rick
4. **Expected**: Rick's message should turn blue
5. **Actual**: Message stays green until a new message is sent
## Logs Showing the Issue
```
Mac (Rick):
- Message F4D69DB6... shows "delivered to jack" (stays green)
- Never receives read receipt for this first message
Phone (Jack):
- Opens chat but doesn't send read receipt for existing messages
- Only sends read receipts for new messages received while chat is open
```