Files
bitchat/bitchatTests/ChatUnreadStateResolverTests.swift
T
heyaim 1f785a699f Prevent private chats with same-name peers from merging (#1736)
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-11-25 08:06:37 -10:00

70 lines
1.8 KiB
Swift

import BitFoundation
import Foundation
import Testing
@testable import bitchat
struct ChatUnreadStateResolverTests {
@Test
func directUnreadPeerReturnsTrue() {
let peerID = PeerID(str: "peer-a")
let context = ChatUnreadPeerContext(
peerID: peerID,
noiseKeyPeerID: nil,
nostrPeerID: nil
)
#expect(ChatUnreadStateResolver.hasUnreadMessages(
for: context,
unreadPrivateMessages: [peerID]
))
}
@Test
func stableNoiseKeyUnreadReturnsTrue() {
let peerID = PeerID(str: "ephemeral")
let stableID = PeerID(str: "stable")
let context = ChatUnreadPeerContext(
peerID: peerID,
noiseKeyPeerID: stableID,
nostrPeerID: nil
)
#expect(ChatUnreadStateResolver.hasUnreadMessages(
for: context,
unreadPrivateMessages: [stableID]
))
}
@Test
func nostrConversationUnreadReturnsTrue() {
let peerID = PeerID(str: "ephemeral")
let nostrID = PeerID(nostr_: "abcdef")
let context = ChatUnreadPeerContext(
peerID: peerID,
noiseKeyPeerID: nil,
nostrPeerID: nostrID
)
#expect(ChatUnreadStateResolver.hasUnreadMessages(
for: context,
unreadPrivateMessages: [nostrID]
))
}
@Test
func unrelatedUnreadConversationReturnsFalse() {
let peerID = PeerID(str: "mesh-peer")
let geoDM = PeerID(nostr_: "0123456789abcdef")
let context = ChatUnreadPeerContext(
peerID: peerID,
noiseKeyPeerID: nil,
nostrPeerID: nil
)
#expect(!ChatUnreadStateResolver.hasUnreadMessages(
for: context,
unreadPrivateMessages: [geoDM]
))
}
}