mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 08:45:19 +00:00
Simplifies geonotes architecture by eliminating all background subscriptions: - Delete LocationNotesCounter.swift (104 lines) and related tests (58 lines) - Remove background subscription system entirely - Icon is now constant darker orange (indicates availability, not state) - Subscription ONLY happens when user explicitly opens the sheet - Total: ~220 lines of code removed Privacy Benefits: - Zero network traffic until user action - No location leaking to relays via background polling - User must explicitly opt-in to discover notes The icon (note.text in orange) simply indicates the feature is available when location permission is granted. Notes are only fetched when the sheet is opened, prioritizing privacy over convenience. Co-authored-by: jack <jackjackbits@users.noreply.github.com>
94 lines
3.4 KiB
Swift
94 lines
3.4 KiB
Swift
import Testing
|
|
import Foundation
|
|
@testable import bitchat
|
|
|
|
@MainActor
|
|
struct LocationNotesManagerTests {
|
|
// func testSubscribeWithoutRelaysSetsNoRelaysState() {
|
|
// var subscribeCalled = false
|
|
// let deps = LocationNotesDependencies(
|
|
// relayLookup: { _, _ in [] },
|
|
// subscribe: { _, _, _, _, _ in
|
|
// subscribeCalled = true
|
|
// },
|
|
// unsubscribe: { _ in },
|
|
// sendEvent: { _, _ in },
|
|
// deriveIdentity: { _ in fatalError("should not derive identity") },
|
|
// now: { Date() }
|
|
// )
|
|
//
|
|
// let manager = LocationNotesManager(geohash: "u4pruydq", dependencies: deps)
|
|
//
|
|
// XCTAssertFalse(subscribeCalled)
|
|
// XCTAssertEqual(manager.state, .noRelays)
|
|
// XCTAssertTrue(manager.initialLoadComplete)
|
|
// XCTAssertEqual(manager.errorMessage, String(localized: "location_notes.error.no_relays"))
|
|
// // Make sure we're getting an actual translated value and not the localization key
|
|
// XCTAssertNotEqual(manager.errorMessage, "location_notes.error.no_relays")
|
|
// }
|
|
//
|
|
// func testSendWhenNoRelaysSurfacesError() {
|
|
// var sendCalled = false
|
|
// let deps = LocationNotesDependencies(
|
|
// relayLookup: { _, _ in [] },
|
|
// subscribe: { _, _, _, _, _ in },
|
|
// unsubscribe: { _ in },
|
|
// sendEvent: { _, _ in sendCalled = true },
|
|
// deriveIdentity: { _ in throw TestError.shouldNotDerive },
|
|
// now: { Date() }
|
|
// )
|
|
//
|
|
// let manager = LocationNotesManager(geohash: "zzzzzzzz", dependencies: deps)
|
|
// manager.send(content: "hello", nickname: "tester")
|
|
//
|
|
// XCTAssertFalse(sendCalled)
|
|
// XCTAssertEqual(manager.state, .noRelays)
|
|
// XCTAssertEqual(manager.errorMessage, String(localized: "location_notes.error.no_relays"))
|
|
// // Make sure we're getting an actual translated value and not the localization key
|
|
// XCTAssertNotEqual(manager.errorMessage, "location_notes.error.no_relays")
|
|
// }
|
|
|
|
@Test func subscribeUsesGeoRelaysAndAppendsNotes() {
|
|
var relaysCaptured: [String] = []
|
|
var storedHandler: ((NostrEvent) -> Void)?
|
|
var storedEOSE: (() -> Void)?
|
|
let deps = LocationNotesDependencies(
|
|
relayLookup: { _, _ in ["wss://relay.one"] },
|
|
subscribe: { filter, id, relays, handler, eose in
|
|
#expect(filter.kinds == [1])
|
|
#expect(!id.isEmpty)
|
|
relaysCaptured = relays
|
|
storedHandler = handler
|
|
storedEOSE = eose
|
|
},
|
|
unsubscribe: { _ in },
|
|
sendEvent: { _, _ in },
|
|
deriveIdentity: { _ in throw TestError.shouldNotDerive },
|
|
now: { Date() }
|
|
)
|
|
|
|
let manager = LocationNotesManager(geohash: "u4pruydq", dependencies: deps)
|
|
#expect(relaysCaptured == ["wss://relay.one"])
|
|
#expect(manager.state == .loading)
|
|
|
|
var event = NostrEvent(
|
|
pubkey: "pub",
|
|
createdAt: Date(),
|
|
kind: .textNote,
|
|
tags: [["g", "u4pruydq"]],
|
|
content: "hi"
|
|
)
|
|
event.id = "event1"
|
|
storedHandler?(event)
|
|
storedEOSE?()
|
|
|
|
#expect(manager.state == .ready)
|
|
#expect(manager.notes.count == 1)
|
|
#expect(manager.notes.first?.content == "hi")
|
|
}
|
|
|
|
private enum TestError: Error {
|
|
case shouldNotDerive
|
|
}
|
|
}
|