This some trash code.
This commit is contained in:
1 parent
aad97bdd9e
commit
32dc397e00
3 files changed
+95
-66
No files matched your search
+18
-9
@@ -22,12 +22,16 @@ import at.torch.compose.ui.composable.ShareProfileScreen
|
|||||||
import at.torch.compose.ui.composable.UnsyncedProfileScreen
|
import at.torch.compose.ui.composable.UnsyncedProfileScreen
|
||||||
import at.torch.compose.ui.composable.navigation.routes.ActiveProfileRoute
|
import at.torch.compose.ui.composable.navigation.routes.ActiveProfileRoute
|
||||||
import at.torch.compose.ui.composable.navigation.routes.ChatRoomCreationRoute
|
import at.torch.compose.ui.composable.navigation.routes.ChatRoomCreationRoute
|
||||||
|
import at.torch.compose.ui.composable.navigation.routes.LandingRoute
|
||||||
import at.torch.compose.ui.composable.navigation.routes.LoadingRoute
|
import at.torch.compose.ui.composable.navigation.routes.LoadingRoute
|
||||||
import at.torch.compose.ui.composable.navigation.routes.NostrEventDetailRoute
|
import at.torch.compose.ui.composable.navigation.routes.NostrEventDetailRoute
|
||||||
import at.torch.compose.ui.composable.navigation.routes.ShareProfileRoute
|
import at.torch.compose.ui.composable.navigation.routes.ShareProfileRoute
|
||||||
import at.torch.compose.ui.composable.navigation.routes.SocialPreconditionRoute
|
import at.torch.compose.ui.composable.navigation.routes.SocialPreconditionRoute
|
||||||
import at.torch.compose.ui.composable.navigation.routes.SovereignWalletStartupRoute
|
import at.torch.compose.ui.composable.navigation.routes.SovereignWalletStartupRoute
|
||||||
import at.torch.compose.ui.composable.navigation.routes.WriteNewNoteRoute
|
import at.torch.compose.ui.composable.navigation.routes.WriteNewNoteRoute
|
||||||
|
import at.torch.compose.ui.view.model.NavigationViewModel
|
||||||
|
import at.torch.compose.ui.view.model.NotaryViewModel
|
||||||
|
import at.torch.compose.ui.view.model.SynchronizationViewModel
|
||||||
import at.torch.compose.ui.view.state.NavigationUIState
|
import at.torch.compose.ui.view.state.NavigationUIState
|
||||||
import co.touchlab.kermit.Logger
|
import co.touchlab.kermit.Logger
|
||||||
import fr.acinq.phoenix.PhoenixGlobal
|
import fr.acinq.phoenix.PhoenixGlobal
|
||||||
@@ -84,8 +88,8 @@ fun TorchNavHost(
|
|||||||
phoenixGlobal = phoenixGlobal
|
phoenixGlobal = phoenixGlobal
|
||||||
))
|
))
|
||||||
|
|
||||||
val navigationViewModel: at.torch.compose.ui.view.model.NavigationViewModel = viewModel (
|
val navigationViewModel: NavigationViewModel = viewModel (
|
||||||
factory = at.torch.compose.ui.view.model.NavigationViewModel.factory(
|
factory = NavigationViewModel.factory(
|
||||||
activeWallet = sovereignWalletViewModel.activeWalletInUI,
|
activeWallet = sovereignWalletViewModel.activeWalletInUI,
|
||||||
initialNavigationUIState = NavigationUIState.Loading(),
|
initialNavigationUIState = NavigationUIState.Loading(),
|
||||||
nostrRepository = databaseNostrRepository,
|
nostrRepository = databaseNostrRepository,
|
||||||
@@ -94,8 +98,8 @@ fun TorchNavHost(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
val notaryViewModel: at.torch.compose.ui.view.model.NotaryViewModel = viewModel(
|
val notaryViewModel: NotaryViewModel = viewModel(
|
||||||
factory = at.torch.compose.ui.view.model.NotaryViewModel.factory(
|
factory = NotaryViewModel.factory(
|
||||||
activeWalletStateFlow = sovereignWalletViewModel.activeWalletInUI,
|
activeWalletStateFlow = sovereignWalletViewModel.activeWalletInUI,
|
||||||
nostrRepository = databaseNostrRepository,
|
nostrRepository = databaseNostrRepository,
|
||||||
chatRepository = databaseChatRepository,
|
chatRepository = databaseChatRepository,
|
||||||
@@ -104,8 +108,8 @@ fun TorchNavHost(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Produce a notary UI Element...
|
// TODO: Produce a notary UI Element...
|
||||||
val synchronizationViewModel: at.torch.compose.ui.view.model.SynchronizationViewModel = viewModel(
|
val synchronizationViewModel: SynchronizationViewModel = viewModel(
|
||||||
factory = at.torch.compose.ui.view.model.SynchronizationViewModel.factory(
|
factory = SynchronizationViewModel.factory(
|
||||||
activeWalletStateFlow = sovereignWalletViewModel.activeWalletInUI,
|
activeWalletStateFlow = sovereignWalletViewModel.activeWalletInUI,
|
||||||
nostrRepository = databaseNostrRepository,
|
nostrRepository = databaseNostrRepository,
|
||||||
chatRepository = databaseChatRepository,
|
chatRepository = databaseChatRepository,
|
||||||
@@ -229,17 +233,22 @@ fun TorchNavHost(
|
|||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = LoadingRoute()
|
startDestination = LoadingRoute()
|
||||||
) {
|
) {
|
||||||
composable<SovereignWalletStartupRoute> {
|
composable<SovereignWalletStartupRoute> { backStackEntry ->
|
||||||
|
val route = backStackEntry.toRoute<SovereignWalletStartupRoute>()
|
||||||
|
|
||||||
at.torch.compose.ui.composable.SovereignWalletStartupScreen(
|
at.torch.compose.ui.composable.SovereignWalletStartupScreen(
|
||||||
sovereignWalletViewModel = sovereignWalletViewModel,
|
sovereignWalletViewModel = sovereignWalletViewModel,
|
||||||
onNavigateToWalletLandingPage = {
|
onNavigateToWalletLandingPage = {
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
route = LoadingRoute(
|
route = LoadingRoute(
|
||||||
text = "Loading Aux"
|
text = "Landing... Aux"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onNavigateToWalletIntroPage = {
|
onNavigateToWalletIntroPage = {
|
||||||
|
applicationIOScope.launch {
|
||||||
|
navigationViewModel.loadInitialNostrProfile(route)
|
||||||
|
}
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
route = LoadingRoute(
|
route = LoadingRoute(
|
||||||
text = "Introducing... Aux"
|
text = "Introducing... Aux"
|
||||||
@@ -248,7 +257,7 @@ fun TorchNavHost(
|
|||||||
},
|
},
|
||||||
onSuccessfulStartup = {
|
onSuccessfulStartup = {
|
||||||
applicationIOScope.launch {
|
applicationIOScope.launch {
|
||||||
navigationViewModel.loadNostrProfile()
|
navigationViewModel.loadInitialNostrProfile(route)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
forceWalletId = null,
|
forceWalletId = null,
|
||||||
|
|||||||
+76
-57
@@ -4,6 +4,8 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.lifecycle.viewmodel.initializer
|
import androidx.lifecycle.viewmodel.initializer
|
||||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||||
|
import at.torch.compose.database.model.intermdiate.LocalAccount
|
||||||
|
import at.torch.compose.ui.composable.navigation.routes.SovereignWalletStartupRoute
|
||||||
import at.torch.compose.ui.view.state.NavigationUIState
|
import at.torch.compose.ui.view.state.NavigationUIState
|
||||||
import co.touchlab.kermit.Logger
|
import co.touchlab.kermit.Logger
|
||||||
import fr.acinq.phoenix.data.ActiveWallet
|
import fr.acinq.phoenix.data.ActiveWallet
|
||||||
@@ -17,6 +19,7 @@ import kotlinx.coroutines.flow.StateFlow
|
|||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
import kotlinx.coroutines.flow.getAndUpdate
|
import kotlinx.coroutines.flow.getAndUpdate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlin.time.Duration.Companion.milliseconds
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
@@ -59,19 +62,84 @@ class NavigationViewModel(
|
|||||||
observeProfile()
|
observeProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun loadNostrProfile() {
|
suspend fun loadInitialNostrProfile(startupRoute: SovereignWalletStartupRoute? = null) {
|
||||||
|
logger.d("loadInitialNostrProfile: $startupRoute")
|
||||||
val activeUserPublicKey = nostrRepository.getLocalAccounts().firstOrNull()?.profile?.publicKey
|
val activeUserPublicKey = nostrRepository.getLocalAccounts().firstOrNull()?.profile?.publicKey
|
||||||
|
|
||||||
if (activeUserPublicKey == null) {
|
if (activeUserPublicKey == null) {
|
||||||
// TODO: We can just go directly to startup witout fear...
|
|
||||||
_navigationUIState.getAndUpdate {
|
_navigationUIState.getAndUpdate {
|
||||||
NavigationUIState.Landing
|
if (startupRoute != null) {
|
||||||
|
NavigationUIState.Landing
|
||||||
|
} else {
|
||||||
|
NavigationUIState.StartupPhoenix
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// _navigationUIState.getAndUpdate {
|
if (startupRoute != null) {
|
||||||
// NavigationUIState.Loading(text = "Getting profile ready")
|
val localAccount = nostrRepository.observeProfile(
|
||||||
// }
|
publicKey = activeUserPublicKey
|
||||||
loadNostrProfile(activeUserPublicKey)
|
).firstOrNull()
|
||||||
|
|
||||||
|
processLocalAccount(localAccount)
|
||||||
|
} else {
|
||||||
|
_navigationUIState.getAndUpdate {
|
||||||
|
NavigationUIState.StartupPhoenix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processLocalAccount(localAccount: LocalAccount?) {
|
||||||
|
logger.i("processLocalAccount: $localAccount")
|
||||||
|
|
||||||
|
_navigationUIState.getAndUpdate {
|
||||||
|
if (localAccount == null) {
|
||||||
|
logger.i("We need to be on the landing screen so user creates account")
|
||||||
|
NavigationUIState.Landing
|
||||||
|
} else if (localAccount.unsignedNostrEvent == null) {
|
||||||
|
logger.i("We need to be on the landing screen so user creates account")
|
||||||
|
NavigationUIState.Landing
|
||||||
|
} else if (localAccount.broadcastNostrEventReceipt != null) {
|
||||||
|
logger.i("We have a broadcast receipt: ${localAccount.profile}")
|
||||||
|
NavigationUIState.ProfileLoaded(
|
||||||
|
publicKey = localAccount.unsignedNostrEvent.pubKey
|
||||||
|
)
|
||||||
|
} else if (localAccount.unsignedNostrEvent.signedAt != null && localAccount.profile != null) {
|
||||||
|
logger.i("We have successfully synced a profile: ${localAccount.profile}")
|
||||||
|
NavigationUIState.ProfileLoaded(
|
||||||
|
publicKey = localAccount.unsignedNostrEvent.pubKey
|
||||||
|
)
|
||||||
|
} else if (localAccount.broadcastNostrEventRequest != null) {
|
||||||
|
logger.i("We have a broadcast request: ${localAccount.broadcastNostrEventRequest}")
|
||||||
|
NavigationUIState.UnannouncedProfile(
|
||||||
|
broadcastNostrEventRequest = localAccount.broadcastNostrEventRequest
|
||||||
|
)
|
||||||
|
} else if (localAccount.profile != null) {
|
||||||
|
logger.i("We have a profile that needs to queued for broadcast: ${localAccount.profile}")
|
||||||
|
NavigationUIState.UnqueuedProfile(
|
||||||
|
profile = localAccount.profile
|
||||||
|
)
|
||||||
|
} else if (localAccount.nostrEvent != null) {
|
||||||
|
logger.i("Nostr event with the profile needs to be indexed: ${localAccount.nostrEvent}")
|
||||||
|
NavigationUIState.UnindexedProfile(
|
||||||
|
nostrEvent = localAccount.nostrEvent
|
||||||
|
)
|
||||||
|
} else if (localAccount.unsignedNostrEvent.signedAt != null && localAccount.synchronizeNostrEventRequests.isEmpty()) {
|
||||||
|
logger.i("We should request to sync profile: ${localAccount.unsignedNostrEvent}")
|
||||||
|
NavigationUIState.UnqueuedProfileSynchronization(
|
||||||
|
unsignedNostrEvent = localAccount.unsignedNostrEvent
|
||||||
|
)
|
||||||
|
} else if (localAccount.unsignedNostrEvent.signedAt != null && localAccount.synchronizeNostrEventRequests.isEmpty()) {
|
||||||
|
logger.i("We should be syncing the profile: ${localAccount.unsignedNostrEvent}")
|
||||||
|
NavigationUIState.UnsyncedProfile(
|
||||||
|
unsignedNostrEvent = localAccount.unsignedNostrEvent
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
logger.i("We have an unsigned profile: ${localAccount.unsignedNostrEvent}")
|
||||||
|
NavigationUIState.UnsignedProfile(
|
||||||
|
unsignedNostrEvent = localAccount.unsignedNostrEvent
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,56 +147,7 @@ class NavigationViewModel(
|
|||||||
nostrRepository.observeProfile(
|
nostrRepository.observeProfile(
|
||||||
publicKey = activeUserPublicKey
|
publicKey = activeUserPublicKey
|
||||||
).distinctUntilChanged().collect { localProfile ->
|
).distinctUntilChanged().collect { localProfile ->
|
||||||
logger.i("Local Profile: $localProfile")
|
processLocalAccount(localProfile)
|
||||||
_navigationUIState.getAndUpdate {
|
|
||||||
if (localProfile == null) {
|
|
||||||
logger.i("We need to be on the landing screen so user creates account")
|
|
||||||
NavigationUIState.Landing
|
|
||||||
} else if (localProfile.unsignedNostrEvent == null) {
|
|
||||||
logger.i("We need to be on the landing screen so user creates account")
|
|
||||||
NavigationUIState.Landing
|
|
||||||
} else if (localProfile.broadcastNostrEventReceipt != null) {
|
|
||||||
logger.i("We have a broadcast receipt: ${localProfile.profile}")
|
|
||||||
NavigationUIState.ProfileLoaded(
|
|
||||||
publicKey = localProfile.unsignedNostrEvent.pubKey
|
|
||||||
)
|
|
||||||
} else if (localProfile.unsignedNostrEvent.signedAt != null && localProfile.profile != null) {
|
|
||||||
logger.i("We have successfully synced a profile: ${localProfile.profile}")
|
|
||||||
NavigationUIState.ProfileLoaded(
|
|
||||||
publicKey = localProfile.unsignedNostrEvent.pubKey
|
|
||||||
)
|
|
||||||
} else if (localProfile.broadcastNostrEventRequest != null) {
|
|
||||||
logger.i("We have a broadcast request: ${localProfile.broadcastNostrEventRequest}")
|
|
||||||
NavigationUIState.UnannouncedProfile(
|
|
||||||
broadcastNostrEventRequest = localProfile.broadcastNostrEventRequest
|
|
||||||
)
|
|
||||||
} else if (localProfile.profile != null) {
|
|
||||||
logger.i("We have a profile that needs to queued for broadcast: ${localProfile.profile}")
|
|
||||||
NavigationUIState.UnqueuedProfile(
|
|
||||||
profile = localProfile.profile
|
|
||||||
)
|
|
||||||
} else if (localProfile.nostrEvent != null) {
|
|
||||||
logger.i("Nostr event with the profile needs to be indexed: ${localProfile.nostrEvent}")
|
|
||||||
NavigationUIState.UnindexedProfile(
|
|
||||||
nostrEvent = localProfile.nostrEvent
|
|
||||||
)
|
|
||||||
} else if (localProfile.unsignedNostrEvent.signedAt != null && localProfile.synchronizeNostrEventRequests.isEmpty()) {
|
|
||||||
logger.i("We should request to sync profile: ${localProfile.unsignedNostrEvent}")
|
|
||||||
NavigationUIState.UnqueuedProfileSynchronization(
|
|
||||||
unsignedNostrEvent = localProfile.unsignedNostrEvent
|
|
||||||
)
|
|
||||||
} else if (localProfile.unsignedNostrEvent.signedAt != null && localProfile.synchronizeNostrEventRequests.isEmpty()) {
|
|
||||||
logger.i("We should be syncing the profile: ${localProfile.unsignedNostrEvent}")
|
|
||||||
NavigationUIState.UnsyncedProfile(
|
|
||||||
unsignedNostrEvent = localProfile.unsignedNostrEvent
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
logger.i("We have an unsigned profile: ${localProfile.unsignedNostrEvent}")
|
|
||||||
NavigationUIState.UnsignedProfile(
|
|
||||||
unsignedNostrEvent = localProfile.unsignedNostrEvent
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class NotaryViewModel(
|
|||||||
private val logger = Logger.withTag(TAG)
|
private val logger = Logger.withTag(TAG)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
logger.d("NotaryViewModel.init")
|
||||||
scope.launch {
|
scope.launch {
|
||||||
activeWalletStateFlow.collectLatest { activeWallet ->
|
activeWalletStateFlow.collectLatest { activeWallet ->
|
||||||
logger.d("Notary ActiveWallet: $activeWallet")
|
logger.d("Notary ActiveWallet: $activeWallet")
|
||||||
|
|||||||
Reference in new issue
Block a user