load when clicked

This commit is contained in:
callebtc
2025-10-18 12:10:14 +02:00
parent 6d107199a8
commit 02868a95d4
3 changed files with 3 additions and 82 deletions
@@ -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(
@@ -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) {
@@ -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<Application>()
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()
}