From 534151f1bb7e2c5ddfb630339e40367a75b06557 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Tue, 27 Jun 2023 20:58:04 +0300 Subject: [PATCH] android: group preference to prohibit files and media (#2620) Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> --- .../java/chat/simplex/app/model/SimpleXAPI.kt | 29 +++++++++++++++---- .../simplex/app/views/chat/ComposeView.kt | 16 ++++++++-- .../app/views/chat/group/GroupPreferences.kt | 6 ++++ .../app/src/main/res/values/strings.xml | 7 +++++ 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt index fdc038d64d..c20fe976b1 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt @@ -2930,7 +2930,8 @@ enum class GroupFeature: Feature { @SerialName("directMessages") DirectMessages, @SerialName("fullDelete") FullDelete, @SerialName("reactions") Reactions, - @SerialName("voice") Voice; + @SerialName("voice") Voice, + @SerialName("files") Files; override val hasParam: Boolean get() = when(this) { TimedMessages -> true @@ -2944,6 +2945,7 @@ enum class GroupFeature: Feature { FullDelete -> generalGetString(R.string.full_deletion) Reactions -> generalGetString(R.string.message_reactions) Voice -> generalGetString(R.string.voice_messages) + Files -> generalGetString(R.string.files_and_media) } val icon: Painter @@ -2953,6 +2955,7 @@ enum class GroupFeature: Feature { FullDelete -> painterResource(R.drawable.ic_delete_forever) Reactions -> painterResource(R.drawable.ic_add_reaction) Voice -> painterResource(R.drawable.ic_keyboard_voice) + Files -> painterResource(R.drawable.ic_draft) } @Composable @@ -2962,6 +2965,7 @@ enum class GroupFeature: Feature { FullDelete -> painterResource(R.drawable.ic_delete_forever_filled) Reactions -> painterResource(R.drawable.ic_add_reaction_filled) Voice -> painterResource(R.drawable.ic_keyboard_voice_filled) + Files -> painterResource(R.drawable.ic_draft_filled) } fun enableDescription(enabled: GroupFeatureEnabled, canEdit: Boolean): String = @@ -2987,6 +2991,10 @@ enum class GroupFeature: Feature { GroupFeatureEnabled.ON -> generalGetString(R.string.allow_to_send_voice) GroupFeatureEnabled.OFF -> generalGetString(R.string.prohibit_sending_voice) } + Files -> when(enabled) { + GroupFeatureEnabled.ON -> generalGetString(R.string.allow_to_send_files) + GroupFeatureEnabled.OFF -> generalGetString(R.string.prohibit_sending_files) + } } } else { when(this) { @@ -3010,6 +3018,10 @@ enum class GroupFeature: Feature { GroupFeatureEnabled.ON -> generalGetString(R.string.group_members_can_send_voice) GroupFeatureEnabled.OFF -> generalGetString(R.string.voice_messages_are_prohibited) } + Files -> when(enabled) { + GroupFeatureEnabled.ON -> generalGetString(R.string.group_members_can_send_files) + GroupFeatureEnabled.OFF -> generalGetString(R.string.files_are_prohibited_in_group) + } } } } @@ -3122,7 +3134,8 @@ data class FullGroupPreferences( val directMessages: GroupPreference, val fullDelete: GroupPreference, val reactions: GroupPreference, - val voice: GroupPreference + val voice: GroupPreference, + val files: GroupPreference, ) { fun toGroupPreferences(): GroupPreferences = GroupPreferences( @@ -3130,7 +3143,8 @@ data class FullGroupPreferences( directMessages = directMessages, fullDelete = fullDelete, reactions = reactions, - voice = voice + voice = voice, + files = files, ) companion object { @@ -3139,7 +3153,8 @@ data class FullGroupPreferences( directMessages = GroupPreference(GroupFeatureEnabled.OFF), fullDelete = GroupPreference(GroupFeatureEnabled.OFF), reactions = GroupPreference(GroupFeatureEnabled.ON), - voice = GroupPreference(GroupFeatureEnabled.ON) + voice = GroupPreference(GroupFeatureEnabled.ON), + files = GroupPreference(GroupFeatureEnabled.ON), ) } } @@ -3150,7 +3165,8 @@ data class GroupPreferences( val directMessages: GroupPreference?, val fullDelete: GroupPreference?, val reactions: GroupPreference?, - val voice: GroupPreference? + val voice: GroupPreference?, + val files: GroupPreference?, ) { companion object { val sampleData = GroupPreferences( @@ -3158,7 +3174,8 @@ data class GroupPreferences( directMessages = GroupPreference(GroupFeatureEnabled.OFF), fullDelete = GroupPreference(GroupFeatureEnabled.OFF), reactions = GroupPreference(GroupFeatureEnabled.ON), - voice = GroupPreference(GroupFeatureEnabled.ON) + voice = GroupPreference(GroupFeatureEnabled.ON), + files = GroupPreference(GroupFeatureEnabled.ON), ) } } diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt index 32f68a8b91..189a8e4ad9 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt @@ -16,6 +16,7 @@ import android.webkit.MimeTypeMap import android.widget.Toast import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContract +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.* @@ -713,11 +714,22 @@ fun ComposeView( modifier = Modifier.padding(end = 8.dp), verticalAlignment = Alignment.Bottom, ) { - IconButton(showChooseAttachment, enabled = !composeState.value.attachmentDisabled && rememberUpdatedState(chat.userCanSend).value) { + val isGroupAndProhibitedFiles = chat.chatInfo is ChatInfo.Group && !chat.chatInfo.groupInfo.fullGroupPreferences.files.on + val attachmentClicked = if (isGroupAndProhibitedFiles) { + { + AlertManager.shared.showAlertMsg( + title = generalGetString(R.string.files_and_media_prohibited), + text = generalGetString(R.string.only_owners_can_enable_files_and_media) + ) + } + } else { + showChooseAttachment + } + IconButton(attachmentClicked, enabled = !composeState.value.attachmentDisabled && rememberUpdatedState(chat.userCanSend).value) { Icon( painterResource(R.drawable.ic_attach_file_filled_500), contentDescription = stringResource(R.string.attach), - tint = if (!composeState.value.attachmentDisabled && userCanSend.value) MaterialTheme.colors.primary else MaterialTheme.colors.secondary, + tint = if (!composeState.value.attachmentDisabled && userCanSend.value && !isGroupAndProhibitedFiles) MaterialTheme.colors.primary else MaterialTheme.colors.secondary, modifier = Modifier .size(28.dp) .clip(CircleShape) diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/group/GroupPreferences.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/group/GroupPreferences.kt index e23f0dd264..d6157140b7 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/group/GroupPreferences.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/group/GroupPreferences.kt @@ -103,6 +103,12 @@ private fun GroupPreferencesLayout( FeatureSection(GroupFeature.Voice, allowVoice, groupInfo, preferences, onTTLUpdated) { applyPrefs(preferences.copy(voice = GroupPreference(enable = it))) } +// TODO uncomment in 5.3 +// SectionDividerSpaced(true, maxBottomPadding = false) +// val allowFiles = remember(preferences) { mutableStateOf(preferences.files.enable) } +// FeatureSection(GroupFeature.Files, allowFiles, groupInfo, preferences, onTTLUpdated) { +// applyPrefs(preferences.copy(files = GroupPreference(enable = it))) +// } if (groupInfo.canEdit) { SectionDividerSpaced(maxTopPadding = true, maxBottomPadding = false) ResetSaveButtons( diff --git a/apps/android/app/src/main/res/values/strings.xml b/apps/android/app/src/main/res/values/strings.xml index 4130f55ac4..fa79b17d3b 100644 --- a/apps/android/app/src/main/res/values/strings.xml +++ b/apps/android/app/src/main/res/values/strings.xml @@ -281,6 +281,8 @@ you are observer You can\'t send messages! Please contact group admin. + Files and media prohibited! + Only group owners can enable files and media. Image @@ -1290,6 +1292,7 @@ Delete for everyone Message reactions Voice messages + Files and media Audio/video calls \nAvailable in v5.1 enabled @@ -1344,6 +1347,8 @@ Prohibit sending voice messages. Allow message reactions. Prohibit messages reactions. + Allow to send files and media. + Prohibit sending files and media. Group members can send disappearing messages. Disappearing messages are prohibited in this group. Group members can send direct messages. @@ -1354,6 +1359,8 @@ Voice messages are prohibited in this group. Group members can add message reactions. Message reactions are prohibited in this group. + Group members can send files and media. + Files and media are prohibited in this group. Delete after %d sec %ds