Fix READ receipt status not updating to blue checks

- Add findMessageIndex helper to handle peer ID format mismatch
  (short 16-hex vs long 64-hex noise key)
- Prevent DELIVERED acks from downgrading .read status back to .delivered
  (fixes race condition where late-arriving delivery acks overwrote read status)
- Use incoming peerID for READ receipts instead of creating new ID from noise key
- Explicitly re-assign messages array to trigger @Published setter

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
jack
2026-01-12 18:23:56 -10:00
co-authored by Claude Opus 4.5
parent 5fcffefa28
commit beb04fc887
2 changed files with 53 additions and 19 deletions
@@ -740,15 +740,11 @@ extension ChatViewModel {
if isViewing {
// Mark read immediately if viewing
// Use router to send read receipt
// Use the incoming peerID directly - it has the established Noise session.
// Don't use PeerID(hexData: noiseKey) as that creates a 64-hex ID without a session.
// Use meshService directly (not messageRouter) so it queues if peer disconnects.
let receipt = ReadReceipt(originalMessageID: message.id, readerID: meshService.myPeerID, readerNickname: nickname)
if let key = noiseKey {
// Send via router to stable key if available (preferred for persistence/Nostr fallback)
messageRouter.sendReadReceipt(receipt, to: PeerID(hexData: key))
} else {
// Fallback to mesh direct
meshService.sendReadReceipt(receipt, to: peerID)
}
meshService.sendReadReceipt(receipt, to: peerID)
sentReadReceipts.insert(message.id)
} else {
// Notify