diff --git a/apps/ios/Shared/Views/Chat/ComposeMessage/ComposeView.swift b/apps/ios/Shared/Views/Chat/ComposeMessage/ComposeView.swift index 619f0b95f3..adaa2edad4 100644 --- a/apps/ios/Shared/Views/Chat/ComposeMessage/ComposeView.swift +++ b/apps/ios/Shared/Views/Chat/ComposeMessage/ComposeView.swift @@ -45,7 +45,7 @@ struct ComposeState { var voiceMessageRecordingState: VoiceMessageRecordingState var inProgress = false var progressByTimeout = false - var useLinkPreviews: Bool = UserDefaults.standard.bool(forKey: DEFAULT_PRIVACY_LINK_PREVIEWS) + var useLinkPreviews = true var mentions: MentionedMembers = [:] init( @@ -476,17 +476,20 @@ struct ComposeView: View { } else { composeState = composeState.copy(parsedMessage: parsedMsg ?? FormattedText.plain(msg)) } - if composeState.linkPreviewAllowed { - if msg.count > 0 { + if composeState.linkPreviewAllowed && UserDefaults.standard.bool(forKey: DEFAULT_PRIVACY_LINK_PREVIEWS) { + if !msg.isEmpty { showLinkPreview(parsedMsg) } else { resetLinkPreview() hasSimplexLink = false + composeState = composeState.copy(preview: .noPreview) } - } else if msg.count > 0 && !chat.groupFeatureEnabled(.simplexLinks) { - (_, hasSimplexLink) = getMessageLinks(parsedMsg) } else { - hasSimplexLink = false + resetLinkPreview() + hasSimplexLink = !msg.isEmpty && !chat.groupFeatureEnabled(.simplexLinks) && getMessageLinks(parsedMsg).hasSimplexLink + if composeState.linkPreviewAllowed { + composeState = composeState.copy(preview: .noPreview) + } } } .onChange(of: chat.chatInfo.sendMsgEnabled) { sendEnabled in diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt index a3365b2087..de48a67988 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt @@ -124,7 +124,7 @@ fun ChatView( } } else { val searchText = rememberSaveable { mutableStateOf("") } - val useLinkPreviews = chatModel.controller.appPrefs.privacyLinkPreviews.get() + val useLinkPreviews = true val composeState = rememberSaveable(saver = ComposeState.saver()) { val draft = chatModel.draft.value val sharedContent = chatModel.sharedContent.value diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeView.kt index fdc6a3fed5..c575efcb35 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeView.kt @@ -373,7 +373,7 @@ fun ComposeView( val hasSimplexLink = rememberSaveable { mutableStateOf(getMessageLinks(parseToMarkdown(composeState.value.message.text)).second) } val prevLinkUrl = rememberSaveable { mutableStateOf(null) } val pendingLinkUrl = rememberSaveable { mutableStateOf(null) } - val useLinkPreviews = chatModel.controller.appPrefs.privacyLinkPreviews.get() + val useLinkPreviews = true val saveLastDraft = chatModel.controller.appPrefs.privacySaveLastDraft.get() val smallFont = MaterialTheme.typography.body1.copy(color = MaterialTheme.colors.onBackground) val textStyle = remember(MaterialTheme.colors.isLight) { mutableStateOf(smallFont) } @@ -902,7 +902,7 @@ fun ComposeView( fun onMessageChange(s: ComposeMessage) { var parsedMessage = parseToMarkdown(s.text) - if (chatModel.controller.appPrefs.privacySanitizeLinks.state.value && parsedMessage != null) { + if (chatModel.controller.appPrefs.privacySanitizeLinks.get() && parsedMessage != null) { val (updatedMsg, updatedParsedMsg, sanitizedPos) = sanitizeMessage(parsedMessage) if (sanitizedPos == null) { composeState.value = composeState.value.copy(message = s, parsedMessage = parsedMessage) @@ -918,17 +918,18 @@ fun ComposeView( textStyle.value = if (s.text.codePoints().count() < 4) largeEmojiFont else mediumEmojiFont } else { textStyle.value = smallFont - if (composeState.value.linkPreviewAllowed) { + if (composeState.value.linkPreviewAllowed && chatModel.controller.appPrefs.privacyLinkPreviews.get()) { if (s.text.isNotEmpty()) { showLinkPreview(parsedMessage) } else { resetLinkPreview() hasSimplexLink.value = false + composeState.value = composeState.value.copy(preview = ComposePreview.NoPreview) } - } else if (s.text.isNotEmpty() && !chat.groupFeatureEnabled(GroupFeature.SimplexLinks)) { - hasSimplexLink.value = getMessageLinks(parsedMessage).second } else { - hasSimplexLink.value = false + resetLinkPreview() + hasSimplexLink.value = s.text.isNotEmpty() && !chat.groupFeatureEnabled(GroupFeature.SimplexLinks) && getMessageLinks(parsedMessage).second + if (composeState.value.linkPreviewAllowed) composeState.value = composeState.value.copy(preview = ComposePreview.NoPreview) } } }