mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 22:45:19 +00:00
* Friend-courier store-and-forward: mutual favorites carry sealed messages to offline peers When a private message has no reachable transport, the router now seals it to the recipient's Noise static key (new one-way Noise X pattern) and hands the envelope to up to three connected mutual favorites. Couriers store the opaque ciphertext under strict quotas (20 total, 5 per depositor, 16 KiB, 24 h) and hand it over when the recipient's announce matches a rotating HMAC recipient tag; the recipient opens it and the message flows through the normal private-message pipeline, so dedup and delivery acks just work. - CourierEnvelope TLV + courierEnvelope (0x04) message type in BitFoundation - Noise X one-way pattern reusing the existing handshake machinery, domain-separated by a courier prologue; sender identity authenticated via the ss DH (no forward secrecy - documented tradeoff) - CourierStore with eviction, file persistence, and panic-wipe integration - Rotating recipient tags (HMAC over epoch day) so carried envelopes don't correlate for observers who don't already know the recipient's key - New "carried" delivery status with figure.walk glyph; header indicator while carrying mail for others - Three-node end-to-end test ferrying packets through real BLEService instances, plus codec/crypto/store/router suites (986 tests green) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Fix courier handoff verification and directed sends * Authenticate courier deposits by ingress peer * Gate courier handover on direct announces and isolate store test Envelopes are removed from the courier store optimistically, so releasing them on a relayed (multi-hop) announce risks losing carried mail to a speculative flood that never reaches the recipient. Handover now also requires the announce to have arrived directly (full TTL), i.e. an actual encounter with a live link; regression test builds a relayed copy of a genuinely signed announce (TTL is excluded from announce signatures). Also make CourierStore's on-disk location injectable so the persistence test round-trips through a temp directory instead of wiping the real Application Support store, and reattach BLEAnnounceHandler's doc comment to the class it describes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Use Xcode-bundled Swift in CI instead of a standalone toolchain The unpinned setup-swift action installs Swift 6.1, which refuses the SDK on runner images that have rolled to Xcode 26.5 ("this SDK is not supported by the compiler"). Jobs passed or failed depending on which image they landed on. The Xcode-bundled toolchain always matches the image's SDK, and matches local development. Cache keys now include the toolchain version so artifacts from one compiler are never restored into builds with another. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Drop couriered mail from blocked senders at envelope open The UI-layer block check (isPeerBlocked in the transport event coordinator) resolves a fingerprint from the live session or peer list, but a couriered message arrives precisely when its sender is absent — no session, no registry entry — so the check failed open and a blocked identity's mail was delivered anyway. Gate in openCourierEnvelope, where the sealed sender's full static key is in hand. End-to-end test ferries a full deposit→carry→handover round and verifies the envelope from a blocked sender never reaches the delegate (confirmed failing without the gate). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Fix favorites end-to-end: peer-list dedup, Nostr sync, /fav key corruption - UnifiedPeerService: dedup offline favorites against mesh peers by noise key. Phase 2 compared a 64-hex noise-key PeerID against 16-hex mesh IDs (never equal), leaving only a nickname+isConnected heuristic — a mutual favorite that was reachable-but-not-connected or renamed rendered twice, and a same-nick stranger could suppress a favorite entirely. - Nostr inbound: intercept [FAVORITED]/[UNFAVORITED] markers in the live PM handler so they update theyFavoritedUs instead of rendering as chat text; mutual favorites can now form over Nostr. Delete the dead favorite-aware PM variant and ChatNostrCoordinator.handleFavoriteNotification (unwired, parsed a stale FAVORITE:TRUE|… format no sender emits). - NostrTransport.isPeerReachable: match short form regardless of incoming ID width — toggling an offline favorite (addressed by 64-hex noise key) was silently dropped with no reachable transport. - BLEService.sendPrivateMessage: normalize recipient to the short ID like sendFilePrivate, so a 64-hex target hits the existing Noise session instead of initiating a handshake with a 32-byte wire recipient ID. - /fav, /unfav: stop writing Data(hexString: peerID.id) — the 8-byte routing ID for mesh peers — into the favorites store as a "noise key", and stop double-sending the favorite notification; delegate to toggleFavorite with a proper state check. - FavoritesPersistenceService.updatePeerFavoritedUs: keep the stored nickname when the caller passes the "Unknown" placeholder. - Bump marketing version to 1.5.4. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Route DMs to mutual favorites via Nostr when a mesh-keyed peer goes offline Field-tested on device: with a DM window opened while the peer was on mesh (conversation keyed by the short 16-hex ID), walking out of range and sending failed instantly with "peer not reachable" even though the header showed the peer as Nostr-reachable (mutual favorite, npub known). sendPrivateMessage derived the favorites key as Data(hexString: peerID.id) — for a short mesh ID that is the 8-byte routing ID, never the noise key — so the mutual-favorite/Nostr-key checks always came up empty and the send failed before reaching MessageRouter. Conversations keyed by the full 64-hex noise-key ID (opened from the offline favorite row) were unaffected, which is why later tests appeared to work. Resolve the noise key properly (peerID.noiseKey, then the unified peer row, then the favorites store by derived short ID) and add a regression test for the mesh-keyed-peer-goes-offline case. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Label Nostr DMs from favorites with their stored nickname Field-tested: a DM delivered over the Nostr fallback rendered as "anon#678e" instead of the sender's name. The inbound handler named the sender via displayNameForNostrPubkey, which only knows geohash-scoped names — even though the pipeline had already resolved the sender's noise key (the conversation is keyed by it). When the conversation key carries a noise key, prefer the favorite's stored nickname; geohash DMs (nostr_ keys) keep the anon geo name. This also stops an inbound Nostr [FAVORITED] from overwriting the stored nickname with the anon fallback, since the same name feeds updatePeerFavoritedUs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Fix courier path for offline favorites addressed by noise-key IDs Two Codex review findings, both the same ID-width confusion this PR targets, in the courier flow: - CourierDirectory.favoritesBacked resolved recipients only via getFavoriteStatus(forPeerID:), which requires a short 16-hex ID — offline favorites are addressed by the full 64-hex noise-key ID, so attemptCourierDeposit silently bailed for exactly the peers couriers exist to serve. The 64-hex ID now yields its own key directly. - openCourierEnvelope emitted the derived short mesh ID even when the sender has no live mesh identity, landing couriered mail in an unresolvable short-ID thread labeled "Unknown". Absent senders now emit the full noise-key ID so the message joins the stable favorite conversation; present senders keep the live short-ID thread. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
496 lines
19 KiB
Swift
496 lines
19 KiB
Swift
import Foundation
|
|
import Testing
|
|
import BitFoundation
|
|
@testable import bitchat
|
|
|
|
@Suite(.serialized)
|
|
struct CommandProcessorTests {
|
|
|
|
@MainActor
|
|
@Test func slapNotFoundGrammar() {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let processor = CommandProcessor(contextProvider: nil, meshService: nil, identityManager: identityManager)
|
|
let result = processor.process("/slap @system")
|
|
switch result {
|
|
case .error(let message):
|
|
#expect(message == "cannot slap system: not found")
|
|
default:
|
|
Issue.record("Expected error result")
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
@Test func hugNotFoundGrammar() {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let processor = CommandProcessor(contextProvider: nil, meshService: nil, identityManager: identityManager)
|
|
let result = processor.process("/hug @system")
|
|
switch result {
|
|
case .error(let message):
|
|
#expect(message == "cannot hug system: not found")
|
|
default:
|
|
Issue.record("Expected error result")
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
@Test func slapUsageMessage() {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let processor = CommandProcessor(contextProvider: nil, meshService: nil, identityManager: identityManager)
|
|
let result = processor.process("/slap")
|
|
switch result {
|
|
case .error(let message):
|
|
#expect(message == "usage: /slap <nickname>")
|
|
default:
|
|
Issue.record("Expected error result for usage message")
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
@Test func msgStartsPrivateChatAndSendsMessage() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider()
|
|
let peerID = PeerID(str: "abcd1234abcd1234")
|
|
context.nicknameToPeerID["alice"] = peerID
|
|
let processor = CommandProcessor(contextProvider: context, meshService: nil, identityManager: identityManager)
|
|
|
|
let result = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/msg @alice hello there")
|
|
}
|
|
|
|
switch result {
|
|
case .success(let message):
|
|
#expect(message == "started private chat with alice")
|
|
default:
|
|
Issue.record("Expected success result")
|
|
}
|
|
#expect(context.startedPrivateChats == [peerID])
|
|
#expect(context.sentPrivateMessages.count == 1)
|
|
#expect(context.sentPrivateMessages.first?.content == "hello there")
|
|
#expect(context.sentPrivateMessages.first?.peerID == peerID)
|
|
}
|
|
|
|
@MainActor
|
|
@Test func whoInMeshListsSortedPeerNicknames() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider()
|
|
let transport = MockTransport()
|
|
transport.peerNicknames = [
|
|
PeerID(str: "b"): "bob",
|
|
PeerID(str: "a"): "alice"
|
|
]
|
|
let processor = CommandProcessor(contextProvider: context, meshService: transport, identityManager: identityManager)
|
|
|
|
let result = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/who")
|
|
}
|
|
|
|
switch result {
|
|
case .success(let message):
|
|
#expect(message == "online: alice, bob")
|
|
default:
|
|
Issue.record("Expected success result")
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
@Test func whoInGeohashListsVisibleParticipantsExcludingSelf() async throws {
|
|
let bridge = NostrIdentityBridge(keychain: MockKeychain())
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider(idBridge: bridge)
|
|
let geohash = "u4pruy"
|
|
let selfPubkey = try bridge.deriveIdentity(forGeohash: geohash).publicKeyHex.lowercased()
|
|
context.visibleGeoParticipants = [
|
|
CommandGeoParticipant(id: selfPubkey, displayName: "me"),
|
|
CommandGeoParticipant(id: String(repeating: "b", count: 64), displayName: "bob")
|
|
]
|
|
let processor = CommandProcessor(contextProvider: context, meshService: MockTransport(), identityManager: identityManager)
|
|
let channel = ChannelID.location(GeohashChannel(level: .city, geohash: geohash))
|
|
|
|
let result = await withSelectedChannel(channel, context: context) {
|
|
processor.process("/who")
|
|
}
|
|
|
|
switch result {
|
|
case .success(let message):
|
|
#expect(message == "online: bob")
|
|
default:
|
|
Issue.record("Expected success result")
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
@Test func clearInPrivateChatRemovesOnlySelectedConversation() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider()
|
|
let activePeer = PeerID(str: "active")
|
|
let otherPeer = PeerID(str: "other")
|
|
context.selectedPrivateChatPeer = activePeer
|
|
context.privateChats = [
|
|
activePeer: [makeMessage(sender: "alice", content: "secret")],
|
|
otherPeer: [makeMessage(sender: "bob", content: "keep")]
|
|
]
|
|
let processor = CommandProcessor(contextProvider: context, meshService: nil, identityManager: identityManager)
|
|
|
|
let result = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/clear")
|
|
}
|
|
|
|
switch result {
|
|
case .handled:
|
|
break
|
|
default:
|
|
Issue.record("Expected handled result")
|
|
}
|
|
#expect(context.privateChats[activePeer] == [])
|
|
#expect(context.privateChats[otherPeer]?.count == 1)
|
|
}
|
|
|
|
@MainActor
|
|
@Test func clearInPublicChatClearsTimeline() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider()
|
|
let processor = CommandProcessor(contextProvider: context, meshService: nil, identityManager: identityManager)
|
|
|
|
let result = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/clear")
|
|
}
|
|
|
|
switch result {
|
|
case .handled:
|
|
break
|
|
default:
|
|
Issue.record("Expected handled result")
|
|
}
|
|
#expect(context.clearCurrentPublicTimelineCallCount == 1)
|
|
}
|
|
|
|
@MainActor
|
|
@Test func hugInPrivateChatSendsPersonalizedMessageAndLocalEcho() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider(nickname: "me")
|
|
let transport = MockTransport()
|
|
let peerID = PeerID(str: "abcd1234abcd1234")
|
|
context.selectedPrivateChatPeer = peerID
|
|
context.nicknameToPeerID["bob"] = peerID
|
|
transport.peerNicknames[peerID] = "Bob"
|
|
let processor = CommandProcessor(contextProvider: context, meshService: transport, identityManager: identityManager)
|
|
|
|
let result = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/hug @bob")
|
|
}
|
|
|
|
switch result {
|
|
case .handled:
|
|
break
|
|
default:
|
|
Issue.record("Expected handled result")
|
|
}
|
|
#expect(transport.sentPrivateMessages.count == 1)
|
|
#expect(transport.sentPrivateMessages.first?.content == "* 🫂 me hugs you *")
|
|
#expect(context.localPrivateSystemMessages.first?.content == "🫂 you hugged bob")
|
|
#expect(context.localPrivateSystemMessages.first?.peerID == peerID)
|
|
}
|
|
|
|
@MainActor
|
|
@Test func slapInPublicChatSendsPublicRawAndEcho() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider(nickname: "me")
|
|
let peerID = PeerID(str: "abcd1234abcd1234")
|
|
context.nicknameToPeerID["bob"] = peerID
|
|
let processor = CommandProcessor(contextProvider: context, meshService: MockTransport(), identityManager: identityManager)
|
|
|
|
let result = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/slap @bob")
|
|
}
|
|
|
|
switch result {
|
|
case .handled:
|
|
break
|
|
default:
|
|
Issue.record("Expected handled result")
|
|
}
|
|
#expect(context.sentPublicRawMessages == ["* 🐟 me slaps bob around a bit with a large trout *"])
|
|
#expect(context.publicSystemMessages == ["🐟 me slaps bob around a bit with a large trout"])
|
|
}
|
|
|
|
@MainActor
|
|
@Test func blockWithoutArgsListsMeshAndGeohashBlocks() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider()
|
|
let transport = MockTransport()
|
|
let peerID = PeerID(str: "abcd1234abcd1234")
|
|
transport.peerNicknames[peerID] = "bob"
|
|
transport.peerFingerprints[peerID] = "fp-bob"
|
|
context.blockedUsers = ["fp-bob"]
|
|
context.visibleGeoParticipants = [
|
|
CommandGeoParticipant(id: String(repeating: "c", count: 64), displayName: "carol")
|
|
]
|
|
identityManager.setNostrBlocked(String(repeating: "c", count: 64), isBlocked: true)
|
|
let processor = CommandProcessor(contextProvider: context, meshService: transport, identityManager: identityManager)
|
|
|
|
let result = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/block")
|
|
}
|
|
|
|
switch result {
|
|
case .success(let message):
|
|
#expect(message == "blocked peers: bob | geohash blocks: carol")
|
|
default:
|
|
Issue.record("Expected success result")
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
@Test func blockAndUnblockMeshPeerUpdateIdentityState() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider()
|
|
let transport = MockTransport()
|
|
let peerID = PeerID(str: "abcd1234abcd1234")
|
|
transport.peerFingerprints[peerID] = "fp-bob"
|
|
context.nicknameToPeerID["bob"] = peerID
|
|
let processor = CommandProcessor(contextProvider: context, meshService: transport, identityManager: identityManager)
|
|
|
|
let blockResult = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/block @bob")
|
|
}
|
|
switch blockResult {
|
|
case .success(let message):
|
|
#expect(message == "blocked bob. you will no longer receive messages from them")
|
|
default:
|
|
Issue.record("Expected success result")
|
|
}
|
|
#expect(identityManager.isBlocked(fingerprint: "fp-bob"))
|
|
|
|
let unblockResult = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/unblock bob")
|
|
}
|
|
switch unblockResult {
|
|
case .success(let message):
|
|
#expect(message == "unblocked bob")
|
|
default:
|
|
Issue.record("Expected success result")
|
|
}
|
|
#expect(!identityManager.isBlocked(fingerprint: "fp-bob"))
|
|
}
|
|
|
|
@MainActor
|
|
@Test func blockAndUnblockGeohashPeerUseNostrBlockList() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider()
|
|
context.displayNameToNostrPubkey["carol"] = String(repeating: "d", count: 64)
|
|
let processor = CommandProcessor(contextProvider: context, meshService: MockTransport(), identityManager: identityManager)
|
|
|
|
let blockResult = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/block carol")
|
|
}
|
|
switch blockResult {
|
|
case .success(let message):
|
|
#expect(message == "blocked carol in geohash chats")
|
|
default:
|
|
Issue.record("Expected success result")
|
|
}
|
|
#expect(identityManager.isNostrBlocked(pubkeyHexLowercased: String(repeating: "d", count: 64)))
|
|
|
|
let unblockResult = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/unblock @carol")
|
|
}
|
|
switch unblockResult {
|
|
case .success(let message):
|
|
#expect(message == "unblocked carol in geohash chats")
|
|
default:
|
|
Issue.record("Expected success result")
|
|
}
|
|
#expect(!identityManager.isNostrBlocked(pubkeyHexLowercased: String(repeating: "d", count: 64)))
|
|
}
|
|
|
|
/// /fav must go through toggleFavorite (which persists by the real noise
|
|
/// key) — not write the hex peer ID into the favorites store, and not
|
|
/// send a second favorite notification.
|
|
@MainActor
|
|
@Test func favoriteCommandTogglesWithoutDirectStoreWrite() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider()
|
|
let processor = CommandProcessor(
|
|
contextProvider: context,
|
|
meshService: MockTransport(),
|
|
identityManager: identityManager
|
|
)
|
|
let peerID = PeerID(str: "00aa00bb00cc00dd")
|
|
context.nicknameToPeerID["alice"] = peerID
|
|
|
|
let result = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/fav alice")
|
|
}
|
|
|
|
switch result {
|
|
case .success(let message):
|
|
#expect(message == "added alice to favorites")
|
|
default:
|
|
Issue.record("Expected success result")
|
|
}
|
|
#expect(context.toggledFavorites == [peerID])
|
|
#expect(context.favoriteNotifications.isEmpty)
|
|
// The 8-byte routing ID must never be stored as a "noise key".
|
|
let bogusKey = Data(hexString: peerID.id)!
|
|
#expect(FavoritesPersistenceService.shared.getFavoriteStatus(for: bogusKey) == nil)
|
|
|
|
// Unfavoriting someone who is not a favorite is a no-op.
|
|
let unfavResult = await withSelectedChannel(.mesh, context: context) {
|
|
processor.process("/unfav alice")
|
|
}
|
|
switch unfavResult {
|
|
case .success(let message):
|
|
#expect(message == "alice is not a favorite")
|
|
default:
|
|
Issue.record("Expected success result")
|
|
}
|
|
#expect(context.toggledFavorites == [peerID])
|
|
}
|
|
|
|
@MainActor
|
|
@Test func favoriteCommandIsRejectedOutsideMesh() async {
|
|
let identityManager = MockIdentityManager(MockKeychain())
|
|
let context = MockCommandContextProvider()
|
|
let processor = CommandProcessor(
|
|
contextProvider: context,
|
|
meshService: MockTransport(),
|
|
identityManager: identityManager
|
|
)
|
|
let channel = ChannelID.location(GeohashChannel(level: .city, geohash: "u4pruy"))
|
|
|
|
let result = await withSelectedChannel(channel, context: context) {
|
|
processor.process("/fav alice")
|
|
}
|
|
|
|
switch result {
|
|
case .error(let message):
|
|
#expect(message == "favorites are only for mesh peers in #mesh")
|
|
default:
|
|
Issue.record("Expected error result")
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
private func withSelectedChannel<T>(
|
|
_ channel: ChannelID,
|
|
context: MockCommandContextProvider? = nil,
|
|
perform work: @escaping () throws -> T
|
|
) async rethrows -> T {
|
|
let originalChannel = LocationChannelManager.shared.selectedChannel
|
|
let originalContextChannel = context?.activeChannel
|
|
await setSelectedChannel(channel, context: context)
|
|
do {
|
|
let result = try work()
|
|
await setSelectedChannel(originalChannel, context: context, explicitChannel: originalContextChannel)
|
|
return result
|
|
} catch {
|
|
await setSelectedChannel(originalChannel, context: context, explicitChannel: originalContextChannel)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
private func setSelectedChannel(
|
|
_ channel: ChannelID,
|
|
context: MockCommandContextProvider? = nil,
|
|
explicitChannel: ChannelID? = nil
|
|
) async {
|
|
context?.activeChannel = explicitChannel ?? channel
|
|
LocationChannelManager.shared.select(channel)
|
|
for _ in 0..<40 {
|
|
if LocationChannelManager.shared.selectedChannel == channel {
|
|
return
|
|
}
|
|
await Task.yield()
|
|
try? await Task.sleep(nanoseconds: 5_000_000)
|
|
}
|
|
}
|
|
|
|
private func makeMessage(sender: String, content: String) -> BitchatMessage {
|
|
BitchatMessage(
|
|
sender: sender,
|
|
content: content,
|
|
timestamp: Date(timeIntervalSince1970: 1_700_000_000),
|
|
isRelay: false
|
|
)
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
private final class MockCommandContextProvider: CommandContextProvider {
|
|
var nickname: String
|
|
var activeChannel: ChannelID = .mesh
|
|
var selectedPrivateChatPeer: PeerID?
|
|
var blockedUsers: Set<String> = []
|
|
var privateChats: [PeerID: [BitchatMessage]] = [:]
|
|
let idBridge: NostrIdentityBridge
|
|
|
|
var nicknameToPeerID: [String: PeerID] = [:]
|
|
var visibleGeoParticipants: [CommandGeoParticipant] = []
|
|
var displayNameToNostrPubkey: [String: String] = [:]
|
|
|
|
private(set) var startedPrivateChats: [PeerID] = []
|
|
private(set) var sentPrivateMessages: [(content: String, peerID: PeerID)] = []
|
|
private(set) var clearCurrentPublicTimelineCallCount = 0
|
|
private(set) var sentPublicRawMessages: [String] = []
|
|
private(set) var localPrivateSystemMessages: [(content: String, peerID: PeerID)] = []
|
|
private(set) var publicSystemMessages: [String] = []
|
|
private(set) var toggledFavorites: [PeerID] = []
|
|
private(set) var favoriteNotifications: [(peerID: PeerID, isFavorite: Bool)] = []
|
|
|
|
init(nickname: String = "tester", idBridge: NostrIdentityBridge = NostrIdentityBridge(keychain: MockKeychain())) {
|
|
self.nickname = nickname
|
|
self.idBridge = idBridge
|
|
}
|
|
|
|
func getPeerIDForNickname(_ nickname: String) -> PeerID? {
|
|
nicknameToPeerID[nickname]
|
|
}
|
|
|
|
func getVisibleGeoParticipants() -> [CommandGeoParticipant] {
|
|
visibleGeoParticipants
|
|
}
|
|
|
|
func nostrPubkeyForDisplayName(_ displayName: String) -> String? {
|
|
displayNameToNostrPubkey[displayName]
|
|
}
|
|
|
|
func startPrivateChat(with peerID: PeerID) {
|
|
startedPrivateChats.append(peerID)
|
|
}
|
|
|
|
func sendPrivateMessage(_ content: String, to peerID: PeerID) {
|
|
sentPrivateMessages.append((content, peerID))
|
|
}
|
|
|
|
func clearCurrentPublicTimeline() {
|
|
clearCurrentPublicTimelineCallCount += 1
|
|
}
|
|
|
|
private(set) var clearedPrivateChats: [PeerID] = []
|
|
func clearPrivateChat(_ peerID: PeerID) {
|
|
clearedPrivateChats.append(peerID)
|
|
privateChats[peerID] = []
|
|
}
|
|
|
|
func sendPublicRaw(_ content: String) {
|
|
sentPublicRawMessages.append(content)
|
|
}
|
|
|
|
func addLocalPrivateSystemMessage(_ content: String, to peerID: PeerID) {
|
|
localPrivateSystemMessages.append((content, peerID))
|
|
}
|
|
|
|
func addPublicSystemMessage(_ content: String) {
|
|
publicSystemMessages.append(content)
|
|
}
|
|
|
|
func toggleFavorite(peerID: PeerID) {
|
|
toggledFavorites.append(peerID)
|
|
}
|
|
|
|
func sendFavoriteNotification(to peerID: PeerID, isFavorite: Bool) {
|
|
favoriteNotifications.append((peerID, isFavorite))
|
|
}
|
|
}
|