From 4c6ead64f4753f555c77c17ec54a61997cf7ad73 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 20 Feb 2023 15:07:34 +0100 Subject: [PATCH] Added config option to show secure chat button in contact details & call history even if no LIME capability in presence (or no presence at all) --- .../activities/main/contact/viewmodels/ContactViewModel.kt | 6 ++++-- .../activities/main/history/viewmodels/CallLogViewModel.kt | 2 +- app/src/main/java/org/linphone/core/CorePreferences.kt | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/linphone/activities/main/contact/viewmodels/ContactViewModel.kt b/app/src/main/java/org/linphone/activities/main/contact/viewmodels/ContactViewModel.kt index a025bd0af..e57ef514a 100644 --- a/app/src/main/java/org/linphone/activities/main/contact/viewmodels/ContactViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/contact/viewmodels/ContactViewModel.kt @@ -204,7 +204,8 @@ class ContactViewModel(friend: Friend, async: Boolean = false) : MessageNotifier val presenceModel = friend.getPresenceModelForUriOrTel(value) val hasPresence = presenceModel?.basicStatus == PresenceBasicStatus.Open val isMe = coreContext.core.defaultAccount?.params?.identityAddress?.weakEqual(address) ?: false - val secureChatAllowed = LinphoneUtils.isEndToEndEncryptedChatAvailable() && !isMe && friend.getPresenceModelForUriOrTel(value)?.hasCapability(FriendCapability.LimeX3Dh) ?: false + val hasLimeCapability = corePreferences.allowEndToEndEncryptedChatWithoutPresence || (friend.getPresenceModelForUriOrTel(value)?.hasCapability(FriendCapability.LimeX3Dh) ?: false) + val secureChatAllowed = LinphoneUtils.isEndToEndEncryptedChatAvailable() && !isMe && hasLimeCapability val displayValue = if (coreContext.core.defaultAccount?.params?.domain == address.domain) (address.username ?: value) else value val noa = ContactNumberOrAddressData(address, hasPresence, displayValue, showSecureChat = secureChatAllowed, listener = listener) list.add(noa) @@ -218,7 +219,8 @@ class ContactViewModel(friend: Friend, async: Boolean = false) : MessageNotifier val address = coreContext.core.interpretUrl(contactAddress, true) address?.displayName = displayName.value.orEmpty() val isMe = if (address != null) coreContext.core.defaultAccount?.params?.identityAddress?.weakEqual(address) ?: false else false - val secureChatAllowed = LinphoneUtils.isEndToEndEncryptedChatAvailable() && !isMe && friend.getPresenceModelForUriOrTel(number)?.hasCapability(FriendCapability.LimeX3Dh) ?: false + val hasLimeCapability = corePreferences.allowEndToEndEncryptedChatWithoutPresence || (friend.getPresenceModelForUriOrTel(number)?.hasCapability(FriendCapability.LimeX3Dh) ?: false) + val secureChatAllowed = LinphoneUtils.isEndToEndEncryptedChatAvailable() && !isMe && hasLimeCapability val label = PhoneNumberUtils.vcardParamStringToAddressBookLabel(coreContext.context.resources, phoneNumber.label ?: "") val noa = ContactNumberOrAddressData(address, hasPresence, number, isSip = false, showSecureChat = secureChatAllowed, typeLabel = label, listener = listener) list.add(noa) diff --git a/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogViewModel.kt b/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogViewModel.kt index 5d6ed9416..e8ea1b8b0 100644 --- a/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogViewModel.kt @@ -101,7 +101,7 @@ class CallLogViewModel(val callLog: CallLog, private val isRelated: Boolean = fa val hidePlainChat = corePreferences.forceEndToEndEncryptedChat - val secureChatAllowed = LinphoneUtils.isEndToEndEncryptedChatAvailable() && (contact.value?.getPresenceModelForUriOrTel(peerSipUri)?.hasCapability(FriendCapability.LimeX3Dh) ?: false) + val secureChatAllowed = LinphoneUtils.isEndToEndEncryptedChatAvailable() && (corePreferences.allowEndToEndEncryptedChatWithoutPresence || (contact.value?.getPresenceModelForUriOrTel(peerSipUri)?.hasCapability(FriendCapability.LimeX3Dh) ?: false)) val relatedCallLogs = MutableLiveData>() diff --git a/app/src/main/java/org/linphone/core/CorePreferences.kt b/app/src/main/java/org/linphone/core/CorePreferences.kt index f82c97cf8..b88579935 100644 --- a/app/src/main/java/org/linphone/core/CorePreferences.kt +++ b/app/src/main/java/org/linphone/core/CorePreferences.kt @@ -470,6 +470,10 @@ class CorePreferences constructor(private val context: Context) { val forceEndToEndEncryptedChat: Boolean get() = config.getBool("app", "force_lime_chat_rooms", false) + // Turning this ON will show the secure chat button even if there is no LIME capability in presence (or no presence) + val allowEndToEndEncryptedChatWithoutPresence: Boolean + get() = config.getBool("app", "allow_lime_friend_without_capability", false) + // This will prevent UI from showing up, except for the launcher & the foreground service notification val preventInterfaceFromShowingUp: Boolean get() = config.getBool("app", "keep_app_invisible", false)