Fix sending multiple invites to a room reaching only one or two people

This commit is contained in:
Jorge Martín 2022-05-20 17:47:40 +02:00
parent 4094a66f3c
commit 96e3544a47
2 changed files with 33 additions and 32 deletions

1
changelog.d/6109.bugfix Normal file
View file

@ -0,0 +1 @@
Fix sending multiple invites to a room reaching only one or two people

View file

@ -28,8 +28,9 @@ import im.vector.app.core.resources.StringProvider
import im.vector.app.features.userdirectory.PendingSelection import im.vector.app.features.userdirectory.PendingSelection
import kotlinx.coroutines.flow.asFlow import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch import kotlinx.coroutines.flow.onCompletion
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.getRoom
@ -55,7 +56,6 @@ class InviteUsersToRoomViewModel @AssistedInject constructor(
} }
private fun inviteUsersToRoom(selections: Set<PendingSelection>) { private fun inviteUsersToRoom(selections: Set<PendingSelection>) {
viewModelScope.launch {
_viewEvents.post(InviteUsersToRoomViewEvents.Loading) _viewEvents.post(InviteUsersToRoomViewEvents.Loading)
selections.asFlow() selections.asFlow()
.map { user -> .map { user ->
@ -63,11 +63,9 @@ class InviteUsersToRoomViewModel @AssistedInject constructor(
is PendingSelection.UserPendingSelection -> room.membershipService().invite(user.user.userId, null) is PendingSelection.UserPendingSelection -> room.membershipService().invite(user.user.userId, null)
is PendingSelection.ThreePidPendingSelection -> room.membershipService().invite3pid(user.threePid) is PendingSelection.ThreePidPendingSelection -> room.membershipService().invite3pid(user.threePid)
} }
} }.onCompletion { error ->
.catch { cause -> if (error != null) return@onCompletion
_viewEvents.post(InviteUsersToRoomViewEvents.Failure(cause))
}
.collect {
val successMessage = when (selections.size) { val successMessage = when (selections.size) {
1 -> stringProvider.getString( 1 -> stringProvider.getString(
R.string.invitation_sent_to_one_user, R.string.invitation_sent_to_one_user,
@ -87,7 +85,9 @@ class InviteUsersToRoomViewModel @AssistedInject constructor(
} }
_viewEvents.post(InviteUsersToRoomViewEvents.Success(successMessage)) _viewEvents.post(InviteUsersToRoomViewEvents.Success(successMessage))
} }
} .catch { cause ->
_viewEvents.post(InviteUsersToRoomViewEvents.Failure(cause))
}.launchIn(viewModelScope)
} }
fun getUserIdsOfRoomMembers(): Set<String> { fun getUserIdsOfRoomMembers(): Set<String> {