Code review
This commit is contained in:
parent
195fb6f6fc
commit
9b02704d5b
|
@ -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,35 +61,36 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
|
||||||
peopleYouKnow = Success(peopleYouKnow)
|
peopleYouKnow = Success(peopleYouKnow)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
refreshInviteSummaryIfNeeded(roomSummary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (roomSummary.membership == Membership.INVITE) {
|
private fun refreshInviteSummaryIfNeeded(roomSummary: RoomSummary) {
|
||||||
// we can try to query the room summary api to get more info?
|
if (roomSummary.membership == Membership.INVITE) {
|
||||||
viewModelScope.launch {
|
// we can try to query the room summary api to get more info?
|
||||||
tryOrNull { session.peekRoom(roomSummary.roomId) }?.let { peekResult ->
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
when (peekResult) {
|
when (val peekResult = tryOrNull { session.peekRoom(roomSummary.roomId) }) {
|
||||||
is PeekResult.Success -> {
|
is PeekResult.Success -> {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
summary = Success(
|
summary = Success(
|
||||||
roomSummary.copy(
|
roomSummary.copy(
|
||||||
joinedMembersCount = peekResult.numJoinedMembers,
|
joinedMembersCount = peekResult.numJoinedMembers,
|
||||||
// it's also possible that the name/avatar did change since the invite..
|
// it's also possible that the name/avatar did change since the invite..
|
||||||
// if it's null keep the old one as summary API might not be available
|
// if it's null keep the old one as summary API might not be available
|
||||||
// and peek result could be null for other reasons (not peekable)
|
// and peek result could be null for other reasons (not peekable)
|
||||||
avatarUrl = peekResult.avatarUrl ?: roomSummary.avatarUrl,
|
avatarUrl = peekResult.avatarUrl ?: roomSummary.avatarUrl,
|
||||||
displayName = peekResult.name ?: roomSummary.displayName,
|
displayName = peekResult.name ?: roomSummary.displayName,
|
||||||
topic = peekResult.topic ?: roomSummary.topic
|
topic = peekResult.topic ?: roomSummary.topic
|
||||||
// maybe use someMembers field later?
|
// maybe use someMembers field later?
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else -> {
|
||||||
|
// nop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue