Skip to content

Commit

Permalink
Prompt the user when the invited MatrixId is not recognized (#8483)
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle committed Jun 5, 2023
1 parent 824f380 commit 07e0695
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/8468.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prompt the user when the invited MatrixId is not recognized
4 changes: 4 additions & 0 deletions library/ui-strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,8 @@
<string name="create_room_public_title">"Public"</string>
<string name="create_room_public_description">"Anyone will be able to join this room"</string>
<string name="create_room_federation_error">"The room has been created, but some invitations have not been sent for the following reason:\n\n%s"</string>
<string name="create_room_unknown_users_dialog_content">Unable to find profiles for the Matrix IDs listed below. Would you like to start a chat anyway?\n\n%s</string>
<string name="create_room_unknown_users_dialog_submit">Start chat anyway</string>

<string name="keys_backup_unable_to_get_trust_info">"An error occurred getting trust info"</string>
<string name="keys_backup_unable_to_get_keys_backup_data">"An error occurred getting keys backup data"</string>
Expand Down Expand Up @@ -2744,6 +2746,8 @@
<item quantity="other">Invitations sent to %1$s and %2$d more</item>
</plurals>
<string name="invite_users_to_room_failure">We could not invite users. Please check the users you want to invite and try again.</string>
<string name="invite_unknown_users_dialog_content">Unable to find profiles for the Matrix IDs listed below. Would you like to invite them anyway?\n\n%s</string>
<string name="invite_unknown_users_dialog_submit">Invite anyway</string>

<string name="user_code_scan">Scan a QR code</string>
<string name="user_code_share">Share my code</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import im.vector.app.features.qrcode.QrCodeScannerEvents
import im.vector.app.features.qrcode.QrCodeScannerFragment
import im.vector.app.features.qrcode.QrCodeScannerViewModel
import im.vector.app.features.qrcode.QrScannerArgs
import im.vector.app.features.userdirectory.PendingSelection
import im.vector.app.features.userdirectory.UserListFragment
import im.vector.app.features.userdirectory.UserListFragmentArgs
import im.vector.app.features.userdirectory.UserListSharedAction
Expand Down Expand Up @@ -160,7 +161,19 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
}

private fun handleOnMenuItemSubmitClick(action: UserListSharedAction.OnMenuItemSubmitClick) {
viewModel.handle(CreateDirectRoomAction.PrepareRoomWithSelectedUsers(action.selections))
val unknownUsers = action.selections.filter { it is PendingSelection.UserPendingSelection && it.isUnknownUser }
if (unknownUsers.isEmpty()) {
viewModel.handle(CreateDirectRoomAction.PrepareRoomWithSelectedUsers(action.selections))
} else {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.dialog_title_confirmation)
.setMessage(getString(R.string.create_room_unknown_users_dialog_content, unknownUsers.joinToString("\n", "") { it.getMxId() }))
.setPositiveButton(R.string.create_room_unknown_users_dialog_submit) { _, _ ->
viewModel.handle(CreateDirectRoomAction.PrepareRoomWithSelectedUsers(action.selections))
}
.setNegativeButton(R.string.action_cancel, null)
.show()
}
}

private fun renderCreateAndInviteState(state: Async<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import im.vector.app.core.utils.onPermissionDeniedSnackbar
import im.vector.app.core.utils.registerForPermissionsResult
import im.vector.app.core.utils.toast
import im.vector.app.features.contactsbook.ContactsBookFragment
import im.vector.app.features.userdirectory.PendingSelection
import im.vector.app.features.userdirectory.UserListFragment
import im.vector.app.features.userdirectory.UserListFragmentArgs
import im.vector.app.features.userdirectory.UserListSharedAction
Expand Down Expand Up @@ -94,7 +95,19 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() {
}

private fun handleOnMenuItemSubmitClick(action: UserListSharedAction.OnMenuItemSubmitClick) {
viewModel.handle(InviteUsersToRoomAction.InviteSelectedUsers(action.selections))
val unknownUsers = action.selections.filter { it is PendingSelection.UserPendingSelection && it.isUnknownUser }
if (unknownUsers.isEmpty()) {
viewModel.handle(InviteUsersToRoomAction.InviteSelectedUsers(action.selections))
} else {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.dialog_title_confirmation)
.setMessage(getString(R.string.invite_unknown_users_dialog_content, unknownUsers.joinToString("\n", "") { it.getMxId() }))
.setPositiveButton(R.string.invite_unknown_users_dialog_submit) { _, _ ->
viewModel.handle(InviteUsersToRoomAction.InviteSelectedUsers(action.selections))
}
.setNegativeButton(R.string.action_cancel, null)
.show()
}
}

private fun openPhoneBook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.matrix.android.sdk.api.session.user.model.User
import org.matrix.android.sdk.api.util.toMatrixItem

sealed class PendingSelection {
data class UserPendingSelection(val user: User) : PendingSelection()
data class UserPendingSelection(val user: User, var isUnknownUser: Boolean = false) : PendingSelection()
data class ThreePidPendingSelection(val threePid: ThreePid) : PendingSelection()

fun getBestName(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class UserListViewModel @AssistedInject constructor(
.sortedBy { it.toMatrixItem().firstLetterOfDisplayName() }
val userProfile = if (MatrixPatterns.isUserId(search)) {
val user = tryOrNull { session.profileService().getProfileAsUser(search) }
setState { copy(unknownUserId = search.takeIf { user == null }) }
User(
userId = search,
displayName = user?.displayName,
Expand All @@ -284,6 +285,9 @@ class UserListViewModel @AssistedInject constructor(
(action.pendingSelection is PendingSelection.UserPendingSelection &&
state.pendingSelections.last() is PendingSelection.UserPendingSelection)
if (canSelectUser) {
if (action.pendingSelection is PendingSelection.UserPendingSelection) {
action.pendingSelection.isUnknownUser = action.pendingSelection.getMxId() == state.unknownUserId
}
val selections = state.pendingSelections.toggle(action.pendingSelection, singleElement = state.singleSelection)
setState { copy(pendingSelections = selections) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data class UserListViewState(
val matchingEmail: Async<ThreePidUser?> = Uninitialized,
val filteredMappedContacts: List<MappedContact> = emptyList(),
val pendingSelections: Set<PendingSelection> = emptySet(),
val unknownUserId: String? = null,
val searchTerm: String = "",
val singleSelection: Boolean,
val single3pidSelection: Boolean,
Expand Down

0 comments on commit 07e0695

Please sign in to comment.