bitchat/bitchat/ViewModels/ChatUnreadStateResolver.swift
heyaim 215ba06859 Prevent private chats with same-name peers from merging
Nickname matching could put one peer's messages in another peer's
private chat on DM arrival or chat opening. A reply or explicit Resend
could then target the wrong peer. GeoDM Block could also block a
matching mesh peer while leaving the sender unblocked.

Remove both history rules and the unread-name fallback. Keep fingerprint
and known-key joins. Join courier full-key and derived short-ID history,
preserving mesh sender IDs and recognizing the aliases for receipts.
Resolve geohash Block by the sender's mapped key; stop if it is missing.
Correct the fingerprint-test fixture to resolve through the transport.

Restoring the removed rules fails their regressions. App, package and
simulator tests, performance checks, SwiftLint, unsigned iOS simulator
and macOS Release builds, and macOS Periphery pass. iOS Periphery
matches the local baseline. No hardware run; receipts tested to
transport handoff.
2026-09-28 13:01:22 -05:00

33 lines
745 B
Swift

import BitFoundation
import Foundation
struct ChatUnreadPeerContext {
let peerID: PeerID
let noiseKeyPeerID: PeerID?
let nostrPeerID: PeerID?
}
enum ChatUnreadStateResolver {
static func hasUnreadMessages(
for context: ChatUnreadPeerContext,
unreadPrivateMessages: Set<PeerID>
) -> Bool {
if unreadPrivateMessages.contains(context.peerID) {
return true
}
if let noiseKeyPeerID = context.noiseKeyPeerID,
unreadPrivateMessages.contains(noiseKeyPeerID) {
return true
}
if let nostrPeerID = context.nostrPeerID,
unreadPrivateMessages.contains(nostrPeerID) {
return true
}
return false
}
}