mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 17:45:19 +00:00
Break circular dependency between CommandProcessor and ChatViewModel
Introduce CommandContextProvider protocol to define what CommandProcessor needs from its context. This follows the Dependency Inversion Principle: - Create CommandContextProvider protocol with 15 methods/properties - Create CommandGeoParticipant struct for geo participant data - Add getVisibleGeoParticipants() to ChatViewModel - ChatViewModel now conforms to CommandContextProvider - CommandProcessor depends on protocol, not concrete ChatViewModel Benefits: - Breaks the tight coupling between CommandProcessor and ChatViewModel - Makes CommandProcessor more testable (can use mock context) - Clear contract for what CommandProcessor needs - Backwards-compatible via chatViewModel property alias Also fixes a concurrency bug in BitchatApp where notification delegate was accessing main-actor-isolated property from arbitrary thread.
This commit is contained in:
@@ -92,7 +92,7 @@ import UniformTypeIdentifiers
|
||||
/// Manages the application state and business logic for BitChat.
|
||||
/// Acts as the primary coordinator between UI components and backend services,
|
||||
/// implementing the BitchatDelegate protocol to handle network events.
|
||||
final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
final class ChatViewModel: ObservableObject, BitchatDelegate, CommandContextProvider {
|
||||
// Precompiled regexes and detectors reused across formatting
|
||||
private enum Regexes {
|
||||
static let hashtag: NSRegularExpression = {
|
||||
@@ -1906,6 +1906,11 @@ final class ChatViewModel: ObservableObject, BitchatDelegate {
|
||||
.sorted { $0.lastSeen > $1.lastSeen }
|
||||
return people
|
||||
}
|
||||
|
||||
/// CommandContextProvider conformance - returns visible geo participants
|
||||
func getVisibleGeoParticipants() -> [CommandGeoParticipant] {
|
||||
visibleGeohashPeople().map { CommandGeoParticipant(id: $0.id, displayName: $0.displayName) }
|
||||
}
|
||||
/// Returns the current participant count for a specific geohash, using the 5-minute activity window.
|
||||
@MainActor
|
||||
func geohashParticipantCount(for geohash: String) -> Int {
|
||||
|
||||
Reference in New Issue
Block a user