diff --git a/app/src/main/java/com/bitchat/android/nostr/LocationNotesManager.kt b/app/src/main/java/com/bitchat/android/nostr/LocationNotesManager.kt index fe4f964a..1b6042e5 100644 --- a/app/src/main/java/com/bitchat/android/nostr/LocationNotesManager.kt +++ b/app/src/main/java/com/bitchat/android/nostr/LocationNotesManager.kt @@ -286,30 +286,10 @@ class LocationNotesManager private constructor() { val subscribe = subscribeFunc if (subscribe == null) { Log.e(TAG, "Cannot subscribe - subscribe function not initialized") - _state.value = State.NO_RELAYS + _state.value = State.LOADING return } - - // CRITICAL FIX: Get geo-specific relays for this geohash (matching iOS pattern) - // iOS: let relays = dependencies.relayLookup(geohash, TransportConfig.nostrGeoRelayCount) - val relays = try { - com.bitchat.android.nostr.RelayDirectory.closestRelaysForGeohash(currentGeohash, 5) - } catch (e: Exception) { - Log.e(TAG, "Failed to lookup relays for geohash $currentGeohash: ${e.message}") - emptyList() - } - - // Check if we have any relays (iOS pattern: guard !relays.isEmpty()) - if (relays.isEmpty()) { - Log.w(TAG, "No geo relays available for geohash: $currentGeohash") - _state.value = State.NO_RELAYS - _initialLoadComplete.value = true - _errorMessage.value = "No relays available" - return - } - - Log.d(TAG, "📡 Found ${relays.size} geo relays for geohash $currentGeohash: ${relays.joinToString()}") - + _state.value = State.LOADING val filter = NostrFilter.geohashNotes( diff --git a/app/src/main/java/com/bitchat/android/ui/ChatViewModel.kt b/app/src/main/java/com/bitchat/android/ui/ChatViewModel.kt index a670aa20..b0661c56 100644 --- a/app/src/main/java/com/bitchat/android/ui/ChatViewModel.kt +++ b/app/src/main/java/com/bitchat/android/ui/ChatViewModel.kt @@ -148,8 +148,7 @@ class ChatViewModel( } } - // SIMPLIFIED: Initialize location notes manager subscription (no separate counter) - initializeLocationNotesManagerSubscription() + // Removed background location notes subscription. Notes now load only when sheet opens. } fun cancelMediaSend(messageId: String) { diff --git a/app/src/main/java/com/bitchat/android/ui/LocationNotesViewModelExtensions.kt b/app/src/main/java/com/bitchat/android/ui/LocationNotesViewModelExtensions.kt deleted file mode 100644 index d8e638ce..00000000 --- a/app/src/main/java/com/bitchat/android/ui/LocationNotesViewModelExtensions.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.bitchat.android.ui - -import android.app.Application -import com.bitchat.android.geohash.ChannelID -import com.bitchat.android.geohash.GeohashChannelLevel -import com.bitchat.android.geohash.LocationChannelManager -import com.bitchat.android.nostr.LocationNotesManager -import com.bitchat.android.geohash.LocationChannelManager.PermissionState - -private val BUILDING_LEVEL = GeohashChannelLevel.BUILDING - -/** - * Automatically keep LocationNotesManager in sync with mesh chat and location availability. - * Subscribes to building-level notes when the user is in mesh chat and location access is ready. - */ -fun ChatViewModel.initializeLocationNotesManagerSubscription() { - val app = getApplication() - val locationManager = LocationChannelManager.getInstance(app) - val notesManager = LocationNotesManager.getInstance() - - fun refreshNotesSubscription() { - val permissionGranted = locationManager.permissionState.value == PermissionState.AUTHORIZED - val servicesEnabled = locationManager.isLocationServicesEnabled() - val viewingMesh = selectedLocationChannel.value is ChannelID.Mesh - - if (permissionGranted && servicesEnabled && viewingMesh) { - val buildingChannel = locationManager.availableChannels.value - ?.firstOrNull { it.level == BUILDING_LEVEL } - - if (buildingChannel != null) { - notesManager.setGeohash(buildingChannel.geohash) - } else { - // Trigger a refresh; when channels arrive we'll get called again - locationManager.refreshChannels() - } - } else { - notesManager.cancel() - } - } - - selectedLocationChannel.observeForever { refreshNotesSubscription() } - locationManager.permissionState.observeForever { - if (it == PermissionState.AUTHORIZED) { - locationManager.refreshChannels() - } - refreshNotesSubscription() - } - locationManager.availableChannels.observeForever { refreshNotesSubscription() } - locationManager.locationServicesEnabled.observeForever { enabled -> - if (enabled) { - locationManager.refreshChannels() - } - refreshNotesSubscription() - } - - // Evaluate immediately with current state - refreshNotesSubscription() -}