Merge pull request #4057 from vector-im/feature/bca/quick_invite_card_improvement
Improve invite bottom sheet
This commit is contained in:
commit
cde6e8cc1b
|
@ -0,0 +1 @@
|
||||||
|
Improve space invite bottom sheet
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.features.spaces.invite
|
package im.vector.app.features.spaces.invite
|
||||||
|
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
|
@ -32,7 +33,11 @@ import im.vector.app.core.platform.VectorViewModel
|
||||||
import im.vector.app.features.session.coroutineScope
|
import im.vector.app.features.session.coroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
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.RoomSummary
|
||||||
|
import org.matrix.android.sdk.api.session.room.peeking.PeekResult
|
||||||
|
|
||||||
class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
|
class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
|
||||||
@Assisted private val initialState: SpaceInviteBottomSheetState,
|
@Assisted private val initialState: SpaceInviteBottomSheetState,
|
||||||
|
@ -42,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) }
|
||||||
|
@ -57,6 +61,34 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
|
||||||
peopleYouKnow = Success(peopleYouKnow)
|
peopleYouKnow = Success(peopleYouKnow)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (roomSummary.membership == Membership.INVITE) {
|
||||||
|
getLatestRoomSummary(roomSummary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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?
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue