From ea84aa1478081095df6a0e6c120bc7e29100dd4a Mon Sep 17 00:00:00 2001 From: Al Lansley Date: Mon, 12 Aug 2024 14:17:04 +1000 Subject: [PATCH] Tied in bandDeleteAll string --- .../v2/menus/ConversationActionModeCallback.kt | 7 +++++++ .../conversation/v2/menus/ConversationMenuHelper.kt | 6 +++--- .../org/thoughtcrime/securesms/home/HomeActivity.kt | 12 +----------- .../main/res/menu/menu_conversation_item_action.xml | 3 +-- .../libsession/messaging/open_groups/OpenGroupApi.kt | 3 +-- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationActionModeCallback.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationActionModeCallback.kt index c7862ca22e..720310fa5e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationActionModeCallback.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationActionModeCallback.kt @@ -40,6 +40,8 @@ class ConversationActionModeCallback(private val adapter: ConversationAdapter, p val edKeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair()!! val blindedPublicKey = openGroup?.publicKey?.let { SodiumUtilities.blindedKeyPair(it, edKeyPair)?.publicKey?.asBytes } ?.let { AccountId(IdPrefix.BLINDED, it) }?.hexString + + // Embedded function fun userCanDeleteSelectedItems(): Boolean { val allSentByCurrentUser = selectedItems.all { it.isOutgoing } val allReceivedByCurrentUser = selectedItems.all { !it.isOutgoing } @@ -47,6 +49,8 @@ class ConversationActionModeCallback(private val adapter: ConversationAdapter, p if (allSentByCurrentUser) { return true } return OpenGroupManager.isUserModerator(context, openGroup.groupId, userPublicKey, blindedPublicKey) } + + // Embedded function fun userCanBanSelectedUsers(): Boolean { if (openGroup == null) { return false } val anySentByCurrentUser = selectedItems.any { it.isOutgoing } @@ -55,6 +59,9 @@ class ConversationActionModeCallback(private val adapter: ConversationAdapter, p if (selectedUsers.size > 1) { return false } return OpenGroupManager.isUserModerator(context, openGroup.groupId, userPublicKey, blindedPublicKey) } + + + // Delete message menu.findItem(R.id.menu_context_delete_message).isVisible = userCanDeleteSelectedItems() // Ban user diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationMenuHelper.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationMenuHelper.kt index 2ec7334139..ee8cd08636 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationMenuHelper.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationMenuHelper.kt @@ -52,11 +52,11 @@ object ConversationMenuHelper { ) { // Prepare menu.clear() - val isOpenGroup = thread.isCommunityRecipient + val isCommunity = thread.isCommunityRecipient // Base menu (options that should always be present) inflater.inflate(R.menu.menu_conversation, menu) // Expiring messages - if (!isOpenGroup && (thread.hasApprovedMe() || thread.isClosedGroupRecipient || thread.isLocalNumber)) { + if (!isCommunity && (thread.hasApprovedMe() || thread.isClosedGroupRecipient || thread.isLocalNumber)) { inflater.inflate(R.menu.menu_conversation_expiration, menu) } // One-on-one chat menu allows copying the account id @@ -76,7 +76,7 @@ object ConversationMenuHelper { inflater.inflate(R.menu.menu_conversation_closed_group, menu) } // Open group menu - if (isOpenGroup) { + if (isCommunity) { inflater.inflate(R.menu.menu_conversation_open_group, menu) } // Muting diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index 86ee3fb347..c70f78fed2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -95,6 +95,7 @@ import kotlin.time.Duration.Companion.hours import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds +// Intent extra keys so we know where we came from private const val NEW_ACCOUNT = "HomeActivity_NEW_ACCOUNT" private const val FROM_ONBOARDING = "HomeActivity_FROM_ONBOARDING" @@ -105,11 +106,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), private val TAG = "HomeActivity" -// companion object { -// const val NEW_ACCOUNT = "HomeActivity_NEW_ACCOUNT" -// const val FROM_ONBOARDING = "HomeActivity_FROM_ONBOARDING" -// } - private lateinit var binding: ActivityHomeBinding private lateinit var glide: RequestManager @@ -160,12 +156,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), private val isFromOnboarding: Boolean get() = intent.getBooleanExtra(FROM_ONBOARDING, false) private val isNewAccount: Boolean get() = intent.getBooleanExtra(NEW_ACCOUNT, false) - - - - - - // ACL REMOVE BLOCK START fun getRelativeTimeLocalized(timestampMS: Long): String { diff --git a/app/src/main/res/menu/menu_conversation_item_action.xml b/app/src/main/res/menu/menu_conversation_item_action.xml index d1758faddf..047c8ab953 100644 --- a/app/src/main/res/menu/menu_conversation_item_action.xml +++ b/app/src/main/res/menu/menu_conversation_item_action.xml @@ -47,9 +47,8 @@ android:id="@+id/menu_context_ban_user" app:showAsAction="never" /> - diff --git a/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupApi.kt b/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupApi.kt index e988b579f1..ae2afc2db4 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupApi.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/open_groups/OpenGroupApi.kt @@ -679,8 +679,7 @@ object OpenGroupApi { } fun unban(publicKey: String, room: String, server: String): Promise { - val request = - Request(verb = DELETE, room = room, server = server, endpoint = Endpoint.UserUnban(publicKey)) + val request = Request(verb = DELETE, room = room, server = server, endpoint = Endpoint.UserUnban(publicKey)) return send(request).map { Log.d("Loki", "Unbanned user: $publicKey from: $server.$room") }