mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 20:05:19 +00:00
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:
@@ -531,8 +531,10 @@ struct ContentView: View {
|
||||
.onChange(of: viewModel.selectedPrivateChatPeer) { newPeerID in
|
||||
// When switching to a private chat, send read receipts
|
||||
if let peerID = newPeerID {
|
||||
print("[UI] Selected private chat peer changed to \(peerID)")
|
||||
// Small delay to ensure messages are loaded
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
print("[UI] Triggering markPrivateMessagesAsRead for peer \(peerID)")
|
||||
viewModel.markPrivateMessagesAsRead(from: peerID)
|
||||
}
|
||||
}
|
||||
@@ -540,7 +542,9 @@ struct ContentView: View {
|
||||
.onAppear {
|
||||
// Also check when view appears
|
||||
if let peerID = viewModel.selectedPrivateChatPeer {
|
||||
print("[UI] Messages view appeared with selected peer \(peerID)")
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
print("[UI] Triggering markPrivateMessagesAsRead on appear for peer \(peerID)")
|
||||
viewModel.markPrivateMessagesAsRead(from: peerID)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user