mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 03:25:20 +00:00
load when clicked
This commit is contained in:
@@ -286,30 +286,10 @@ class LocationNotesManager private constructor() {
|
|||||||
val subscribe = subscribeFunc
|
val subscribe = subscribeFunc
|
||||||
if (subscribe == null) {
|
if (subscribe == null) {
|
||||||
Log.e(TAG, "Cannot subscribe - subscribe function not initialized")
|
Log.e(TAG, "Cannot subscribe - subscribe function not initialized")
|
||||||
_state.value = State.NO_RELAYS
|
_state.value = State.LOADING
|
||||||
return
|
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
|
_state.value = State.LOADING
|
||||||
|
|
||||||
val filter = NostrFilter.geohashNotes(
|
val filter = NostrFilter.geohashNotes(
|
||||||
|
|||||||
@@ -148,8 +148,7 @@ class ChatViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SIMPLIFIED: Initialize location notes manager subscription (no separate counter)
|
// Removed background location notes subscription. Notes now load only when sheet opens.
|
||||||
initializeLocationNotesManagerSubscription()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cancelMediaSend(messageId: String) {
|
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()
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user