Fix read receipts for existing messages when opening chat

- Added delay to ensure messages are loaded before checking
- Fixed logic to check if message is FROM the other person (not TO them)
- Added onAppear handler to send read receipts when view loads
- Added detailed logging to debug the flow
- Now correctly identifies received messages that need read receipts
This commit is contained in:
jack
2025-07-06 22:42:08 +02:00
parent fbe779e684
commit e93d02afd0
2 changed files with 24 additions and 6 deletions
+12 -1
View File
@@ -531,7 +531,18 @@ struct ContentView: View {
.onChange(of: viewModel.selectedPrivateChatPeer) { newPeerID in
// When switching to a private chat, send read receipts
if let peerID = newPeerID {
viewModel.markPrivateMessagesAsRead(from: peerID)
// Small delay to ensure messages are loaded
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
viewModel.markPrivateMessagesAsRead(from: peerID)
}
}
}
.onAppear {
// Also check when view appears
if let peerID = viewModel.selectedPrivateChatPeer {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
viewModel.markPrivateMessagesAsRead(from: peerID)
}
}
}
}