From 3103fe970add3b652177ecd870ce0003be7eb71d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 12 Aug 2020 11:01:01 +0200 Subject: [PATCH] Ensure users do not accidentally ignore other users (#1890) - Wording: use "Ignore" instead of "Block" for consistency across the app and with other Element app --- CHANGES.md | 1 + .../accountdata/UpdateIgnoredUserIdsTask.kt | 6 +++--- .../home/room/detail/RoomDetailFragment.kt | 17 +++++++++++++---- vector/src/main/res/values/strings.xml | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index da1858c378..adfda09700 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Features ✨: Improvements 🙌: - Give user the possibility to prevent accidental call (#1869) + - Ensure users do not accidentally ignore other users (#1890) Bugfix 🐛: - Fix invisible toolbar (Status.im theme) (#1746) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt index 2c3f75fe06..b47a25187b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt @@ -18,14 +18,14 @@ package org.matrix.android.sdk.internal.session.user.accountdata import com.zhuinden.monarchy.Monarchy +import org.greenrobot.eventbus.EventBus +import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes import org.matrix.android.sdk.internal.database.model.IgnoredUserEntity import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.sync.model.accountdata.IgnoredUsersContent -import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes import org.matrix.android.sdk.internal.task.Task -import org.greenrobot.eventbus.EventBus import javax.inject.Inject internal interface UpdateIgnoredUserIdsTask : Task { @@ -51,7 +51,7 @@ internal class DefaultUpdateIgnoredUserIdsTask @Inject constructor( { it.userId } ).toMutableSet() - val original = ignoredUserIds.toList() + val original = ignoredUserIds.toSet() ignoredUserIds.removeAll { it in params.userIdsToUnIgnore } ignoredUserIds.addAll(params.userIdsToIgnore) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 6f7e39af43..424731fdb0 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -1491,7 +1491,7 @@ class RoomDetailFragment @Inject constructor( promptReasonToReportContent(action) } is EventSharedAction.IgnoreUser -> { - roomDetailViewModel.handle(RoomDetailAction.IgnoreUser(action.senderId)) + action.senderId?.let { askConfirmationToIgnoreUser(it) } } is EventSharedAction.OnUrlClicked -> { onUrlClicked(action.url, action.title) @@ -1507,12 +1507,21 @@ class RoomDetailFragment @Inject constructor( startActivity(KeysBackupRestoreActivity.intent(it)) } } - else -> { - Toast.makeText(context, "Action $action is not implemented yet", Toast.LENGTH_LONG).show() - } } } + private fun askConfirmationToIgnoreUser(senderId: String) { + AlertDialog.Builder(requireContext()) + .setTitle(R.string.room_participants_action_ignore_title) + .setMessage(R.string.room_participants_action_ignore_prompt_msg) + .setNegativeButton(R.string.cancel, null) + .setPositiveButton(R.string.room_participants_action_ignore) { _, _ -> + roomDetailViewModel.handle(RoomDetailAction.IgnoreUser(senderId)) + } + .show() + .withColoredButton(DialogInterface.BUTTON_POSITIVE) + } + /** * Insert a user displayName in the message editor. * diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 33b09205f1..daae4dee2f 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -1801,7 +1801,7 @@ "Report this content" "Reason for reporting this content" "REPORT" - "BLOCK USER" + "IGNORE USER" "Content reported" "This content was reported.\n\nIf you don't want to see any more content from this user, you can block him to hide his messages" @@ -1814,7 +1814,7 @@ There is no network connection right now - Block user + Ignore user "All messages (noisy)" "All messages"