ui: fix permission to generate link previews (#6166)

This commit is contained in:
Evgeny
2025-08-09 16:33:06 +01:00
committed by GitHub
parent 96708dbbf0
commit c2d0b7df46
3 changed files with 17 additions and 13 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -373,7 +373,7 @@ fun ComposeView(
val hasSimplexLink = rememberSaveable { mutableStateOf(getMessageLinks(parseToMarkdown(composeState.value.message.text)).second) }
val prevLinkUrl = rememberSaveable { mutableStateOf<String?>(null) }
val pendingLinkUrl = rememberSaveable { mutableStateOf<String?>(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)
}
}
}