Skip to content

Commit

Permalink
fix: self-deleting msg in doze mode on ConversationScreen [WPB-5894] (#…
Browse files Browse the repository at this point in the history
…2642)

Co-authored-by: Yamil Medina <yamilmedina@users.noreply.github.com>
  • Loading branch information
saleniuk and yamilmedina committed Jan 31, 2024
1 parent 51c465e commit 0c41348
Show file tree
Hide file tree
Showing 6 changed files with 403 additions and 256 deletions.
199 changes: 119 additions & 80 deletions app/src/androidTest/java/com/wire/android/SelfDeletionTimerTest.kt

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions app/src/main/kotlin/com/wire/android/GlobalObserversManager.kt
Expand Up @@ -22,11 +22,13 @@ import com.wire.android.datastore.UserDataStoreProvider
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.notification.NotificationChannelsManager
import com.wire.android.notification.WireNotificationManager
import com.wire.android.util.CurrentScreenManager
import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.logout.LogoutReason
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.auth.LogoutCallback
import com.wire.kalium.logic.feature.session.CurrentSessionResult
import com.wire.kalium.logic.feature.user.webSocketStatus.ObservePersistentWebSocketConnectionStatusUseCase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
Expand All @@ -35,8 +37,12 @@ import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton
Expand All @@ -52,6 +58,7 @@ class GlobalObserversManager @Inject constructor(
private val notificationManager: WireNotificationManager,
private val notificationChannelsManager: NotificationChannelsManager,
private val userDataStoreProvider: UserDataStoreProvider,
private val currentScreenManager: CurrentScreenManager,
) {
private val scope = CoroutineScope(SupervisorJob() + dispatcherProvider.io())

Expand All @@ -65,6 +72,7 @@ class GlobalObserversManager @Inject constructor(
}
}
scope.handleLogouts()
scope.handleDeleteEphemeralMessageEndDate()
}

private suspend fun setUpNotifications() {
Expand Down Expand Up @@ -114,4 +122,21 @@ class GlobalObserversManager @Inject constructor(
awaitClose { coreLogic.getGlobalScope().logoutCallbackManager.unregister(callback) }
}.launchIn(this)
}

private fun CoroutineScope.handleDeleteEphemeralMessageEndDate() {
launch {
currentScreenManager.isAppVisibleFlow()
.flatMapLatest { isAppVisible ->
if (isAppVisible) {
coreLogic.getGlobalScope().session.currentSessionFlow()
.distinctUntilChanged()
.filter { it is CurrentSessionResult.Success && it.accountInfo.isValid() }
.map { (it as CurrentSessionResult.Success).accountInfo.userId }
} else {
emptyFlow()
}
}
.collect { userId -> coreLogic.getSessionScope(userId).messages.deleteEphemeralMessageEndDate() }
}
}
}

0 comments on commit 0c41348

Please sign in to comment.