Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,14 +34,15 @@ import javax.inject.Singleton
*/
@Singleton
class LoginTypeSelector @Inject constructor(
@KaliumCoreLogic private val coreLogic: CoreLogic,
@KaliumCoreLogic private val coreLogic: Lazy<CoreLogic>,
@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].
Expand Down
37 changes: 19 additions & 18 deletions app/src/main/kotlin/com/wire/android/ui/CallFeedbackViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<CoreLogic>,
private val currentSessionFlow: Lazy<CurrentSessionFlowUseCase>,
private val isAnalyticsAvailable: Lazy<IsAnalyticsAvailableUseCase>,
private val analyticsManager: Lazy<AnonymousAnalyticsManager>,
) : ViewModel() {

val showCallFeedbackFlow = MutableSharedFlow<Unit>()
Expand All @@ -62,32 +63,32 @@ 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()
}
}
.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)
}

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(),
Expand All @@ -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(),
Expand All @@ -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,
Expand All @@ -136,17 +137,17 @@ class CallFeedbackViewModel @Inject constructor(
)
}
)
coreLogic.getSessionScope(it).calls.updateNextTimeCallFeedback(doNotAsk)
coreLogic.get().getSessionScope(it).calls.updateNextTimeCallFeedback(doNotAsk)
}
}
}

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(),
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
@OptIn(ExperimentalCoroutinesApi::class)
@HiltViewModel
class WireActivityViewModel @Inject constructor(
@KaliumCoreLogic private val coreLogic: CoreLogic,
@KaliumCoreLogic private val coreLogic: Lazy<CoreLogic>,
private val dispatchers: DispatcherProvider,
currentSessionFlow: Lazy<CurrentSessionFlowUseCase>,
private val doesValidSessionExist: Lazy<DoesValidSessionExistUseCase>,
Expand Down Expand Up @@ -288,11 +288,11 @@
data: InputStream
) {
viewModelScope.launch(dispatchers.io()) {
when (val currentSession = coreLogic.getGlobalScope().session.currentSession()) {
when (val currentSession = coreLogic.get().getGlobalScope().session.currentSession()) {

Check warning on line 291 in app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt#L291

Added line #L291 was not covered by tests
is CurrentSessionResult.Failure.Generic -> null
CurrentSessionResult.Failure.SessionNotFound -> null
is CurrentSessionResult.Success -> {
coreLogic.sessionScope(currentSession.accountInfo.userId) {
coreLogic.get().sessionScope(currentSession.accountInfo.userId) {

Check warning on line 295 in app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt#L295

Added line #L295 was not covered by tests
when (val result = debug.synchronizeExternalData(InputStreamReader(data).readText())) {
is SynchronizeExternalDataResult.Success -> {
appLogger.d("Synchronized external data")
Expand Down Expand Up @@ -358,11 +358,11 @@
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)

Check warning on line 365 in app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt#L365

Added line #L365 was not covered by tests
clearUserData(currentUserId)
}
accountSwitch.get().invoke(SwitchAccountParam.TryToSwitchToNextAccount).also {
Expand Down Expand Up @@ -439,11 +439,11 @@
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) {
Expand Down Expand Up @@ -485,7 +485,7 @@

fun observePersistentConnectionStatus() {
viewModelScope.launch {
coreLogic.getGlobalScope().observePersistentWebSocketConnectionStatus()
coreLogic.get().getGlobalScope().observePersistentWebSocketConnectionStatus()
.let { result ->
when (result) {
is ObservePersistentWebSocketConnectionStatusUseCase.Result.Failure -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<UserDataStore>,
private val selfServerConfig: Lazy<SelfServerConfigUseCase>,
) : 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
Expand All @@ -61,17 +62,17 @@ class AnalyticsUsageViewModel @Inject constructor(

fun agreeAnalyticsUsage() {
viewModelScope.launch {
dataStore.setIsAnonymousAnalyticsEnabled(enabled = true)
dataStore.setIsAnalyticsDialogSeen()
dataStore.get().setIsAnonymousAnalyticsEnabled(enabled = true)
dataStore.get().setIsAnalyticsDialogSeen()

hideDialog()
}
}

fun declineAnalyticsUsage() {
viewModelScope.launch {
dataStore.setIsAnonymousAnalyticsEnabled(enabled = false)
dataStore.setIsAnalyticsDialogSeen()
dataStore.get().setIsAnonymousAnalyticsEnabled(enabled = false)
dataStore.get().setIsAnalyticsDialogSeen()

hideDialog()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<CoreLogic>,
) : ViewModel() {

var state by mutableStateOf(CommonTopAppBarState())
Expand All @@ -62,8 +63,8 @@ class CommonTopAppBarViewModel @Inject constructor(
currentScreenManager.observeCurrentScreen(viewModelScope)

private fun connectivityFlow(userId: UserId): Flow<Connectivity> =
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)
Expand All @@ -82,7 +83,7 @@ class CommonTopAppBarViewModel @Inject constructor(

@VisibleForTesting
internal suspend fun activeCallsFlow(userId: UserId): Flow<List<Call>> =
coreLogic.sessionScope(userId) {
coreLogic.get().sessionScope(userId) {
combine(
calls.establishedCall(),
calls.getIncomingCalls(),
Expand All @@ -94,7 +95,7 @@ class CommonTopAppBarViewModel @Inject constructor(

init {
viewModelScope.launch {
coreLogic.globalScope {
coreLogic.get().globalScope {
session.currentSessionFlow()
.flatMapLatest {
when (it) {
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,10 +43,10 @@ import javax.inject.Inject
@HiltViewModel
class HomeDrawerViewModel @Inject constructor(
val savedStateHandle: SavedStateHandle,
private val observeArchivedUnreadConversationsCount: ObserveArchivedUnreadConversationsCountUseCase,
private val observeArchivedUnreadConversationsCount: Lazy<ObserveArchivedUnreadConversationsCountUseCase>,
private val observeSelfUser: ObserveSelfUserUseCase,
private val getTeamUrl: GetTeamUrlUseCase,
private val globalDataStore: GlobalDataStore,
private val globalDataStore: Lazy<GlobalDataStore>,
) : ViewModel() {

var drawerState by mutableStateOf(HomeDrawerState())
Expand Down Expand Up @@ -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 {
Expand Down
Loading
Loading