diff --git a/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomActivity.kt b/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomActivity.kt index 08d2653ca9..839a0767d8 100644 --- a/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomActivity.kt @@ -24,7 +24,6 @@ import android.view.View import androidx.appcompat.app.AlertDialog import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.viewModel -import com.airbnb.mvrx.withState import im.vector.matrix.android.api.failure.Failure import im.vector.riotx.R import im.vector.riotx.core.di.ScreenComponent @@ -102,7 +101,7 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() { private fun renderInviteEvents(viewEvent: InviteUsersToRoomViewEvents) { when (viewEvent) { is InviteUsersToRoomViewEvents.Loading -> renderInviteLoading() - is InviteUsersToRoomViewEvents.Success -> renderInvitationSuccess() + is InviteUsersToRoomViewEvents.Success -> renderInvitationSuccess(viewEvent.successMessage) is InviteUsersToRoomViewEvents.Failure -> renderInviteFailure(viewEvent.throwable) } } @@ -125,8 +124,8 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() { .show() } - private fun renderInvitationSuccess() = withState(viewModel) { - toast(R.string.invitations_sent_successfully) + private fun renderInvitationSuccess(successMessage: String) { + toast(successMessage) finish() } diff --git a/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomViewEvents.kt index b4ecfc5a52..a76d4a4077 100644 --- a/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomViewEvents.kt +++ b/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomViewEvents.kt @@ -21,5 +21,5 @@ import im.vector.riotx.core.platform.VectorViewEvents sealed class InviteUsersToRoomViewEvents : VectorViewEvents { object Loading : InviteUsersToRoomViewEvents() data class Failure(val throwable: Throwable) : InviteUsersToRoomViewEvents() - object Success : InviteUsersToRoomViewEvents() + data class Success(val successMessage: String) : InviteUsersToRoomViewEvents() } diff --git a/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomViewModel.kt b/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomViewModel.kt index 7a01ab2baa..2d033fdf35 100644 --- a/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/invite/InviteUsersToRoomViewModel.kt @@ -24,12 +24,15 @@ import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.user.model.User import im.vector.matrix.rx.rx +import im.vector.riotx.R import im.vector.riotx.core.platform.VectorViewModel +import im.vector.riotx.core.resources.StringProvider import io.reactivex.Observable class InviteUsersToRoomViewModel @AssistedInject constructor(@Assisted initialState: InviteUsersToRoomViewState, - session: Session) + session: Session, + val stringProvider: StringProvider) : VectorViewModel(initialState) { private val room = session.getRoom(initialState.roomId)!! @@ -61,7 +64,17 @@ class InviteUsersToRoomViewModel @AssistedInject constructor(@Assisted room.rx().invite(user.userId, null) }.subscribe( { - _viewEvents.post(InviteUsersToRoomViewEvents.Success) + val successMessage = when (selectedUsers.size) { + 1 -> stringProvider.getString(R.string.invitation_sent_to_one_user, + selectedUsers.first().displayName) + 2 -> stringProvider.getString(R.string.invitations_sent_to_two_users, + selectedUsers.first().displayName, + selectedUsers.last().displayName) + else -> stringProvider.getString(R.string.invitations_sent_to_three_and_more_users, + selectedUsers.first().displayName, + selectedUsers.size - 1) + } + _viewEvents.post(InviteUsersToRoomViewEvents.Success(successMessage)) }, { _viewEvents.post(InviteUsersToRoomViewEvents.Failure(it)) diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index fb52976d3f..caaf1a6439 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -2372,7 +2372,9 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming INVITE Inviting users… Invite Users - Invitation sent successfully + Invitation sent to %1$s + Invitations sent to %1$s and %2$s + Invitations sent to %1$s and %2$d more We could not invite users. Please check the users you want to invite and try again. \ No newline at end of file