diff --git a/app/src/main/kotlin/com/wire/android/navigation/LoginTypeSelector.kt b/app/src/main/kotlin/com/wire/android/navigation/LoginTypeSelector.kt index c88688cf4c5..b15a9b2b6a3 100644 --- a/app/src/main/kotlin/com/wire/android/navigation/LoginTypeSelector.kt +++ b/app/src/main/kotlin/com/wire/android/navigation/LoginTypeSelector.kt @@ -22,6 +22,7 @@ import com.wire.android.di.KaliumCoreLogic import com.wire.kalium.logic.CoreLogic import com.wire.kalium.logic.configuration.server.ServerConfig import com.wire.kalium.logic.feature.auth.LoginContext +import dagger.Lazy import kotlinx.coroutines.flow.first import javax.inject.Inject import javax.inject.Named @@ -33,14 +34,15 @@ import javax.inject.Singleton */ @Singleton class LoginTypeSelector @Inject constructor( - @KaliumCoreLogic private val coreLogic: CoreLogic, + @KaliumCoreLogic private val coreLogic: Lazy, @Named("useNewLoginForDefaultBackend") private val useNewLoginForDefaultBackend: Boolean, ) { /** * Observe the [LoginContext] for the given [ServerConfig.Links]. */ - private suspend fun loginContextFlow(serverLinks: ServerConfig.Links) = coreLogic.getGlobalScope().observeLoginContext(serverLinks) + private suspend fun loginContextFlow(serverLinks: ServerConfig.Links) = + coreLogic.get().getGlobalScope().observeLoginContext(serverLinks) /** * Determine if the new login flow can be used for the given [ServerConfig.Links]. diff --git a/app/src/main/kotlin/com/wire/android/ui/CallFeedbackViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/CallFeedbackViewModel.kt index 4ce8541c4b9..9ab12dbfcf6 100644 --- a/app/src/main/kotlin/com/wire/android/ui/CallFeedbackViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/CallFeedbackViewModel.kt @@ -32,6 +32,7 @@ import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.session.CurrentSessionFlowUseCase import com.wire.kalium.logic.feature.session.CurrentSessionResult import com.wire.kalium.logic.feature.user.ShouldAskCallFeedbackUseCaseResult +import dagger.Lazy import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.collectLatest @@ -45,10 +46,10 @@ import javax.inject.Inject @HiltViewModel class CallFeedbackViewModel @Inject constructor( - @KaliumCoreLogic private val coreLogic: CoreLogic, - private val currentSessionFlow: CurrentSessionFlowUseCase, - private val isAnalyticsAvailable: IsAnalyticsAvailableUseCase, - private val analyticsManager: AnonymousAnalyticsManager, + @KaliumCoreLogic private val coreLogic: Lazy, + private val currentSessionFlow: Lazy, + private val isAnalyticsAvailable: Lazy, + private val analyticsManager: Lazy, ) : ViewModel() { val showCallFeedbackFlow = MutableSharedFlow() @@ -62,12 +63,12 @@ class CallFeedbackViewModel @Inject constructor( } private suspend fun observeAskCallFeedback() { - currentSessionFlow() + currentSessionFlow.get().invoke() .distinctUntilChanged() .flatMapLatest { session -> if (session is CurrentSessionResult.Success && session.accountInfo.isValid()) { currentUserId = session.accountInfo.userId - coreLogic.getSessionScope(currentUserId!!).observeSyncState() + coreLogic.get().getSessionScope(currentUserId!!).observeSyncState() } else { currentUserId = null emptyFlow() @@ -75,10 +76,10 @@ class CallFeedbackViewModel @Inject constructor( } .filter { it == SyncState.Live } .flatMapLatest { - coreLogic.getSessionScope(currentUserId!!).calls.observeAskCallFeedbackUseCase() + coreLogic.get().getSessionScope(currentUserId!!).calls.observeAskCallFeedbackUseCase() } .collectLatest { shouldAskFeedback -> - if (isAnalyticsAvailable(currentUserId!!)) { + if (isAnalyticsAvailable.get().invoke(currentUserId!!)) { when (shouldAskFeedback) { is ShouldAskCallFeedbackUseCaseResult.ShouldAskCallFeedback -> { showCallFeedbackFlow.emit(Unit) @@ -86,8 +87,8 @@ class CallFeedbackViewModel @Inject constructor( is ShouldAskCallFeedbackUseCaseResult.ShouldNotAskCallFeedback.CallDurationIsLessThanOneMinute -> { val recentlyEndedCallMetadata = - coreLogic.getSessionScope(currentUserId!!).calls.observeRecentlyEndedCallMetadata().first() - analyticsManager.sendEvent( + coreLogic.get().getSessionScope(currentUserId!!).calls.observeRecentlyEndedCallMetadata().first() + analyticsManager.get().sendEvent( with(recentlyEndedCallMetadata) { AnalyticsEvent.CallQualityFeedback.TooShort( callDuration = shouldAskFeedback.callDurationInSeconds.toInt(), @@ -102,8 +103,8 @@ class CallFeedbackViewModel @Inject constructor( is ShouldAskCallFeedbackUseCaseResult.ShouldNotAskCallFeedback.NextTimeForCallFeedbackIsNotReached -> { val recentlyEndedCallMetadata = - coreLogic.getSessionScope(currentUserId!!).calls.observeRecentlyEndedCallMetadata().first() - analyticsManager.sendEvent( + coreLogic.get().getSessionScope(currentUserId!!).calls.observeRecentlyEndedCallMetadata().first() + analyticsManager.get().sendEvent( with(recentlyEndedCallMetadata) { AnalyticsEvent.CallQualityFeedback.Muted( callDuration = shouldAskFeedback.callDurationInSeconds.toInt(), @@ -123,8 +124,8 @@ class CallFeedbackViewModel @Inject constructor( fun rateCall(rate: Int, doNotAsk: Boolean) { currentUserId?.let { viewModelScope.launch { - val recentlyEndedCallMetadata = coreLogic.getSessionScope(it).calls.observeRecentlyEndedCallMetadata().first() - analyticsManager.sendEvent( + val recentlyEndedCallMetadata = coreLogic.get().getSessionScope(it).calls.observeRecentlyEndedCallMetadata().first() + analyticsManager.get().sendEvent( with(recentlyEndedCallMetadata) { AnalyticsEvent.CallQualityFeedback.Answered( score = rate, @@ -136,7 +137,7 @@ class CallFeedbackViewModel @Inject constructor( ) } ) - coreLogic.getSessionScope(it).calls.updateNextTimeCallFeedback(doNotAsk) + coreLogic.get().getSessionScope(it).calls.updateNextTimeCallFeedback(doNotAsk) } } } @@ -144,9 +145,9 @@ class CallFeedbackViewModel @Inject constructor( fun skipCallFeedback(doNotAsk: Boolean) { currentUserId?.let { viewModelScope.launch { - val recentlyEndedCallMetadata = coreLogic.getSessionScope(it).calls.observeRecentlyEndedCallMetadata().first() - coreLogic.getSessionScope(it).calls.updateNextTimeCallFeedback(doNotAsk) - analyticsManager.sendEvent( + val recentlyEndedCallMetadata = coreLogic.get().getSessionScope(it).calls.observeRecentlyEndedCallMetadata().first() + coreLogic.get().getSessionScope(it).calls.updateNextTimeCallFeedback(doNotAsk) + analyticsManager.get().sendEvent( with(recentlyEndedCallMetadata) { AnalyticsEvent.CallQualityFeedback.Dismissed( callDuration = callDetails.callDurationInSeconds.toInt(), diff --git a/app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt index 7827610f34a..a7e26247dda 100644 --- a/app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt @@ -104,7 +104,7 @@ import javax.inject.Inject @OptIn(ExperimentalCoroutinesApi::class) @HiltViewModel class WireActivityViewModel @Inject constructor( - @KaliumCoreLogic private val coreLogic: CoreLogic, + @KaliumCoreLogic private val coreLogic: Lazy, private val dispatchers: DispatcherProvider, currentSessionFlow: Lazy, private val doesValidSessionExist: Lazy, @@ -288,11 +288,11 @@ class WireActivityViewModel @Inject constructor( data: InputStream ) { viewModelScope.launch(dispatchers.io()) { - when (val currentSession = coreLogic.getGlobalScope().session.currentSession()) { + when (val currentSession = coreLogic.get().getGlobalScope().session.currentSession()) { is CurrentSessionResult.Failure.Generic -> null CurrentSessionResult.Failure.SessionNotFound -> null is CurrentSessionResult.Success -> { - coreLogic.sessionScope(currentSession.accountInfo.userId) { + coreLogic.get().sessionScope(currentSession.accountInfo.userId) { when (val result = debug.synchronizeExternalData(InputStreamReader(data).readText())) { is SynchronizeExternalDataResult.Success -> { appLogger.d("Synchronized external data") @@ -358,11 +358,11 @@ class WireActivityViewModel @Inject constructor( switchAccountActions: SwitchAccountActions ) { viewModelScope.launch { - coreLogic.getGlobalScope().session.currentSession().takeIf { + coreLogic.get().getGlobalScope().session.currentSession().takeIf { it is CurrentSessionResult.Success }?.let { val currentUserId = (it as CurrentSessionResult.Success).accountInfo.userId - coreLogic.getSessionScope(currentUserId).logout(LogoutReason.SELF_HARD_LOGOUT) + coreLogic.get().getSessionScope(currentUserId).logout(LogoutReason.SELF_HARD_LOGOUT) clearUserData(currentUserId) } accountSwitch.get().invoke(SwitchAccountParam.TryToSwitchToNextAccount).also { @@ -439,11 +439,11 @@ class WireActivityViewModel @Inject constructor( key: String, domain: String?, onSuccess: (ConversationId) -> Unit - ) = when (val currentSession = coreLogic.getGlobalScope().session.currentSession()) { + ) = when (val currentSession = coreLogic.get().getGlobalScope().session.currentSession()) { is CurrentSessionResult.Failure.Generic -> null CurrentSessionResult.Failure.SessionNotFound -> null is CurrentSessionResult.Success -> { - coreLogic.sessionScope(currentSession.accountInfo.userId) { + coreLogic.get().sessionScope(currentSession.accountInfo.userId) { when (val result = conversations.checkIConversationInviteCode(code, key, domain)) { is CheckConversationInviteCodeUseCase.Result.Success -> { if (result.isSelfMember) { @@ -485,7 +485,7 @@ class WireActivityViewModel @Inject constructor( fun observePersistentConnectionStatus() { viewModelScope.launch { - coreLogic.getGlobalScope().observePersistentWebSocketConnectionStatus() + coreLogic.get().getGlobalScope().observePersistentWebSocketConnectionStatus() .let { result -> when (result) { is ObservePersistentWebSocketConnectionStatusUseCase.Result.Failure -> { diff --git a/app/src/main/kotlin/com/wire/android/ui/analytics/AnalyticsUsageViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/analytics/AnalyticsUsageViewModel.kt index d42c464e107..f8fe47b6f0d 100644 --- a/app/src/main/kotlin/com/wire/android/ui/analytics/AnalyticsUsageViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/analytics/AnalyticsUsageViewModel.kt @@ -25,6 +25,7 @@ import androidx.lifecycle.viewModelScope import com.wire.android.datastore.UserDataStore import com.wire.kalium.logic.configuration.server.ServerConfig import com.wire.kalium.logic.feature.user.SelfServerConfigUseCase +import dagger.Lazy import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch @@ -33,18 +34,18 @@ import javax.inject.Inject @HiltViewModel class AnalyticsUsageViewModel @Inject constructor( private val analyticsEnabled: AnalyticsConfiguration, - private val dataStore: UserDataStore, - private val selfServerConfig: SelfServerConfigUseCase + private val dataStore: Lazy, + private val selfServerConfig: Lazy, ) : ViewModel() { var state by mutableStateOf(AnalyticsUsageState()) init { viewModelScope.launch { - val isDialogSeen = dataStore.isAnalyticsDialogSeen().first() - val isAnalyticsUsageEnabled = dataStore.isAnonymousUsageDataEnabled().first() + val isDialogSeen = dataStore.get().isAnalyticsDialogSeen().first() + val isAnalyticsUsageEnabled = dataStore.get().isAnonymousUsageDataEnabled().first() val isAnalyticsConfigurationEnabled = analyticsEnabled is AnalyticsConfiguration.Enabled - val isValidBackend = when (val serverConfig = selfServerConfig()) { + val isValidBackend = when (val serverConfig = selfServerConfig.get().invoke()) { is SelfServerConfigUseCase.Result.Success -> serverConfig.serverLinks.links.api == ServerConfig.PRODUCTION.api || serverConfig.serverLinks.links.api == ServerConfig.STAGING.api @@ -61,8 +62,8 @@ class AnalyticsUsageViewModel @Inject constructor( fun agreeAnalyticsUsage() { viewModelScope.launch { - dataStore.setIsAnonymousAnalyticsEnabled(enabled = true) - dataStore.setIsAnalyticsDialogSeen() + dataStore.get().setIsAnonymousAnalyticsEnabled(enabled = true) + dataStore.get().setIsAnalyticsDialogSeen() hideDialog() } @@ -70,8 +71,8 @@ class AnalyticsUsageViewModel @Inject constructor( fun declineAnalyticsUsage() { viewModelScope.launch { - dataStore.setIsAnonymousAnalyticsEnabled(enabled = false) - dataStore.setIsAnalyticsDialogSeen() + dataStore.get().setIsAnonymousAnalyticsEnabled(enabled = false) + dataStore.get().setIsAnalyticsDialogSeen() hideDialog() } diff --git a/app/src/main/kotlin/com/wire/android/ui/common/topappbar/CommonTopAppBarViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/common/topappbar/CommonTopAppBarViewModel.kt index 7bc542bea46..57adf089deb 100644 --- a/app/src/main/kotlin/com/wire/android/ui/common/topappbar/CommonTopAppBarViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/common/topappbar/CommonTopAppBarViewModel.kt @@ -37,6 +37,7 @@ import com.wire.kalium.logic.data.sync.SyncState.Waiting import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.session.CurrentSessionResult import com.wire.kalium.network.NetworkState +import dagger.Lazy import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collectLatest @@ -52,7 +53,7 @@ import javax.inject.Inject @HiltViewModel class CommonTopAppBarViewModel @Inject constructor( private val currentScreenManager: CurrentScreenManager, - @KaliumCoreLogic private val coreLogic: CoreLogic + @KaliumCoreLogic private val coreLogic: Lazy, ) : ViewModel() { var state by mutableStateOf(CommonTopAppBarState()) @@ -62,8 +63,8 @@ class CommonTopAppBarViewModel @Inject constructor( currentScreenManager.observeCurrentScreen(viewModelScope) private fun connectivityFlow(userId: UserId): Flow = - coreLogic.sessionScope(userId) { - combine(observeSyncState(), coreLogic.networkStateObserver.observeNetworkState()) { syncState, networkState -> + coreLogic.get().sessionScope(userId) { + combine(observeSyncState(), coreLogic.get().networkStateObserver.observeNetworkState()) { syncState, networkState -> when (syncState) { is Waiting -> Connectivity.WaitingConnection(null, null) is Failed -> Connectivity.WaitingConnection(syncState.cause, syncState.retryDelay) @@ -82,7 +83,7 @@ class CommonTopAppBarViewModel @Inject constructor( @VisibleForTesting internal suspend fun activeCallsFlow(userId: UserId): Flow> = - coreLogic.sessionScope(userId) { + coreLogic.get().sessionScope(userId) { combine( calls.establishedCall(), calls.getIncomingCalls(), @@ -94,7 +95,7 @@ class CommonTopAppBarViewModel @Inject constructor( init { viewModelScope.launch { - coreLogic.globalScope { + coreLogic.get().globalScope { session.currentSessionFlow() .flatMapLatest { when (it) { @@ -134,7 +135,7 @@ class CommonTopAppBarViewModel @Inject constructor( state = state.copy(connectivityState = connectivityUIState) } } - coreLogic.networkStateObserver.observeNetworkState().collectLatest { + coreLogic.get().networkStateObserver.observeNetworkState().collectLatest { state = state.copy(networkState = it) } } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/drawer/HomeDrawerViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/home/drawer/HomeDrawerViewModel.kt index b2ada2a8ced..daa5303dc6b 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/drawer/HomeDrawerViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/drawer/HomeDrawerViewModel.kt @@ -31,6 +31,7 @@ import com.wire.kalium.logic.data.user.type.UserType import com.wire.kalium.logic.feature.conversation.ObserveArchivedUnreadConversationsCountUseCase import com.wire.kalium.logic.feature.server.GetTeamUrlUseCase import com.wire.kalium.logic.feature.user.ObserveSelfUserUseCase +import dagger.Lazy import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine @@ -42,10 +43,10 @@ import javax.inject.Inject @HiltViewModel class HomeDrawerViewModel @Inject constructor( val savedStateHandle: SavedStateHandle, - private val observeArchivedUnreadConversationsCount: ObserveArchivedUnreadConversationsCountUseCase, + private val observeArchivedUnreadConversationsCount: Lazy, private val observeSelfUser: ObserveSelfUserUseCase, private val getTeamUrl: GetTeamUrlUseCase, - private val globalDataStore: GlobalDataStore, + private val globalDataStore: Lazy, ) : ViewModel() { var drawerState by mutableStateOf(HomeDrawerState()) @@ -78,8 +79,8 @@ class HomeDrawerViewModel @Inject constructor( private fun buildDrawerItems() { viewModelScope.launch { combine( - globalDataStore.wireCellsEnabled(), - observeArchivedUnreadConversationsCount(), + globalDataStore.get().wireCellsEnabled(), + observeArchivedUnreadConversationsCount.get().invoke(), observeTeamManagementUrlForUser() ) { wireCellsEnabled, unreadArchiveConversationsCount, teamManagementUrl -> buildList { diff --git a/app/src/main/kotlin/com/wire/android/ui/home/sync/FeatureFlagNotificationViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/home/sync/FeatureFlagNotificationViewModel.kt index 2c851848eda..8bc69ed84a1 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/sync/FeatureFlagNotificationViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/sync/FeatureFlagNotificationViewModel.kt @@ -43,6 +43,7 @@ import com.wire.kalium.logic.feature.session.CurrentSessionResult import com.wire.kalium.logic.feature.user.E2EIRequiredResult import com.wire.kalium.common.functional.Either import com.wire.kalium.common.functional.fold +import dagger.Lazy import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.collectLatest @@ -54,10 +55,10 @@ import javax.inject.Inject @Suppress("TooManyFunctions") @HiltViewModel class FeatureFlagNotificationViewModel @Inject constructor( - @KaliumCoreLogic private val coreLogic: CoreLogic, - private val currentSessionFlow: CurrentSessionFlowUseCase, - private val globalDataStore: GlobalDataStore, - private val disableAppLockUseCase: DisableAppLockUseCase + @KaliumCoreLogic private val coreLogic: Lazy, + private val currentSessionFlow: Lazy, + private val globalDataStore: Lazy, + private val disableAppLockUseCase: Lazy, ) : ViewModel() { var featureFlagState by mutableStateOf(FeatureFlagState()) @@ -79,7 +80,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( * state. */ private suspend fun initialSync() { - currentSessionFlow() + currentSessionFlow.get().invoke() .distinctUntilChanged() .collectLatest { currentSessionResult -> when { @@ -102,7 +103,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( featureFlagState = FeatureFlagState() // new session, clear feature flag state to default and wait until synced currentSessionResult.accountInfo.userId.let { userId -> currentUserId = userId - coreLogic.getSessionScope(userId).observeSyncState() + coreLogic.get().getSessionScope(userId).observeSyncState() .firstOrNull { it == SyncState.Live }?.let { observeStatesAfterInitialSync(userId) } @@ -125,13 +126,13 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun observeShouldNotifyForRevokedCertificate(userId: UserId) { - coreLogic.getSessionScope(userId).observeShouldNotifyForRevokedCertificate().collect { + coreLogic.get().getSessionScope(userId).observeShouldNotifyForRevokedCertificate().collect { featureFlagState = featureFlagState.copy(shouldShowE2eiCertificateRevokedDialog = it) } } private suspend fun setFileSharingState(userId: UserId) { - coreLogic.getSessionScope(userId).observeFileSharingStatus().collect { fileSharingStatus -> + coreLogic.get().getSessionScope(userId).observeFileSharingStatus().collect { fileSharingStatus -> val state: FeatureFlagState.FileSharingState = fileSharingStatus.state.toFeatureFlagState() featureFlagState = featureFlagState.copy( isFileSharingState = state, @@ -141,7 +142,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun setGuestRoomLinkFeatureFlag(userId: UserId) { - coreLogic.getSessionScope(userId).observeGuestRoomLinkFeatureFlag() + coreLogic.get().getSessionScope(userId).observeGuestRoomLinkFeatureFlag() .collect { guestRoomLinkStatus -> guestRoomLinkStatus.isGuestRoomLinkEnabled?.let { featureFlagState = featureFlagState.copy(isGuestRoomLinkEnabled = it) @@ -153,7 +154,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun setTeamAppLockFeatureFlag(userId: UserId) { - coreLogic.getSessionScope(userId).appLockTeamFeatureConfigObserver() + coreLogic.get().getSessionScope(userId).appLockTeamFeatureConfigObserver() .distinctUntilChanged() .collectLatest { appLockConfig -> appLockConfig?.isStatusChanged?.let { isStatusChanged -> @@ -172,7 +173,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun observeTeamSettingsSelfDeletionStatus(userId: UserId) { - coreLogic.getSessionScope(userId).observeTeamSettingsSelfDeletionStatus() + coreLogic.get().getSessionScope(userId).observeTeamSettingsSelfDeletionStatus() .collect { teamSettingsSelfDeletingStatus -> val areSelfDeletedMessagesEnabled = teamSettingsSelfDeletingStatus.enforcedSelfDeletionTimer !is TeamSelfDeleteTimer.Disabled @@ -196,7 +197,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun setE2EIRequiredState(userId: UserId) { - coreLogic.getSessionScope(userId).observeE2EIRequired().collect { result -> + coreLogic.get().getSessionScope(userId).observeE2EIRequired().collect { result -> val state = when (result) { E2EIRequiredResult.NoGracePeriod.Create -> FeatureFlagState.E2EIRequired.NoGracePeriod.Create E2EIRequiredResult.NoGracePeriod.Renew -> FeatureFlagState.E2EIRequired.NoGracePeriod.Renew @@ -215,7 +216,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun observeCallEndedBecauseOfConversationDegraded(userId: UserId) = - coreLogic.getSessionScope(userId).calls.observeEndCallDueToDegradationDialog().collect { + coreLogic.get().getSessionScope(userId).calls.observeEndCallDueToDegradationDialog().collect { featureFlagState = featureFlagState.copy(showCallEndedBecauseOfConversationDegraded = true) } @@ -223,7 +224,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( featureFlagState = featureFlagState.copy(shouldShowSelfDeletingMessagesDialog = false) viewModelScope.launch { currentUserId?.let { - coreLogic.getSessionScope(it).markSelfDeletingMessagesAsNotified() + coreLogic.get().getSessionScope(it).markSelfDeletingMessagesAsNotified() } } } @@ -232,7 +233,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( featureFlagState = featureFlagState.copy(shouldShowE2eiCertificateRevokedDialog = false) currentUserId?.let { viewModelScope.launch { - coreLogic.getSessionScope(it).markNotifyForRevokedCertificateAsNotified() + coreLogic.get().getSessionScope(it).markNotifyForRevokedCertificateAsNotified() } } } @@ -240,14 +241,14 @@ class FeatureFlagNotificationViewModel @Inject constructor( fun dismissFileSharingDialog() { featureFlagState = featureFlagState.copy(showFileSharingDialog = false) viewModelScope.launch { - currentUserId?.let { coreLogic.getSessionScope(it).markFileSharingStatusAsNotified() } + currentUserId?.let { coreLogic.get().getSessionScope(it).markFileSharingStatusAsNotified() } } } fun dismissGuestRoomLinkDialog() { viewModelScope.launch { currentUserId?.let { - coreLogic.getSessionScope(it).markGuestLinkFeatureFlagAsNotChanged() + coreLogic.get().getSessionScope(it).markGuestLinkFeatureFlagAsNotChanged() } } featureFlagState = featureFlagState.copy(shouldShowGuestRoomLinkDialog = false) @@ -260,22 +261,22 @@ class FeatureFlagNotificationViewModel @Inject constructor( fun markTeamAppLockStatusAsNot() { viewModelScope.launch { currentUserId?.let { - coreLogic.getSessionScope(it).markTeamAppLockStatusAsNotified() + coreLogic.get().getSessionScope(it).markTeamAppLockStatusAsNotified() } } } fun confirmAppLockNotEnforced() { viewModelScope.launch { - when (globalDataStore.getAppLockSource()) { + when (globalDataStore.get().getAppLockSource()) { AppLockSource.Manual -> {} - AppLockSource.TeamEnforced -> disableAppLockUseCase() + AppLockSource.TeamEnforced -> disableAppLockUseCase.get().invoke() } } } - fun isUserAppLockSet() = globalDataStore.isAppLockPasscodeSet() + fun isUserAppLockSet() = globalDataStore.get().isAppLockPasscodeSet() fun enrollE2EICertificate() { featureFlagState = featureFlagState.copy(isE2EILoading = true, startGettingE2EICertificate = true) @@ -317,7 +318,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( ) currentUserId?.let { userId -> viewModelScope.launch { - coreLogic.getSessionScope(userId).markE2EIRequiredAsNotified(result.timeLeft) + coreLogic.get().getSessionScope(userId).markE2EIRequiredAsNotified(result.timeLeft) } } } diff --git a/app/src/main/kotlin/com/wire/android/ui/legalhold/dialog/deactivated/LegalHoldDeactivatedViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/legalhold/dialog/deactivated/LegalHoldDeactivatedViewModel.kt index 70abb98acd3..4772de0a0c5 100644 --- a/app/src/main/kotlin/com/wire/android/ui/legalhold/dialog/deactivated/LegalHoldDeactivatedViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/legalhold/dialog/deactivated/LegalHoldDeactivatedViewModel.kt @@ -31,6 +31,7 @@ import com.wire.kalium.logic.feature.legalhold.LegalHoldState import com.wire.kalium.logic.feature.legalhold.MarkLegalHoldChangeAsNotifiedForSelfUseCase import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldChangeNotifiedForSelfUseCase import com.wire.kalium.logic.feature.session.CurrentSessionResult +import dagger.Lazy import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collectLatest @@ -42,14 +43,14 @@ import javax.inject.Inject @HiltViewModel class LegalHoldDeactivatedViewModel @Inject constructor( - @KaliumCoreLogic private val coreLogic: CoreLogic + @KaliumCoreLogic private val coreLogic: Lazy ) : ViewModel() { var state: LegalHoldDeactivatedState by mutableStateOf(LegalHoldDeactivatedState.Hidden) private set private fun currentSessionFlow(noSession: T, session: suspend UserSessionScope.(UserId) -> Flow): Flow = - coreLogic.getGlobalScope().session.currentSessionFlow() + coreLogic.get().getGlobalScope().session.currentSessionFlow() .flatMapLatest { currentSessionResult -> when (currentSessionResult) { is CurrentSessionResult.Failure.Generic -> { @@ -59,7 +60,7 @@ class LegalHoldDeactivatedViewModel @Inject constructor( CurrentSessionResult.Failure.SessionNotFound -> flowOf(noSession) is CurrentSessionResult.Success -> - currentSessionResult.accountInfo.userId.let { coreLogic.getSessionScope(it).session(it) } + currentSessionResult.accountInfo.userId.let { coreLogic.get().getSessionScope(it).session(it) } } } @@ -78,7 +79,7 @@ class LegalHoldDeactivatedViewModel @Inject constructor( when (it.legalHoldState) { is LegalHoldState.Disabled -> LegalHoldDeactivatedState.Visible(userId) is LegalHoldState.Enabled -> { // for enabled we don't show the dialog, just mark as already notified - coreLogic.getSessionScope(userId).markLegalHoldChangeAsNotifiedForSelf() + coreLogic.get().getSessionScope(userId).markLegalHoldChangeAsNotifiedForSelf() LegalHoldDeactivatedState.Hidden } } @@ -91,7 +92,7 @@ class LegalHoldDeactivatedViewModel @Inject constructor( fun dismiss() { viewModelScope.launch { (state as? LegalHoldDeactivatedState.Visible)?.let { - coreLogic.getSessionScope(it.userId).markLegalHoldChangeAsNotifiedForSelf().let { + coreLogic.get().getSessionScope(it.userId).markLegalHoldChangeAsNotifiedForSelf().let { if (it is MarkLegalHoldChangeAsNotifiedForSelfUseCase.Result.Success) { state = LegalHoldDeactivatedState.Hidden } diff --git a/app/src/main/kotlin/com/wire/android/ui/legalhold/dialog/requested/LegalHoldRequestedViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/legalhold/dialog/requested/LegalHoldRequestedViewModel.kt index aa798693b6e..c07fc4aaca1 100644 --- a/app/src/main/kotlin/com/wire/android/ui/legalhold/dialog/requested/LegalHoldRequestedViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/legalhold/dialog/requested/LegalHoldRequestedViewModel.kt @@ -35,6 +35,7 @@ import com.wire.kalium.logic.feature.legalhold.ApproveLegalHoldRequestUseCase import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldRequestUseCase import com.wire.kalium.logic.feature.session.CurrentSessionResult import com.wire.kalium.logic.feature.user.IsPasswordRequiredUseCase +import dagger.Lazy import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted @@ -50,7 +51,7 @@ import javax.inject.Inject @HiltViewModel class LegalHoldRequestedViewModel @Inject constructor( private val validatePassword: ValidatePasswordUseCase, - @KaliumCoreLogic private val coreLogic: CoreLogic + @KaliumCoreLogic private val coreLogic: Lazy ) : ViewModel() { val passwordTextState: TextFieldState = TextFieldState() @@ -91,7 +92,7 @@ class LegalHoldRequestedViewModel @Inject constructor( }.stateIn(viewModelScope, SharingStarted.Eagerly, LegalHoldRequestData.None) private fun currentSessionFlow(noSession: T, session: UserSessionScope.(UserId) -> Flow): Flow = - coreLogic.getGlobalScope().session.currentSessionFlow() + coreLogic.get().getGlobalScope().session.currentSessionFlow() .flatMapLatest { currentSessionResult -> when (currentSessionResult) { is CurrentSessionResult.Failure.Generic -> { @@ -101,7 +102,7 @@ class LegalHoldRequestedViewModel @Inject constructor( CurrentSessionResult.Failure.SessionNotFound -> flowOf(noSession) is CurrentSessionResult.Success -> - currentSessionResult.accountInfo.userId.let { coreLogic.getSessionScope(it).session(it) } + currentSessionResult.accountInfo.userId.let { coreLogic.get().getSessionScope(it).session(it) } } } @@ -154,7 +155,7 @@ class LegalHoldRequestedViewModel @Inject constructor( } else { val password = if (it.requiresPassword) passwordTextState.text.toString() else null viewModelScope.launch { - coreLogic.sessionScope(it.userId) { + coreLogic.get().sessionScope(it.userId) { approveLegalHoldRequest(password).let { approveLegalHoldResult -> state = when (approveLegalHoldResult) { is ApproveLegalHoldRequestUseCase.Result.Success -> diff --git a/app/src/test/kotlin/com/wire/android/navigation/LoginTypeSelectorTest.kt b/app/src/test/kotlin/com/wire/android/navigation/LoginTypeSelectorTest.kt index fe0762acc5e..3c5b813924d 100644 --- a/app/src/test/kotlin/com/wire/android/navigation/LoginTypeSelectorTest.kt +++ b/app/src/test/kotlin/com/wire/android/navigation/LoginTypeSelectorTest.kt @@ -102,7 +102,10 @@ class LoginTypeSelectorTest { MockKAnnotations.init(this, relaxUnitFun = true) } - fun arrange(useNewLoginForDefaultBackend: Boolean) = this to LoginTypeSelector(coreLogic, useNewLoginForDefaultBackend) + fun arrange(useNewLoginForDefaultBackend: Boolean) = this to LoginTypeSelector( + coreLogic = { coreLogic }, + useNewLoginForDefaultBackend = useNewLoginForDefaultBackend + ) fun withContextFlowForConfig(config: ServerConfig.Links, contextFlow: Flow) = apply { coEvery { coreLogic.getGlobalScope().observeLoginContext(config) } returns contextFlow diff --git a/app/src/test/kotlin/com/wire/android/ui/CallFeedbackViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/CallFeedbackViewModelTest.kt index 4ec3d7bf283..3ae45afc188 100644 --- a/app/src/test/kotlin/com/wire/android/ui/CallFeedbackViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/CallFeedbackViewModelTest.kt @@ -160,10 +160,10 @@ class CallFeedbackViewModelTest { val viewModel: CallFeedbackViewModel by lazy { CallFeedbackViewModel( - coreLogic = coreLogic, - currentSessionFlow = currentSessionFlow, - isAnalyticsAvailable = isAnalyticsAvailable, - analyticsManager = analyticsManager + coreLogic = { coreLogic }, + currentSessionFlow = { currentSessionFlow }, + isAnalyticsAvailable = { isAnalyticsAvailable }, + analyticsManager = { analyticsManager }, ) } diff --git a/app/src/test/kotlin/com/wire/android/ui/WireActivityViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/WireActivityViewModelTest.kt index 5266539093d..0216b4a8d21 100644 --- a/app/src/test/kotlin/com/wire/android/ui/WireActivityViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/WireActivityViewModelTest.kt @@ -845,7 +845,7 @@ class WireActivityViewModelTest { private val viewModel by lazy { WireActivityViewModel( - coreLogic = coreLogic, + coreLogic = { coreLogic }, dispatchers = TestDispatcherProvider(), currentSessionFlow = { currentSessionFlow }, doesValidSessionExist = { doesValidSessionExist }, diff --git a/app/src/test/kotlin/com/wire/android/ui/analytics/AnalyticsUsageViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/analytics/AnalyticsUsageViewModelTest.kt index 7af6ee33894..a40c6e5a141 100644 --- a/app/src/test/kotlin/com/wire/android/ui/analytics/AnalyticsUsageViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/analytics/AnalyticsUsageViewModelTest.kt @@ -124,8 +124,8 @@ class AnalyticsUsageViewModelTest { fun arrange(analyticsConfiguration: AnalyticsConfiguration) = this to AnalyticsUsageViewModel( analyticsEnabled = analyticsConfiguration, - dataStore = dataStore, - selfServerConfig = selfServerConfig + dataStore = { dataStore }, + selfServerConfig = { selfServerConfig }, ) } diff --git a/app/src/test/kotlin/com/wire/android/ui/common/topappbar/CommonTopAppBarViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/common/topappbar/CommonTopAppBarViewModelTest.kt index c804748e0cc..6a2a3ac4558 100644 --- a/app/src/test/kotlin/com/wire/android/ui/common/topappbar/CommonTopAppBarViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/common/topappbar/CommonTopAppBarViewModelTest.kt @@ -334,7 +334,7 @@ class CommonTopAppBarViewModelTest { private val commonTopAppBarViewModel by lazy { CommonTopAppBarViewModel( currentScreenManager = currentScreenManager, - coreLogic = coreLogic + coreLogic = { coreLogic }, ) } diff --git a/app/src/test/kotlin/com/wire/android/ui/home/drawer/HomeDrawerViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/drawer/HomeDrawerViewModelTest.kt index c4295d29c82..447c01632cf 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/drawer/HomeDrawerViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/drawer/HomeDrawerViewModelTest.kt @@ -125,10 +125,10 @@ class HomeDrawerViewModelTest { fun arrange() = this to HomeDrawerViewModel( savedStateHandle = savedStateHandle, - observeArchivedUnreadConversationsCount = observeArchivedUnreadConversationsCount, - globalDataStore = globalDataStore, + observeArchivedUnreadConversationsCount = { observeArchivedUnreadConversationsCount }, + globalDataStore = { globalDataStore }, observeSelfUser = observeSelfUserUseCase, - getTeamUrl = getTeamUrlUseCase + getTeamUrl = getTeamUrlUseCase, ) companion object { diff --git a/app/src/test/kotlin/com/wire/android/ui/home/sync/FeatureFlagNotificationViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/sync/FeatureFlagNotificationViewModelTest.kt index 17e690850db..740d2dd875c 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/sync/FeatureFlagNotificationViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/sync/FeatureFlagNotificationViewModelTest.kt @@ -328,10 +328,10 @@ class FeatureFlagNotificationViewModelTest { val viewModel: FeatureFlagNotificationViewModel by lazy { FeatureFlagNotificationViewModel( - coreLogic = coreLogic, - currentSessionFlow = currentSessionFlow, - globalDataStore = globalDataStore, - disableAppLockUseCase = disableAppLockUseCase + coreLogic = { coreLogic }, + currentSessionFlow = { currentSessionFlow }, + globalDataStore = { globalDataStore }, + disableAppLockUseCase = { disableAppLockUseCase }, ) } diff --git a/app/src/test/kotlin/com/wire/android/ui/legalhold/dialog/deactivated/LegalHoldDeactivatedViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/legalhold/dialog/deactivated/LegalHoldDeactivatedViewModelTest.kt index fe8824f3d27..6d72fc9984f 100644 --- a/app/src/test/kotlin/com/wire/android/ui/legalhold/dialog/deactivated/LegalHoldDeactivatedViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/legalhold/dialog/deactivated/LegalHoldDeactivatedViewModelTest.kt @@ -107,7 +107,7 @@ class LegalHoldDeactivatedViewModelTest { @MockK lateinit var coreLogic: CoreLogic - val viewModel by lazy { LegalHoldDeactivatedViewModel(coreLogic = coreLogic) } + val viewModel by lazy { LegalHoldDeactivatedViewModel(coreLogic = { coreLogic }) } init { MockKAnnotations.init(this) } fun withNotCurrentSession() = apply { diff --git a/app/src/test/kotlin/com/wire/android/ui/legalhold/dialog/requested/LegalHoldRequestedViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/legalhold/dialog/requested/LegalHoldRequestedViewModelTest.kt index 65851481502..30d6dab5fbe 100644 --- a/app/src/test/kotlin/com/wire/android/ui/legalhold/dialog/requested/LegalHoldRequestedViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/legalhold/dialog/requested/LegalHoldRequestedViewModelTest.kt @@ -307,7 +307,7 @@ class LegalHoldRequestedViewModelTest { val viewModel by lazy { LegalHoldRequestedViewModel( validatePassword = validatePassword, - coreLogic = coreLogic + coreLogic = { coreLogic }, ) }