Use parameter wasLastSession
This commit is contained in:
committed by
Benoit Marty
parent
fdc64e9be7
commit
dae44ccab7
@@ -16,7 +16,6 @@ import im.vector.app.features.analytics.itf.VectorAnalyticsScreen
|
||||
import im.vector.app.features.analytics.plan.SuperProperties
|
||||
import im.vector.app.features.analytics.plan.UserProperties
|
||||
import io.element.android.libraries.di.annotations.AppCoroutineScope
|
||||
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||
import io.element.android.libraries.sessionstorage.api.observer.SessionListener
|
||||
import io.element.android.libraries.sessionstorage.api.observer.SessionObserver
|
||||
import io.element.android.services.analytics.api.AnalyticsService
|
||||
@@ -39,7 +38,6 @@ class DefaultAnalyticsService(
|
||||
@AppCoroutineScope
|
||||
private val coroutineScope: CoroutineScope,
|
||||
private val sessionObserver: SessionObserver,
|
||||
private val sessionStore: SessionStore,
|
||||
) : AnalyticsService, SessionListener {
|
||||
// Cache for the store values
|
||||
private val userConsent = AtomicBoolean(false)
|
||||
@@ -77,7 +75,7 @@ class DefaultAnalyticsService(
|
||||
|
||||
override suspend fun onSessionDeleted(userId: String, wasLastSession: Boolean) {
|
||||
// Delete the store when the last session is deleted
|
||||
if (sessionStore.getAllSessions().isEmpty()) {
|
||||
if (wasLastSession) {
|
||||
analyticsStore.reset()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,7 @@ import im.vector.app.features.analytics.plan.MobileScreen
|
||||
import im.vector.app.features.analytics.plan.PollEnd
|
||||
import im.vector.app.features.analytics.plan.SuperProperties
|
||||
import im.vector.app.features.analytics.plan.UserProperties
|
||||
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||
import io.element.android.libraries.sessionstorage.api.observer.SessionObserver
|
||||
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.observer.NoOpSessionObserver
|
||||
import io.element.android.services.analytics.impl.store.AnalyticsStore
|
||||
import io.element.android.services.analytics.impl.store.FakeAnalyticsStore
|
||||
@@ -178,10 +176,24 @@ class DefaultAnalyticsServiceTest {
|
||||
coroutineScope = backgroundScope,
|
||||
analyticsStore = store,
|
||||
)
|
||||
sut.onSessionDeleted("userId", false)
|
||||
sut.onSessionDeleted("userId", true)
|
||||
resetLambda.assertions().isCalledOnce()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when a session is deleted, the store is not reset if it was not the last session`() = runTest {
|
||||
val resetLambda = lambdaRecorder<Unit> { }
|
||||
val store = FakeAnalyticsStore(
|
||||
resetLambda = resetLambda,
|
||||
)
|
||||
val sut = createDefaultAnalyticsService(
|
||||
coroutineScope = backgroundScope,
|
||||
analyticsStore = store,
|
||||
)
|
||||
sut.onSessionDeleted("userId", false)
|
||||
resetLambda.assertions().isNeverCalled()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when a session is added, nothing happen`() = runTest {
|
||||
val sut = createDefaultAnalyticsService(
|
||||
@@ -260,13 +272,11 @@ class DefaultAnalyticsServiceTest {
|
||||
),
|
||||
analyticsStore: AnalyticsStore = FakeAnalyticsStore(),
|
||||
sessionObserver: SessionObserver = NoOpSessionObserver(),
|
||||
sessionStore: SessionStore = InMemorySessionStore(),
|
||||
) = DefaultAnalyticsService(
|
||||
analyticsProviders = analyticsProviders,
|
||||
analyticsStore = analyticsStore,
|
||||
coroutineScope = coroutineScope,
|
||||
sessionObserver = sessionObserver,
|
||||
sessionStore = sessionStore,
|
||||
).also {
|
||||
// Wait for the service to be ready
|
||||
delay(1)
|
||||
|
||||
Reference in New Issue
Block a user