diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt
index 89af46edb5..0ebe77e524 100644
--- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt
+++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt
@@ -2925,6 +2925,20 @@ sealed class MsgContent {
@Serializable(with = MsgContentSerializer::class) class MCFile(override val text: String): MsgContent()
@Serializable(with = MsgContentSerializer::class) class MCUnknown(val type: String? = null, override val text: String, val json: JsonElement): MsgContent()
+ val isVoice: Boolean get() =
+ when (this) {
+ is MCVoice -> true
+ else -> false
+ }
+
+ val isMediaOrFileAttachment: Boolean get() =
+ when (this) {
+ is MCImage -> true
+ is MCVideo -> true
+ is MCFile -> true
+ else -> false
+ }
+
val cmdString: String get() =
if (this is MCUnknown) "json $json" else "json ${json.encodeToString(this)}"
}
diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ShareListNavLinkView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ShareListNavLinkView.kt
index 1de1e40afb..91dffeb7c8 100644
--- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ShareListNavLinkView.kt
+++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ShareListNavLinkView.kt
@@ -9,30 +9,55 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
-import chat.simplex.common.views.helpers.ProfileImage
import chat.simplex.common.model.*
import chat.simplex.common.ui.theme.*
+import chat.simplex.common.views.helpers.*
import chat.simplex.res.MR
@Composable
-fun ShareListNavLinkView(chat: Chat, chatModel: ChatModel) {
+fun ShareListNavLinkView(
+ chat: Chat,
+ chatModel: ChatModel,
+ isMediaOrFileAttachment: Boolean,
+ isVoice: Boolean,
+ hasSimplexLink: Boolean
+) {
val stopped = chatModel.chatRunning.value == false
when (chat.chatInfo) {
- is ChatInfo.Direct ->
+ is ChatInfo.Direct -> {
+ val voiceProhibited = isVoice && !chat.chatInfo.featureEnabled(ChatFeature.Voice)
ShareListNavLinkLayout(
- chatLinkPreview = { SharePreviewView(chat) },
- click = { directChatAction(chat.remoteHostId, chat.chatInfo.contact, chatModel) },
+ chatLinkPreview = { SharePreviewView(chat, disabled = voiceProhibited) },
+ click = {
+ if (voiceProhibited) {
+ showForwardProhibitedByPrefAlert()
+ } else {
+ directChatAction(chat.remoteHostId, chat.chatInfo.contact, chatModel)
+ }
+ },
stopped
)
- is ChatInfo.Group ->
+ }
+ is ChatInfo.Group -> {
+ val simplexLinkProhibited = hasSimplexLink && !chat.groupFeatureEnabled(GroupFeature.SimplexLinks)
+ val fileProhibited = isMediaOrFileAttachment && !chat.groupFeatureEnabled(GroupFeature.Files)
+ val voiceProhibited = isVoice && !chat.chatInfo.featureEnabled(ChatFeature.Voice)
+ val prohibitedByPref = simplexLinkProhibited || fileProhibited || voiceProhibited
ShareListNavLinkLayout(
- chatLinkPreview = { SharePreviewView(chat) },
- click = { groupChatAction(chat.remoteHostId, chat.chatInfo.groupInfo, chatModel) },
+ chatLinkPreview = { SharePreviewView(chat, disabled = prohibitedByPref) },
+ click = {
+ if (prohibitedByPref) {
+ showForwardProhibitedByPrefAlert()
+ } else {
+ groupChatAction(chat.remoteHostId, chat.chatInfo.groupInfo, chatModel)
+ }
+ },
stopped
)
+ }
is ChatInfo.Local ->
ShareListNavLinkLayout(
- chatLinkPreview = { SharePreviewView(chat) },
+ chatLinkPreview = { SharePreviewView(chat, disabled = false) },
click = { noteFolderChatAction(chat.remoteHostId, chat.chatInfo.noteFolder) },
stopped
)
@@ -40,6 +65,13 @@ fun ShareListNavLinkView(chat: Chat, chatModel: ChatModel) {
}
}
+private fun showForwardProhibitedByPrefAlert() {
+ AlertManager.shared.showAlertMsg(
+ title = generalGetString(MR.strings.cannot_share_message_alert_title),
+ text = generalGetString(MR.strings.cannot_share_message_alert_text),
+ )
+}
+
@Composable
private fun ShareListNavLinkLayout(
chatLinkPreview: @Composable () -> Unit,
@@ -53,7 +85,7 @@ private fun ShareListNavLinkLayout(
}
@Composable
-private fun SharePreviewView(chat: Chat) {
+private fun SharePreviewView(chat: Chat, disabled: Boolean) {
Row(
Modifier.fillMaxSize(),
horizontalArrangement = Arrangement.SpaceBetween,
@@ -70,7 +102,7 @@ private fun SharePreviewView(chat: Chat) {
}
Text(
chat.chatInfo.chatViewName, maxLines = 1, overflow = TextOverflow.Ellipsis,
- color = if (chat.chatInfo.incognito) Indigo else Color.Unspecified
+ color = if (disabled) MaterialTheme.colors.secondary else if (chat.chatInfo.incognito) Indigo else Color.Unspecified
)
}
}
diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ShareListView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ShareListView.kt
index a36930f5ce..69382d9fde 100644
--- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ShareListView.kt
+++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ShareListView.kt
@@ -31,13 +31,44 @@ fun ShareListView(chatModel: ChatModel, settingsState: SettingsViewState, stoppe
scaffoldState = scaffoldState,
topBar = { Column { ShareListToolbar(chatModel, userPickerState, stopped) { searchInList = it.trim() } } },
) {
+ val sharedContent = chatModel.sharedContent.value
+ var isMediaOrFileAttachment = false
+ var isVoice = false
+ var hasSimplexLink = false
+ when (sharedContent) {
+ is SharedContent.Text ->
+ hasSimplexLink = hasSimplexLink(sharedContent.text)
+ is SharedContent.Media -> {
+ isMediaOrFileAttachment = true
+ hasSimplexLink = hasSimplexLink(sharedContent.text)
+ }
+ is SharedContent.File -> {
+ isMediaOrFileAttachment = true
+ hasSimplexLink = hasSimplexLink(sharedContent.text)
+ }
+ is SharedContent.Forward -> {
+ val mc = sharedContent.chatItem.content.msgContent
+ if (mc != null) {
+ isMediaOrFileAttachment = mc.isMediaOrFileAttachment
+ isVoice = mc.isVoice
+ hasSimplexLink = hasSimplexLink(mc.text)
+ }
+ }
+ null -> {}
+ }
Box(Modifier.padding(it)) {
Column(
modifier = Modifier
.fillMaxSize()
) {
if (chatModel.chats.isNotEmpty()) {
- ShareList(chatModel, search = searchInList)
+ ShareList(
+ chatModel,
+ search = searchInList,
+ isMediaOrFileAttachment = isMediaOrFileAttachment,
+ isVoice = isVoice,
+ hasSimplexLink = hasSimplexLink
+ )
} else {
EmptyList()
}
@@ -54,6 +85,11 @@ fun ShareListView(chatModel: ChatModel, settingsState: SettingsViewState, stoppe
}
}
+private fun hasSimplexLink(msg: String): Boolean {
+ val parsedMsg = parseToMarkdown(msg) ?: return false
+ return parsedMsg.any { ft -> ft.format is Format.SimplexLink }
+}
+
@Composable
private fun EmptyList() {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
@@ -141,7 +177,13 @@ private fun ShareListToolbar(chatModel: ChatModel, userPickerState: MutableState
}
@Composable
-private fun ShareList(chatModel: ChatModel, search: String) {
+private fun ShareList(
+ chatModel: ChatModel,
+ search: String,
+ isMediaOrFileAttachment: Boolean,
+ isVoice: Boolean,
+ hasSimplexLink: Boolean
+) {
val chats by remember(search) {
derivedStateOf {
val sorted = chatModel.chats.toList().sortedByDescending { it.chatInfo is ChatInfo.Local }
@@ -156,7 +198,13 @@ private fun ShareList(chatModel: ChatModel, search: String) {
modifier = Modifier.fillMaxWidth()
) {
items(chats) { chat ->
- ShareListNavLinkView(chat, chatModel)
+ ShareListNavLinkView(
+ chat,
+ chatModel,
+ isMediaOrFileAttachment = isMediaOrFileAttachment,
+ isVoice = isVoice,
+ hasSimplexLink = hasSimplexLink
+ )
}
}
}
diff --git a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml
index b896c4e980..996ecb11da 100644
--- a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml
+++ b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml
@@ -358,6 +358,8 @@
Share media…
Share file…
Forward message…
+ Cannot send message
+ Selected chat preferences prohibit this message.
Attach