Small cleanup

This commit is contained in:
Benoit Marty 2021-12-31 15:48:08 +01:00
parent 6d8b5db18e
commit 96d5652fcd
2 changed files with 5 additions and 6 deletions

View File

@ -29,12 +29,12 @@ import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.flow.flow import org.matrix.android.sdk.flow.flow
import org.matrix.android.sdk.flow.unwrap
import timber.log.Timber import timber.log.Timber
data class DummyState( data class DummyState(
@ -60,8 +60,8 @@ class UserColorAccountDataViewModel @AssistedInject constructor(
private fun observeAccountData() { private fun observeAccountData() {
session.flow() session.flow()
.liveUserAccountData(setOf(UserAccountDataTypes.TYPE_OVERRIDE_COLORS)) .liveUserAccountData(UserAccountDataTypes.TYPE_OVERRIDE_COLORS)
.mapNotNull { it.firstOrNull() } .unwrap()
.map { it.content.toModel<Map<String, String>>() } .map { it.content.toModel<Map<String, String>>() }
.onEach { userColorAccountDataContent -> .onEach { userColorAccountDataContent ->
if (userColorAccountDataContent == null) { if (userColorAccountDataContent == null) {

View File

@ -39,7 +39,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -131,8 +130,8 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
private fun observeAccountData() { private fun observeAccountData() {
session.flow() session.flow()
.liveUserAccountData(setOf(UserAccountDataTypes.TYPE_OVERRIDE_COLORS)) .liveUserAccountData(UserAccountDataTypes.TYPE_OVERRIDE_COLORS)
.mapNotNull { it.firstOrNull() } .unwrap()
.map { it.content.toModel<Map<String, String>>() } .map { it.content.toModel<Map<String, String>>() }
.map { userColorAccountDataContent -> .map { userColorAccountDataContent ->
userColorAccountDataContent?.get(initialState.userId) userColorAccountDataContent?.get(initialState.userId)