Cleanup and add changelog

This commit is contained in:
Benoit Marty 2021-09-24 15:38:08 +02:00
parent 9b02704d5b
commit 3287980109
2 changed files with 26 additions and 28 deletions

1
changelog.d/4057.feature Normal file
View file

@ -0,0 +1 @@
Improve space invite bottom sheet

View file

@ -61,38 +61,35 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
peopleYouKnow = Success(peopleYouKnow)
)
}
refreshInviteSummaryIfNeeded(roomSummary)
if (roomSummary.membership == Membership.INVITE) {
getLatestRoomSummary(roomSummary)
}
}
}
private fun refreshInviteSummaryIfNeeded(roomSummary: RoomSummary) {
if (roomSummary.membership == Membership.INVITE) {
// we can try to query the room summary api to get more info?
viewModelScope.launch(Dispatchers.IO) {
when (val peekResult = tryOrNull { session.peekRoom(roomSummary.roomId) }) {
is PeekResult.Success -> {
setState {
copy(
summary = Success(
roomSummary.copy(
joinedMembersCount = peekResult.numJoinedMembers,
// 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
// and peek result could be null for other reasons (not peekable)
avatarUrl = peekResult.avatarUrl ?: roomSummary.avatarUrl,
displayName = peekResult.name ?: roomSummary.displayName,
topic = peekResult.topic ?: roomSummary.topic
// maybe use someMembers field later?
)
)
)
}
}
else -> {
// nop
}
}
/**
* Try to request the room summary api to get more info
*/
private fun getLatestRoomSummary(roomSummary: RoomSummary) {
viewModelScope.launch(Dispatchers.IO) {
val peekResult = tryOrNull { session.peekRoom(roomSummary.roomId) } as? PeekResult.Success ?: return@launch
setState {
copy(
summary = Success(
roomSummary.copy(
joinedMembersCount = peekResult.numJoinedMembers,
// 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
// and peek result could be null for other reasons (not peekable)
avatarUrl = peekResult.avatarUrl ?: roomSummary.avatarUrl,
displayName = peekResult.name ?: roomSummary.displayName,
topic = peekResult.topic ?: roomSummary.topic
// maybe use someMembers field later?
)
)
)
}
}
}