Skip to content

Commit 73129c3

Browse files
committed
Fix: Always provide an updated user for crash logging purposes
PR Comment: #1731 #discussion_r2231064987
1 parent 07f4baa commit 73129c3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Simplenote/src/main/java/com/automattic/simplenote/utils/crashlogging/SimplenoteCrashLoggingDataProvider.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.automattic.simplenote.utils.crashlogging
22

3+
import android.util.Log
34
import com.automattic.android.tracks.crashlogging.CrashLoggingDataProvider
45
import com.automattic.android.tracks.crashlogging.CrashLoggingUser
56
import com.automattic.android.tracks.crashlogging.EventLevel
@@ -11,13 +12,14 @@ import com.automattic.simplenote.Simplenote
1112
import com.automattic.simplenote.utils.locale.LocaleProvider
1213
import com.simperium.client.User
1314
import kotlinx.coroutines.flow.Flow
14-
import kotlinx.coroutines.flow.MutableStateFlow
15+
import kotlinx.coroutines.flow.catch
1516
import kotlinx.coroutines.flow.emptyFlow
17+
import kotlinx.coroutines.flow.flow
1618
import java.util.Locale
1719
import javax.inject.Inject
1820

1921
class SimplenoteCrashLoggingDataProvider @Inject constructor(
20-
app: Simplenote,
22+
private val app: Simplenote,
2123
private val localeProvider: LocaleProvider,
2224
) : CrashLoggingDataProvider {
2325

@@ -34,7 +36,8 @@ class SimplenoteCrashLoggingDataProvider @Inject constructor(
3436
ReleaseName.SetByTracksLibrary
3537
}
3638

37-
override val user: Flow<CrashLoggingUser?> = MutableStateFlow(app.simperium?.user?.toCrashLoggingUser())
39+
override val user: Flow<CrashLoggingUser?>
40+
get() = provideUser()
3841

3942
override val applicationContextProvider: Flow<Map<String, String>> = emptyFlow()
4043

@@ -60,6 +63,14 @@ class SimplenoteCrashLoggingDataProvider @Inject constructor(
6063
return false
6164
}
6265

66+
private fun provideUser(): Flow<CrashLoggingUser?> =
67+
flow {
68+
emit(app.simperium?.user?.toCrashLoggingUser())
69+
}.catch { e ->
70+
Log.e(TAG, "Exception getting the user", e)
71+
emit(null)
72+
}
73+
6374
private fun User.toCrashLoggingUser(): CrashLoggingUser? {
6475
if (userId.isNullOrEmpty()) return null
6576

@@ -71,6 +82,7 @@ class SimplenoteCrashLoggingDataProvider @Inject constructor(
7182
}
7283

7384
companion object {
74-
const val DEBUG_RELEASE_NAME = "debug"
85+
private const val DEBUG_RELEASE_NAME = "debug"
86+
private val TAG: String = SimplenoteCrashLoggingDataProvider::class.java.getSimpleName()
7587
}
7688
}

0 commit comments

Comments
 (0)