Remove the empty defaults on ChatTransportEventContext (#1958)

After #1949 and #1950, ChatViewModel had no copy of retryPendingReadReceiptsIfViewing. The empty default hid that, so the app built and the retry did nothing. Without defaults, a missing member fails the build. The test mock now records both calls.
This commit is contained in:
Jozef Koval authored and GitHub committed 2026-11-28 14:02:37 -10:00
1 parent 02e6c31d7a
commit abaa95b6dd
2 files changed
+19 -6

No files matched your search

@@ -9,6 +9,9 @@ import Foundation
/// to the whole `ChatViewModel`. This keeps the coordinator independently
/// testable (see `ChatTransportEventCoordinatorContextTests`) and makes its
/// true dependencies explicit.
///
/// Give no member a default body: a missing `ChatViewModel` member must
/// fail the build, not become a silent no-op.
@MainActor
protocol ChatTransportEventContext: AnyObject {
// MARK: Connection & chat state
@@ -88,11 +91,6 @@ protocol ChatTransportEventContext: AnyObject {
func handleVouchPayload(from peerID: PeerID, payload: Data)
}
extension ChatTransportEventContext {
func failOverRouterOutboxAfterMeshDisconnect(for peerIDAliases: [PeerID]) {}
func retryPendingReadReceiptsIfViewing(peerIDAliases: [PeerID]) {}
}
extension ChatViewModel: ChatTransportEventContext {
// `isConnected`, `nickname`, `myPeerID`, `privateMessages(for:)`,
// `unreadPrivateMessages`, `selectedPrivateChatPeer`, `notifyUIChanged()`,
@@ -112,10 +112,18 @@ private final class MockChatTransportEventContext: ChatTransportEventContext {
// Routing & acknowledgements
private(set) var flushedOutboxPeerIDs: [PeerID] = []
private(set) var failedOverOutboxAliases: [[PeerID]] = []
private(set) var readReceiptRetryAliases: [[PeerID]] = []
private(set) var courierRetryPeerIDs: [PeerID] = []
private(set) var meshDeliveryAcks: [(messageID: String, peerID: PeerID)] = []
func flushRouterOutbox(for peerID: PeerID) { flushedOutboxPeerIDs.append(peerID) }
func failOverRouterOutboxAfterMeshDisconnect(for peerIDAliases: [PeerID]) {
failedOverOutboxAliases.append(peerIDAliases)
}
func retryPendingReadReceiptsIfViewing(peerIDAliases: [PeerID]) {
readReceiptRetryAliases.append(peerIDAliases)
}
func retryCourierDeposits(via peerID: PeerID) { courierRetryPeerIDs.append(peerID) }
func sendMeshDeliveryAck(for messageID: String, to peerID: PeerID) {
meshDeliveryAcks.append((messageID, peerID))
@@ -321,9 +329,12 @@ struct ChatTransportEventCoordinatorContextTests {
let noiseKey = Data(repeating: 0xAB, count: 32)
context.peersByID[peerID] = BitchatPeer(peerID: peerID, noisePublicKey: noiseKey, nickname: "alice")
let stablePeerID = PeerID(hexData: noiseKey)
coordinator.didConnectToPeerSynchronously(peerID)
#expect(context.stablePeerIDCache[peerID] == PeerID(hexData: noiseKey))
#expect(context.stablePeerIDCache[peerID] == stablePeerID)
#expect(context.flushedOutboxPeerIDs == [peerID])
#expect(context.readReceiptRetryAliases == [[peerID, stablePeerID]])
// Their messages' read receipts are un-marked on disconnect so READ
// acks can be re-sent after reconnect; our own messages are not.
@@ -334,6 +345,7 @@ struct ChatTransportEventCoordinatorContextTests {
]
coordinator.didDisconnectFromPeerSynchronously(peerID)
#expect(context.unmarkedReadReceiptBatches == [["theirs-1", "theirs-2"]])
#expect(context.failedOverOutboxAliases == [[peerID, stablePeerID]])
}
@Test @MainActor
@@ -352,10 +364,13 @@ struct ChatTransportEventCoordinatorContextTests {
#expect(context.flushedOutboxPeerIDs == [peerID])
#expect(context.courierRetryPeerIDs == [peerID])
// An unknown peer has no stable ID, so its short ID is the only alias.
#expect(context.readReceiptRetryAliases == [[peerID]])
coordinator.didDisconnectFromPeerSynchronously(peerID)
#expect(context.unmarkedReadReceiptBatches == [[incoming.id]])
#expect(context.failedOverOutboxAliases == [[peerID]])
}
@Test @MainActor