Code review

This commit is contained in:
Valere 2021-09-23 09:52:20 +02:00
parent 195fb6f6fc
commit 9b02704d5b
1 changed files with 26 additions and 25 deletions

View File

@ -36,6 +36,7 @@ import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.peeking.PeekResult import org.matrix.android.sdk.api.session.room.peeking.PeekResult
class SpaceInviteBottomSheetViewModel @AssistedInject constructor( class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
@ -46,7 +47,6 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
init { init {
session.getRoomSummary(initialState.spaceId)?.let { roomSummary -> session.getRoomSummary(initialState.spaceId)?.let { roomSummary ->
val knownMembers = roomSummary.otherMemberIds.filter { val knownMembers = roomSummary.otherMemberIds.filter {
session.getExistingDirectRoomWithUser(it) != null session.getExistingDirectRoomWithUser(it) != null
}.mapNotNull { session.getUser(it) } }.mapNotNull { session.getUser(it) }
@ -61,12 +61,15 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
peopleYouKnow = Success(peopleYouKnow) peopleYouKnow = Success(peopleYouKnow)
) )
} }
refreshInviteSummaryIfNeeded(roomSummary)
}
}
private fun refreshInviteSummaryIfNeeded(roomSummary: RoomSummary) {
if (roomSummary.membership == Membership.INVITE) { if (roomSummary.membership == Membership.INVITE) {
// we can try to query the room summary api to get more info? // we can try to query the room summary api to get more info?
viewModelScope.launch { viewModelScope.launch(Dispatchers.IO) {
tryOrNull { session.peekRoom(roomSummary.roomId) }?.let { peekResult -> when (val peekResult = tryOrNull { session.peekRoom(roomSummary.roomId) }) {
when (peekResult) {
is PeekResult.Success -> { is PeekResult.Success -> {
setState { setState {
copy( copy(
@ -86,9 +89,7 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
} }
} }
else -> { else -> {
// // nop
}
}
} }
} }
} }