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 5569f9d52de..25b44002767 100644 --- a/app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt @@ -99,7 +99,7 @@ import javax.inject.Inject @OptIn(ExperimentalCoroutinesApi::class) @HiltViewModel class WireActivityViewModel @Inject constructor( - @KaliumCoreLogic private val coreLogic: Lazy, + @KaliumCoreLogic private val coreLogic: CoreLogic, private val dispatchers: DispatcherProvider, private val currentSessionFlow: Lazy, private val doesValidSessionExist: Lazy, @@ -309,11 +309,11 @@ class WireActivityViewModel @Inject constructor( @VisibleForTesting internal suspend fun canLoginThroughDeepLinks() = viewModelScope.async { - coreLogic.get().getGlobalScope().session.currentSession().takeIf { + coreLogic.getGlobalScope().session.currentSession().takeIf { it is CurrentSessionResult.Success }?.let { val currentUserId = (it as CurrentSessionResult.Success).accountInfo.userId - coreLogic.get().getSessionScope(currentUserId).calls.establishedCall().first().isEmpty() + coreLogic.getSessionScope(currentUserId).calls.establishedCall().first().isEmpty() } ?: true } @@ -395,11 +395,11 @@ class WireActivityViewModel @Inject constructor( switchAccountActions: SwitchAccountActions ) { viewModelScope.launch { - coreLogic.get().getGlobalScope().session.currentSession().takeIf { + coreLogic.getGlobalScope().session.currentSession().takeIf { it is CurrentSessionResult.Success }?.let { val currentUserId = (it as CurrentSessionResult.Success).accountInfo.userId - coreLogic.get().getSessionScope(currentUserId).logout(LogoutReason.SELF_HARD_LOGOUT) + coreLogic.getSessionScope(currentUserId).logout(LogoutReason.SELF_HARD_LOGOUT) clearUserData(currentUserId) } accountSwitch.get().invoke(SwitchAccountParam.TryToSwitchToNextAccount).also { @@ -475,11 +475,11 @@ class WireActivityViewModel @Inject constructor( key: String, domain: String?, onSuccess: (ConversationId) -> Unit - ) = when (val currentSession = coreLogic.get().getGlobalScope().session.currentSession()) { + ) = when (val currentSession = coreLogic.getGlobalScope().session.currentSession()) { is CurrentSessionResult.Failure.Generic -> null CurrentSessionResult.Failure.SessionNotFound -> null is CurrentSessionResult.Success -> { - coreLogic.get().sessionScope(currentSession.accountInfo.userId) { + coreLogic.sessionScope(currentSession.accountInfo.userId) { when (val result = conversations.checkIConversationInviteCode(code, key, domain)) { is CheckConversationInviteCodeUseCase.Result.Success -> { if (result.isSelfMember) { @@ -533,7 +533,7 @@ class WireActivityViewModel @Inject constructor( fun observePersistentConnectionStatus() { viewModelScope.launch { - coreLogic.get().getGlobalScope().observePersistentWebSocketConnectionStatus() + coreLogic.getGlobalScope().observePersistentWebSocketConnectionStatus() .let { result -> when (result) { is ObservePersistentWebSocketConnectionStatusUseCase.Result.Failure -> { 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 188e8bdea16..8b34b8de34a 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 @@ -32,7 +32,6 @@ import com.wire.kalium.logic.data.call.CallStatus import com.wire.kalium.logic.data.sync.SyncState import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.session.CurrentSessionResult -import dagger.Lazy import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow @@ -49,7 +48,7 @@ import javax.inject.Inject @HiltViewModel class CommonTopAppBarViewModel @Inject constructor( private val currentScreenManager: CurrentScreenManager, - @KaliumCoreLogic private val coreLogic: Lazy, + @KaliumCoreLogic private val coreLogic: CoreLogic ) : ViewModel() { var state by mutableStateOf(CommonTopAppBarState()) @@ -59,7 +58,7 @@ class CommonTopAppBarViewModel @Inject constructor( currentScreenManager.observeCurrentScreen(viewModelScope) private fun connectivityFlow(userId: UserId): Flow = - coreLogic.get().sessionScope(userId) { + coreLogic.sessionScope(userId) { observeSyncState().map { when (it) { is SyncState.Failed, SyncState.Waiting -> Connectivity.WAITING_CONNECTION @@ -71,7 +70,7 @@ class CommonTopAppBarViewModel @Inject constructor( @VisibleForTesting internal suspend fun activeCallFlow(userId: UserId): Flow = - coreLogic.get().sessionScope(userId) { + coreLogic.sessionScope(userId) { combine( calls.establishedCall(), calls.getIncomingCalls(), @@ -85,7 +84,7 @@ class CommonTopAppBarViewModel @Inject constructor( init { viewModelScope.launch { - coreLogic.get().globalScope { + coreLogic.globalScope { session.currentSessionFlow().flatMapLatest { when (it) { is CurrentSessionResult.Failure.Generic, 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 abd7bb85243..a136ff5ff50 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,7 +43,6 @@ import com.wire.kalium.logic.feature.session.CurrentSessionResult import com.wire.kalium.logic.feature.user.E2EIRequiredResult import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.fold -import dagger.Lazy import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.collectLatest @@ -55,7 +54,7 @@ import javax.inject.Inject @Suppress("TooManyFunctions") @HiltViewModel class FeatureFlagNotificationViewModel @Inject constructor( - @KaliumCoreLogic private val coreLogic: Lazy, + @KaliumCoreLogic private val coreLogic: CoreLogic, private val currentSessionFlow: CurrentSessionFlowUseCase, private val globalDataStore: GlobalDataStore, private val disableAppLockUseCase: DisableAppLockUseCase, @@ -103,7 +102,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.get().getSessionScope(userId).observeSyncState() + coreLogic.getSessionScope(userId).observeSyncState() .firstOrNull { it == SyncState.Live }?.let { observeStatesAfterInitialSync(userId) } @@ -126,13 +125,13 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun observeShouldNotifyForRevokedCertificate(userId: UserId) { - coreLogic.get().getSessionScope(userId).observeShouldNotifyForRevokedCertificate().collect { + coreLogic.getSessionScope(userId).observeShouldNotifyForRevokedCertificate().collect { featureFlagState = featureFlagState.copy(shouldShowE2eiCertificateRevokedDialog = it) } } private suspend fun setFileSharingState(userId: UserId) { - coreLogic.get().getSessionScope(userId).observeFileSharingStatus().collect { fileSharingStatus -> + coreLogic.getSessionScope(userId).observeFileSharingStatus().collect { fileSharingStatus -> val state: FeatureFlagState.FileSharingState = fileSharingStatus.state.toFeatureFlagState() featureFlagState = featureFlagState.copy( isFileSharingState = state, @@ -142,7 +141,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun setGuestRoomLinkFeatureFlag(userId: UserId) { - coreLogic.get().getSessionScope(userId).observeGuestRoomLinkFeatureFlag() + coreLogic.getSessionScope(userId).observeGuestRoomLinkFeatureFlag() .collect { guestRoomLinkStatus -> guestRoomLinkStatus.isGuestRoomLinkEnabled?.let { featureFlagState = featureFlagState.copy(isGuestRoomLinkEnabled = it) @@ -154,7 +153,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun setTeamAppLockFeatureFlag(userId: UserId) { - coreLogic.get().getSessionScope(userId).appLockTeamFeatureConfigObserver() + coreLogic.getSessionScope(userId).appLockTeamFeatureConfigObserver() .distinctUntilChanged() .collectLatest { appLockConfig -> appLockConfig?.isStatusChanged?.let { isStatusChanged -> @@ -173,7 +172,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun observeTeamSettingsSelfDeletionStatus(userId: UserId) { - coreLogic.get().getSessionScope(userId).observeTeamSettingsSelfDeletionStatus() + coreLogic.getSessionScope(userId).observeTeamSettingsSelfDeletionStatus() .collect { teamSettingsSelfDeletingStatus -> val areSelfDeletedMessagesEnabled = teamSettingsSelfDeletingStatus.enforcedSelfDeletionTimer !is TeamSelfDeleteTimer.Disabled @@ -197,7 +196,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun setE2EIRequiredState(userId: UserId) { - coreLogic.get().getSessionScope(userId).observeE2EIRequired().collect { result -> + coreLogic.getSessionScope(userId).observeE2EIRequired().collect { result -> val state = when (result) { E2EIRequiredResult.NoGracePeriod.Create -> FeatureFlagState.E2EIRequired.NoGracePeriod.Create E2EIRequiredResult.NoGracePeriod.Renew -> FeatureFlagState.E2EIRequired.NoGracePeriod.Renew @@ -216,7 +215,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( } private suspend fun observeCallEndedBecauseOfConversationDegraded(userId: UserId) = - coreLogic.get().getSessionScope(userId).calls.observeEndCallDialog().collect { + coreLogic.getSessionScope(userId).calls.observeEndCallDialog().collect { featureFlagState = featureFlagState.copy(showCallEndedBecauseOfConversationDegraded = true) } @@ -224,7 +223,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( featureFlagState = featureFlagState.copy(shouldShowSelfDeletingMessagesDialog = false) viewModelScope.launch { currentUserId?.let { - coreLogic.get().getSessionScope(it).markSelfDeletingMessagesAsNotified() + coreLogic.getSessionScope(it).markSelfDeletingMessagesAsNotified() } } } @@ -233,7 +232,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( featureFlagState = featureFlagState.copy(shouldShowE2eiCertificateRevokedDialog = false) currentUserId?.let { viewModelScope.launch { - coreLogic.get().getSessionScope(it).markNotifyForRevokedCertificateAsNotified() + coreLogic.getSessionScope(it).markNotifyForRevokedCertificateAsNotified() } } } @@ -241,14 +240,14 @@ class FeatureFlagNotificationViewModel @Inject constructor( fun dismissFileSharingDialog() { featureFlagState = featureFlagState.copy(showFileSharingDialog = false) viewModelScope.launch { - currentUserId?.let { coreLogic.get().getSessionScope(it).markFileSharingStatusAsNotified() } + currentUserId?.let { coreLogic.getSessionScope(it).markFileSharingStatusAsNotified() } } } fun dismissGuestRoomLinkDialog() { viewModelScope.launch { currentUserId?.let { - coreLogic.get().getSessionScope(it).markGuestLinkFeatureFlagAsNotChanged() + coreLogic.getSessionScope(it).markGuestLinkFeatureFlagAsNotChanged() } } featureFlagState = featureFlagState.copy(shouldShowGuestRoomLinkDialog = false) @@ -261,7 +260,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( fun markTeamAppLockStatusAsNot() { viewModelScope.launch { currentUserId?.let { - coreLogic.get().getSessionScope(it).markTeamAppLockStatusAsNotified() + coreLogic.getSessionScope(it).markTeamAppLockStatusAsNotified() } } } @@ -318,7 +317,7 @@ class FeatureFlagNotificationViewModel @Inject constructor( ) currentUserId?.let { userId -> viewModelScope.launch { - coreLogic.get().getSessionScope(userId).markE2EIRequiredAsNotified(result.timeLeft) + coreLogic.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 27ff3ee1ee2..70abb98acd3 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,7 +31,6 @@ 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 @@ -43,14 +42,14 @@ import javax.inject.Inject @HiltViewModel class LegalHoldDeactivatedViewModel @Inject constructor( - @KaliumCoreLogic private val coreLogic: Lazy, + @KaliumCoreLogic private val coreLogic: CoreLogic ) : ViewModel() { var state: LegalHoldDeactivatedState by mutableStateOf(LegalHoldDeactivatedState.Hidden) private set private fun currentSessionFlow(noSession: T, session: suspend UserSessionScope.(UserId) -> Flow): Flow = - coreLogic.get().getGlobalScope().session.currentSessionFlow() + coreLogic.getGlobalScope().session.currentSessionFlow() .flatMapLatest { currentSessionResult -> when (currentSessionResult) { is CurrentSessionResult.Failure.Generic -> { @@ -60,7 +59,7 @@ class LegalHoldDeactivatedViewModel @Inject constructor( CurrentSessionResult.Failure.SessionNotFound -> flowOf(noSession) is CurrentSessionResult.Success -> - currentSessionResult.accountInfo.userId.let { coreLogic.get().getSessionScope(it).session(it) } + currentSessionResult.accountInfo.userId.let { coreLogic.getSessionScope(it).session(it) } } } @@ -79,7 +78,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.get().getSessionScope(userId).markLegalHoldChangeAsNotifiedForSelf() + coreLogic.getSessionScope(userId).markLegalHoldChangeAsNotifiedForSelf() LegalHoldDeactivatedState.Hidden } } @@ -92,7 +91,7 @@ class LegalHoldDeactivatedViewModel @Inject constructor( fun dismiss() { viewModelScope.launch { (state as? LegalHoldDeactivatedState.Visible)?.let { - coreLogic.get().getSessionScope(it.userId).markLegalHoldChangeAsNotifiedForSelf().let { + coreLogic.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 47ae10158ea..aa798693b6e 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,7 +35,6 @@ 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 @@ -51,7 +50,7 @@ import javax.inject.Inject @HiltViewModel class LegalHoldRequestedViewModel @Inject constructor( private val validatePassword: ValidatePasswordUseCase, - @KaliumCoreLogic private val coreLogic: Lazy, + @KaliumCoreLogic private val coreLogic: CoreLogic ) : ViewModel() { val passwordTextState: TextFieldState = TextFieldState() @@ -92,7 +91,7 @@ class LegalHoldRequestedViewModel @Inject constructor( }.stateIn(viewModelScope, SharingStarted.Eagerly, LegalHoldRequestData.None) private fun currentSessionFlow(noSession: T, session: UserSessionScope.(UserId) -> Flow): Flow = - coreLogic.get().getGlobalScope().session.currentSessionFlow() + coreLogic.getGlobalScope().session.currentSessionFlow() .flatMapLatest { currentSessionResult -> when (currentSessionResult) { is CurrentSessionResult.Failure.Generic -> { @@ -102,7 +101,7 @@ class LegalHoldRequestedViewModel @Inject constructor( CurrentSessionResult.Failure.SessionNotFound -> flowOf(noSession) is CurrentSessionResult.Success -> - currentSessionResult.accountInfo.userId.let { coreLogic.get().getSessionScope(it).session(it) } + currentSessionResult.accountInfo.userId.let { coreLogic.getSessionScope(it).session(it) } } } @@ -155,7 +154,7 @@ class LegalHoldRequestedViewModel @Inject constructor( } else { val password = if (it.requiresPassword) passwordTextState.text.toString() else null viewModelScope.launch { - coreLogic.get().sessionScope(it.userId) { + coreLogic.sessionScope(it.userId) { approveLegalHoldRequest(password).let { approveLegalHoldResult -> state = when (approveLegalHoldResult) { is ApproveLegalHoldRequestUseCase.Result.Success -> 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 4ea48884853..be18bd423b9 100644 --- a/app/src/test/kotlin/com/wire/android/ui/WireActivityViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/WireActivityViewModelTest.kt @@ -756,7 +756,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/common/topappbar/CommonTopAppBarViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/common/topappbar/CommonTopAppBarViewModelTest.kt index 95cbb86ba4a..bf6b050f019 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 @@ -305,7 +305,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/sync/FeatureFlagNotificationViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/sync/FeatureFlagNotificationViewModelTest.kt index a236ae941d9..7665124d460 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,7 +328,7 @@ class FeatureFlagNotificationViewModelTest { val viewModel: FeatureFlagNotificationViewModel by lazy { FeatureFlagNotificationViewModel( - coreLogic = { coreLogic }, + 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 e3e5cd06184..77ebfe74299 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 81d2911dbe2..5fac285f255 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 @@ -308,7 +308,7 @@ class LegalHoldRequestedViewModelTest { val viewModel by lazy { LegalHoldRequestedViewModel( validatePassword = validatePassword, - coreLogic = { coreLogic } + coreLogic = coreLogic ) }