From 155e57ab117d75f62549bdec1ae84116fdf30d25 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 26 Mar 2026 11:11:44 -0400 Subject: [PATCH] Defers most module creations to when they are needed via lambdas --- .../com/vitorpamplona/amethyst/AppModules.kt | 104 ++++++++++-------- .../vitorpamplona/amethyst/model/Account.kt | 8 +- .../amethyst/model/LocalCache.kt | 6 +- .../model/accountsCache/AccountCacheState.kt | 8 +- .../IncomingOtsEventVerifier.kt | 4 +- .../amethyst/model/nip03Timestamp/OtsState.kt | 8 +- .../nip47WalletConnect/NwcSignerState.kt | 14 ++- .../topNavFeeds/FeedTopNavFilterState.kt | 4 +- .../amethyst/service/images/BlossomFetcher.kt | 6 +- .../service/images/ImageLoaderSetup.kt | 2 +- .../vitorpamplona/amethyst/ui/note/Loaders.kt | 2 +- .../ui/screen/AccountSessionManager.kt | 4 +- .../ui/screen/loggedIn/AccountViewModel.kt | 12 +- 13 files changed, 103 insertions(+), 79 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt index 9928ce0a4..2a39bcf6d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt @@ -20,7 +20,6 @@ */ package com.vitorpamplona.amethyst -import android.content.ContentResolver import android.content.Context import androidx.security.crypto.EncryptedSharedPreferences import coil3.disk.DiskCache @@ -111,29 +110,37 @@ class AppModules( // Blocking load of UI Preferences to avoid theme/language blinking val uiPrefs by lazy { + Log.d("AppModules", "UiSharedPreferences Init") UiSharedPreferences(appContext, applicationIOScope) } // Blocking load of Tor Settings to avoid connection leaks val torPrefs by lazy { + Log.d("AppModules", "TorSharedPreferences Init") TorSharedPreferences(appContext, applicationIOScope) } // Namecoin ElectrumX server preferences (global, like Tor settings) val namecoinPrefs by lazy { + Log.d("AppModules", "NamecoinSharedPreferences Init") NamecoinSharedPreferences(appContext, applicationIOScope) } // OTS blockchain explorer preferences (global, like Tor settings) val otsPrefs by lazy { + Log.d("AppModules", "OtsSharedPreferences Init") OtsSharedPreferences(appContext, applicationIOScope) } // App services that should be run as soon as there are subscribers to their flows - val locationManager = LocationState(appContext, applicationIOScope) + val locationManager by lazy { + Log.d("AppModules", "LocationManager Init") + LocationState(appContext, applicationIOScope) + } val connManager = ConnectivityManager(appContext, applicationIOScope) val uiState by lazy { + Log.d("AppModules", "UiSettingsState Init") UiSettingsState(uiPrefs.value, connManager.isMobileOrFalse, applicationIOScope) } @@ -178,8 +185,6 @@ class AppModules( ) } - // Application-wide block height request cache - val otsBlockHeightCache by lazy { OtsBlockHeightCache() } val nip05Client by lazy { Log.d("AppModules", "NIP05Client Init") @@ -189,16 +194,22 @@ class AppModules( ) } - val otsResolverBuilder: TorAwareOkHttpOtsResolverBuilder = - TorAwareOkHttpOtsResolverBuilder( - roleBasedHttpClientBuilder::okHttpClientForMoney, - roleBasedHttpClientBuilder::shouldUseTorForMoneyOperations, - otsBlockHeightCache, - customExplorerUrl = { otsPrefs.current.normalizedUrl() }, - ) + val otsResolverBuilder by + lazy { + Log.d("AppModules", "OtsResolverBuilder Init") + TorAwareOkHttpOtsResolverBuilder( + roleBasedHttpClientBuilder::okHttpClientForMoney, + roleBasedHttpClientBuilder::shouldUseTorForMoneyOperations, + OtsBlockHeightCache(), + customExplorerUrl = { otsPrefs.current.normalizedUrl() }, + ) + } // Application-wide ots verification cache - val otsVerifCache by lazy { VerificationStateCache(otsResolverBuilder) } + val otsVerifCache by lazy { + Log.d("AppModules", "OtsCache Init") + VerificationStateCache(otsResolverBuilder) + } val torEvaluatorFlow = TorRelayState( @@ -250,7 +261,12 @@ class AppModules( val authCoordinator = AuthCoordinator(client, applicationIOScope) // Tries to verify new OTS events when they arrive. - val otsEventVerifier = IncomingOtsEventVerifier(otsVerifCache, cache, applicationIOScope) + val otsEventVerifier = + IncomingOtsEventVerifier( + otsVerifCache = { otsVerifCache }, + cache = cache, + scope = applicationIOScope, + ) // Tracks if it is possible to connect to relays. val failureTracker = RelayOfflineTracker(client) @@ -276,10 +292,10 @@ class AppModules( // keeps all accounts live val accountsCache = AccountCacheState( - geolocationFlow = locationManager.geohashStateFlow, - nwcFilterAssembler = sources.nwc, - contentResolverFn = ::contentResolverFn, - otsResolverBuilder = otsResolverBuilder, + geolocationFlow = { locationManager.geohashStateFlow }, + nwcFilterAssembler = { sources.nwc }, + contentResolverFn = { appContext.contentResolver }, + otsResolverBuilder = { otsResolverBuilder.build() }, cache = cache, client = client, ) @@ -287,8 +303,8 @@ class AppModules( val sessionManager = AccountSessionManager( accountsCache = accountsCache, - client = client, nip05ClientBuilder = { nip05Client }, + clientBuilder = { client }, localPreferences = LocalPreferences, scope = applicationIOScope, ) @@ -314,7 +330,8 @@ class AppModules( } } - val blossomResolver = + val blossomResolver by lazy { + Log.d("AppModules", "BlossomServerResolver Init") BlossomServerResolver( loggedInUsers = { listOfNotNull(sessionManager.loggedInAccount()?.pubKey) }, blossomServers = { addressesToSubscribe -> @@ -330,6 +347,7 @@ class AppModules( }, httpClientBuilder = roleBasedHttpClientBuilder, ) + } // Organizes cache clearing val trimmingService = MemoryTrimmingService(cache) @@ -339,36 +357,47 @@ class AppModules( val accountsTorStateConnector = AccountsTorStateConnector(accountsCache, torEvaluatorFlow, applicationIOScope) // saves the .content of NIP-95 blobs in disk to save memory - val nip95cache: File by lazy { Nip95CacheFactory.new(appContext) } + val nip95cache: File by lazy { + Log.d("AppModules", "NIP95 Cache Init") + Nip95CacheFactory.new(appContext) + } // local video cache with disk + memory - val videoCache: VideoCache by lazy { VideoCacheFactory.new(appContext) } + val videoCache: VideoCache by lazy { + Log.d("AppModules", "VideoCache Init") + VideoCacheFactory.new(appContext) + } // image cache in disk for coil - val diskCache: DiskCache by lazy { ImageCacheFactory.newDisk(appContext) } + val diskCache: DiskCache by lazy { + Log.d("AppModules", "ImageCacheFactory Init") + ImageCacheFactory.newDisk(appContext) + } // image cache in memory for coil - val memoryCache: MemoryCache by lazy { ImageCacheFactory.newMemory(appContext) } + val memoryCache: MemoryCache by lazy { + Log.d("AppModules", "MemoryCache Init") + ImageCacheFactory.newMemory(appContext) + } // crash report storage - val crashReportCache: CrashReportCache by lazy { CrashReportCache(appContext) } + val crashReportCache = CrashReportCache(appContext) // cache for NIP-11 documents val nip11Cache: Nip11CachedRetriever by lazy { + Log.d("AppModules", "Nip11CachedRetriever Init") Nip11CachedRetriever(torEvaluatorFlow::okHttpClientForRelay) } - fun contentResolverFn(): ContentResolver = appContext.contentResolver - fun setImageLoader() { + Log.d("AppModules", "ImageLoaderSetup Init") ImageLoaderSetup.setup( app = appContext, diskCache = { diskCache }, memoryCache = { memoryCache }, - blossomServerResolver = blossomResolver, - ) { url -> - okHttpClients.getHttpClient(roleBasedHttpClientBuilder.shouldUseTorForImageDownload(url)) - } + blossomServerResolver = { blossomResolver }, + callFactory = { okHttpClients.getHttpClient(roleBasedHttpClientBuilder.shouldUseTorForImageDownload(it)) }, + ) } fun encryptedStorage(npub: String? = null): EncryptedSharedPreferences = EncryptedStorage.preferences(appContext, npub) @@ -385,12 +414,6 @@ class AppModules( // forces initialization of uiPrefs in the main thread to avoid blinking themes uiPrefs - // initializes diskcache on an IO thread. - applicationIOScope.launch { - // preloads tor preferences - torPrefs - } - // initializes diskcache on an IO thread. applicationIOScope.launch { // Sets Coil - Tor - OkHttp link @@ -402,15 +425,10 @@ class AppModules( // initializes diskcache on an IO thread. applicationIOScope.launch { - // Sets Coil - Tor - OkHttp link - delay(3000) + // Prepares video cache later + delay(10_000) videoCache } - - applicationIOScope.launch { - // Eagerly initialize OtsSharedPreferences off the main thread - otsPrefs - } } fun terminate(appContext: Context) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index dbe16ea3d..c11146d74 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -143,7 +143,7 @@ import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal import com.vitorpamplona.quartz.nip01Core.tags.hashtags.hashtags import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUserIds import com.vitorpamplona.quartz.nip01Core.tags.references.references -import com.vitorpamplona.quartz.nip03Timestamp.OtsResolverBuilder +import com.vitorpamplona.quartz.nip03Timestamp.OtsResolver import com.vitorpamplona.quartz.nip04Dm.PrivateDMCache import com.vitorpamplona.quartz.nip04Dm.messages.PrivateDmEvent import com.vitorpamplona.quartz.nip09Deletions.DeletionEvent @@ -235,9 +235,9 @@ import kotlin.coroutines.cancellation.CancellationException class Account( val settings: AccountSettings = AccountSettings(KeyPair()), override val signer: NostrSigner, - val geolocationFlow: StateFlow, - val nwcFilterAssembler: NWCPaymentFilterAssembler, - val otsResolverBuilder: OtsResolverBuilder, + val geolocationFlow: () -> StateFlow, + val nwcFilterAssembler: () -> NWCPaymentFilterAssembler, + val otsResolverBuilder: () -> OtsResolver, val cache: LocalCache, val client: INostrClient, val scope: CoroutineScope, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index d792bcb3a..61803f705 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -2491,7 +2491,7 @@ object LocalCache : ILocalCache, ICacheProvider { suspend fun findEarliestOtsForNote( note: Note, - otsVerifCache: VerificationStateCache, + otsVerifCacheBuilder: () -> VerificationStateCache, ): Long? { checkNotInMainThread() @@ -2502,7 +2502,7 @@ object LocalCache : ILocalCache, ICacheProvider { notes.mapNotNull { _, item -> val noteEvent = item.event if ((noteEvent is OtsEvent && noteEvent.isTaggedEvent(note.idHex) && !noteEvent.isExpirationBefore(time))) { - val cachedTime = (otsVerifCache.justCache(noteEvent) as? VerificationState.Verified)?.verifiedTime + val cachedTime = (otsVerifCacheBuilder().justCache(noteEvent) as? VerificationState.Verified)?.verifiedTime if (cachedTime != null) { if (minTime == null || cachedTime < (minTime ?: Long.MAX_VALUE)) { minTime = cachedTime @@ -2518,7 +2518,7 @@ object LocalCache : ILocalCache, ICacheProvider { } candidates.forEach { noteEvent -> - (otsVerifCache.cacheVerify(noteEvent) as? VerificationState.Verified)?.verifiedTime?.let { stampedTime -> + (otsVerifCacheBuilder().cacheVerify(noteEvent) as? VerificationState.Verified)?.verifiedTime?.let { stampedTime -> if (minTime == null || stampedTime < (minTime ?: Long.MAX_VALUE)) { minTime = stampedTime } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/accountsCache/AccountCacheState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/accountsCache/AccountCacheState.kt index 28e417e46..30379256b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/accountsCache/AccountCacheState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/accountsCache/AccountCacheState.kt @@ -31,7 +31,7 @@ import com.vitorpamplona.quartz.nip01Core.core.toHexKey import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal -import com.vitorpamplona.quartz.nip03Timestamp.OtsResolverBuilder +import com.vitorpamplona.quartz.nip03Timestamp.OtsResolver import com.vitorpamplona.quartz.nip55AndroidSigner.client.NostrSignerExternal import com.vitorpamplona.quartz.nip89AppHandlers.clientTag.NostrSignerWithClientTag import com.vitorpamplona.quartz.utils.Log @@ -45,10 +45,10 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update class AccountCacheState( - val geolocationFlow: StateFlow, - val nwcFilterAssembler: NWCPaymentFilterAssembler, + val geolocationFlow: () -> StateFlow, + val nwcFilterAssembler: () -> NWCPaymentFilterAssembler, val contentResolverFn: () -> ContentResolver, - val otsResolverBuilder: OtsResolverBuilder, + val otsResolverBuilder: () -> OtsResolver, val cache: LocalCache, val client: INostrClient, ) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/IncomingOtsEventVerifier.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/IncomingOtsEventVerifier.kt index 3e3222b67..f082fa108 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/IncomingOtsEventVerifier.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/IncomingOtsEventVerifier.kt @@ -32,7 +32,7 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn class IncomingOtsEventVerifier( - private val otsVerifCache: VerificationStateCache, + private val otsVerifCache: () -> VerificationStateCache, private val cache: LocalCache, private val scope: CoroutineScope, ) { @@ -52,7 +52,7 @@ class IncomingOtsEventVerifier( suspend fun consume(note: Note) { note.event?.let { event -> if (event is OtsEvent) { - otsVerifCache.cacheVerify(event) + otsVerifCache().cacheVerify(event) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/OtsState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/OtsState.kt index c8b537f98..423943d4d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/OtsState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip03Timestamp/OtsState.kt @@ -26,7 +26,7 @@ import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner import com.vitorpamplona.quartz.nip03Timestamp.OtsEvent -import com.vitorpamplona.quartz.nip03Timestamp.OtsResolverBuilder +import com.vitorpamplona.quartz.nip03Timestamp.OtsResolver import com.vitorpamplona.quartz.utils.Log import com.vitorpamplona.quartz.utils.TimeUtils import kotlinx.coroutines.CoroutineScope @@ -37,7 +37,7 @@ import java.util.Base64 class OtsState( val signer: NostrSigner, val cache: LocalCache, - val otsResolver: OtsResolverBuilder, + val otsResolver: () -> OtsResolver, val scope: CoroutineScope, val settings: AccountSettings, ) { @@ -58,7 +58,7 @@ class OtsState( Log.d("Pending Attestations", "Updating ${settings.pendingAttestations.value.size} pending attestations") return settings.pendingAttestations.value.toList().mapNotNull { (key, value) -> - val otsState = OtsEvent.upgrade(Base64.getDecoder().decode(value), key, otsResolver.build()) + val otsState = OtsEvent.upgrade(Base64.getDecoder().decode(value), key, otsResolver()) if (otsState != null) { val hint = cache.getNoteIfExists(key)?.toEventHint() @@ -96,7 +96,7 @@ class OtsState( Base64.getEncoder().encodeToString( OtsEvent.stamp( id, - otsResolver.build(), + otsResolver(), ), ), ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip47WalletConnect/NwcSignerState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip47WalletConnect/NwcSignerState.kt index bb40be6cf..616ad24e6 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip47WalletConnect/NwcSignerState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip47WalletConnect/NwcSignerState.kt @@ -64,7 +64,7 @@ import kotlinx.coroutines.launch */ class NwcSignerState( val signer: NostrSigner, - val nwcFilterAssembler: NWCPaymentFilterAssembler, + val nwcFilterAssembler: () -> NWCPaymentFilterAssembler, val cache: LocalCache, val scope: CoroutineScope, val nip47Setup: MutableStateFlow, @@ -163,11 +163,13 @@ class NwcSignerState( relay = walletService.relayUri, ) - nwcFilterAssembler.subscribe(filter) + val assembler = nwcFilterAssembler() + + assembler.subscribe(filter) scope.launch(Dispatchers.IO) { delay(60000) - nwcFilterAssembler.unsubscribe(filter) + assembler.unsubscribe(filter) } cache.consume(event, null, true, walletService.relayUri) { @@ -204,11 +206,13 @@ class NwcSignerState( relay = walletService.relayUri, ) - nwcFilterAssembler.subscribe(filter) + val assembler = nwcFilterAssembler() + + assembler.subscribe(filter) scope.launch(Dispatchers.IO) { delay(60000) // waits 1 minute to complete payment. - nwcFilterAssembler.unsubscribe(filter) + assembler.unsubscribe(filter) } cache.consume(event, zappedNote, true, walletService.relayUri) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/FeedTopNavFilterState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/FeedTopNavFilterState.kt index 44d62f84a..8dae90a9b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/FeedTopNavFilterState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/topNavFeeds/FeedTopNavFilterState.kt @@ -51,7 +51,7 @@ class FeedTopNavFilterState( val feedFilterListName: MutableStateFlow, val kind3Follows: StateFlow, val allFollows: StateFlow, - val locationFlow: StateFlow, + val locationFlow: () -> StateFlow, val followsRelays: StateFlow>, val blockedRelays: StateFlow>, val proxyRelays: StateFlow>, @@ -78,7 +78,7 @@ class FeedTopNavFilterState( } TopFilter.AroundMe -> { - AroundMeFeedFlow(locationFlow, followsRelays, proxyRelays) + AroundMeFeedFlow(locationFlow(), followsRelays, proxyRelays) } TopFilter.Chess -> { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/BlossomFetcher.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/BlossomFetcher.kt index 2b0b80447..7406c8e13 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/BlossomFetcher.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/BlossomFetcher.kt @@ -41,12 +41,12 @@ import kotlin.coroutines.cancellation.CancellationException class BlossomFetcher( private val options: Options, private val data: Uri, - private val blossomServerResolver: BlossomServerResolver, + private val blossomServerResolver: () -> BlossomServerResolver, private val networkFetcher: (url: String) -> Fetcher, ) : Fetcher { override suspend fun fetch(): FetchResult? = try { - val urlResult = blossomServerResolver.findServers(data.toString()) + val urlResult = blossomServerResolver().findServers(data.toString()) networkFetcher(urlResult?.serverUrl ?: data.toString()).fetch() } catch (e: Exception) { if (e is CancellationException) throw e @@ -55,7 +55,7 @@ class BlossomFetcher( @OptIn(ExperimentalCoilApi::class) class Factory( - val blossomServerResolver: BlossomServerResolver, + val blossomServerResolver: () -> BlossomServerResolver, val networkClient: (url: String) -> Call.Factory, ) : Fetcher.Factory { private val connectivityCheckerLazy = singleParameterLazy(::ConnectivityChecker) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt index 22a71cd21..9e8b40a03 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt @@ -64,7 +64,7 @@ class ImageLoaderSetup { app: Context, diskCache: () -> DiskCache, memoryCache: () -> MemoryCache, - blossomServerResolver: BlossomServerResolver, + blossomServerResolver: () -> BlossomServerResolver, callFactory: (url: String) -> Call.Factory, ) { SingletonImageLoader.setUnsafe( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt index 36939b594..28e04659b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt @@ -123,7 +123,7 @@ fun LoadOts( withContext(Dispatchers.IO) { LocalCache.findEarliestOtsForNote( note = noteStatus?.note ?: note, - otsVerifCache = Amethyst.instance.otsVerifCache, + otsVerifCacheBuilder = { Amethyst.instance.otsVerifCache }, ) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt index 07ac0d870..4bd3202fd 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt @@ -93,8 +93,8 @@ sealed class AccountState { @Stable class AccountSessionManager( val accountsCache: AccountCacheState, - val client: INostrClient, val nip05ClientBuilder: () -> Nip05Client, + val clientBuilder: () -> INostrClient, val localPreferences: LocalPreferences, val scope: CoroutineScope, ) { @@ -287,6 +287,8 @@ class AccountSessionManager( val toPost = accountSettings.backupNIP65RelayList?.writeRelaysNorm()?.toSet() ?: DefaultNIP65RelaySet + val client = clientBuilder() + accountSettings.backupUserMetadata?.let { client.send(it, toPost) } accountSettings.backupContactList?.let { client.send(it, toPost) } accountSettings.backupNIP65RelayList?.let { client.send(it, toPost) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 1396e821d..2706c7b01 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -1808,9 +1808,9 @@ fun mockAccountViewModel(): AccountViewModel { Account( settings = AccountSettings(keyPair), signer = NostrSignerInternal(keyPair), - geolocationFlow = MutableStateFlow(LocationState.LocationResult.Loading), - nwcFilterAssembler = nwcFilters, - otsResolverBuilder = EmptyOtsResolverBuilder, + geolocationFlow = { MutableStateFlow(LocationState.LocationResult.Loading) }, + nwcFilterAssembler = { nwcFilters }, + otsResolverBuilder = { EmptyOtsResolverBuilder.build() }, cache = LocalCache, client = client, scope = scope, @@ -1859,9 +1859,9 @@ fun mockVitorAccountViewModel(): AccountViewModel { Account( settings = AccountSettings(keyPair), signer = NostrSignerInternal(keyPair), - geolocationFlow = MutableStateFlow(LocationState.LocationResult.Loading), - nwcFilterAssembler = nwcFilters, - otsResolverBuilder = EmptyOtsResolverBuilder, + geolocationFlow = { MutableStateFlow(LocationState.LocationResult.Loading) }, + nwcFilterAssembler = { nwcFilters }, + otsResolverBuilder = { EmptyOtsResolverBuilder.build() }, cache = LocalCache, client = EmptyNostrClient(), scope = scope,