mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-29 06:28:45 +03:00
Fix sending multiple invites to a room reaching only one or two people
This commit is contained in:
parent
4094a66f3c
commit
96e3544a47
2 changed files with 33 additions and 32 deletions
1
changelog.d/6109.bugfix
Normal file
1
changelog.d/6109.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix sending multiple invites to a room reaching only one or two people
|
|
@ -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,39 +56,38 @@ 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 ->
|
when (user) {
|
||||||
when (user) {
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.catch { cause ->
|
}.onCompletion { error ->
|
||||||
_viewEvents.post(InviteUsersToRoomViewEvents.Failure(cause))
|
if (error != null) return@onCompletion
|
||||||
|
|
||||||
|
val successMessage = when (selections.size) {
|
||||||
|
1 -> stringProvider.getString(
|
||||||
|
R.string.invitation_sent_to_one_user,
|
||||||
|
selections.first().getBestName()
|
||||||
|
)
|
||||||
|
2 -> stringProvider.getString(
|
||||||
|
R.string.invitations_sent_to_two_users,
|
||||||
|
selections.first().getBestName(),
|
||||||
|
selections.last().getBestName()
|
||||||
|
)
|
||||||
|
else -> stringProvider.getQuantityString(
|
||||||
|
R.plurals.invitations_sent_to_one_and_more_users,
|
||||||
|
selections.size - 1,
|
||||||
|
selections.first().getBestName(),
|
||||||
|
selections.size - 1
|
||||||
|
)
|
||||||
}
|
}
|
||||||
.collect {
|
_viewEvents.post(InviteUsersToRoomViewEvents.Success(successMessage))
|
||||||
val successMessage = when (selections.size) {
|
}
|
||||||
1 -> stringProvider.getString(
|
.catch { cause ->
|
||||||
R.string.invitation_sent_to_one_user,
|
_viewEvents.post(InviteUsersToRoomViewEvents.Failure(cause))
|
||||||
selections.first().getBestName()
|
}.launchIn(viewModelScope)
|
||||||
)
|
|
||||||
2 -> stringProvider.getString(
|
|
||||||
R.string.invitations_sent_to_two_users,
|
|
||||||
selections.first().getBestName(),
|
|
||||||
selections.last().getBestName()
|
|
||||||
)
|
|
||||||
else -> stringProvider.getQuantityString(
|
|
||||||
R.plurals.invitations_sent_to_one_and_more_users,
|
|
||||||
selections.size - 1,
|
|
||||||
selections.first().getBestName(),
|
|
||||||
selections.size - 1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
_viewEvents.post(InviteUsersToRoomViewEvents.Success(successMessage))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUserIdsOfRoomMembers(): Set<String> {
|
fun getUserIdsOfRoomMembers(): Set<String> {
|
||||||
|
|
Loading…
Reference in a new issue