From 42d7574d6c1eac5dafda02080d227abdb1e176c2 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 16 May 2022 16:20:34 +0200 Subject: [PATCH 1/5] Fix unexpected logout (#528) --- Btchap/target.yml | 2 +- Config/CommonConfiguration.swift | 4 + RiotShareExtension/target.yml | 2 +- Tchap/Config/CommonConfiguration.swift | 102 ------------------------- Tchap/target.yml | 1 + TchapTests/target.yml | 2 +- changelog.d/528.bugfix | 1 + 7 files changed, 9 insertions(+), 105 deletions(-) delete mode 100644 Tchap/Config/CommonConfiguration.swift create mode 100644 changelog.d/528.bugfix diff --git a/Btchap/target.yml b/Btchap/target.yml index 98f3736ea3..c33f9877e7 100644 --- a/Btchap/target.yml +++ b/Btchap/target.yml @@ -63,6 +63,7 @@ targets: - path: ../Config/Project.xcconfig - path: ../Config/Project-Warnings.xcconfig - path: ../Config/AppIdentifiers.xcconfig + - path: ../Config/CommonConfiguration.swift - path: . excludes: - "**/*.strings" # Exclude all strings files @@ -261,7 +262,6 @@ targets: # Tchap - path: ../Tchap/Config/AppConfiguration.swift - - path: ../Tchap/Config/CommonConfiguration.swift - path: ../Tchap/Config/Configurable.swift # Resources diff --git a/Config/CommonConfiguration.swift b/Config/CommonConfiguration.swift index 5802f8d778..22d2d0d4fe 100644 --- a/Config/CommonConfiguration.swift +++ b/Config/CommonConfiguration.swift @@ -62,10 +62,14 @@ class CommonConfiguration: NSObject, Configurable { // Enable e2e encryption for newly created MXSession sdkOptions.enableCryptoWhenStartingMXSession = true + sdkOptions.computeE2ERoomSummaryTrust = false // Disable identicon use sdkOptions.disableIdenticonUseForUserAvatar = true + // Use UIKit BackgroundTask for handling background tasks in the SDK + sdkOptions.backgroundModeHandler = MXUIKitBackgroundModeHandler() + // Pass httpAdditionalHeaders to the SDK sdkOptions.httpAdditionalHeaders = BuildSettings.httpAdditionalHeaders diff --git a/RiotShareExtension/target.yml b/RiotShareExtension/target.yml index 25109d3411..335740f95b 100644 --- a/RiotShareExtension/target.yml +++ b/RiotShareExtension/target.yml @@ -40,6 +40,7 @@ targets: excludes: - "Shared/View/ShareRoomsRoomCell.*" - "Shared/View/ShareRoomsDiscussionCell.*" + - path: ../Config/CommonConfiguration.swift - path: ../Riot/Categories/Bundle.swift - path: ../Riot/Categories/Character.swift - path: ../Riot/Categories/MXKImageView.swift @@ -86,7 +87,6 @@ targets: # Tchap - path: ../RiotShareExtension/BuildSettings.swift - - path: ../Tchap/Config/CommonConfiguration.swift - path: ../Tchap/Config/Configurable.swift - path: ../Tchap/Extensions - path: ../Tchap/Generated/Images_Riot.swift diff --git a/Tchap/Config/CommonConfiguration.swift b/Tchap/Config/CommonConfiguration.swift deleted file mode 100644 index 67aa6cc69c..0000000000 --- a/Tchap/Config/CommonConfiguration.swift +++ /dev/null @@ -1,102 +0,0 @@ -// -// Copyright 2020 Vector Creations Ltd -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import Foundation - -/// CommonConfiguration is the central point to setup settings for MatrixSDK, MatrixKit and common configurations for all targets. -class CommonConfiguration: NSObject, Configurable { - - // MARK: - Global settings - - func setupSettings() { - setupMatrixKitSettings() - setupMatrixSDKSettings() - } - - private func setupMatrixKitSettings() { - guard let settings = MXKAppSettings.standard() else { - return - } - - // Disable CallKit - settings.isCallKitEnabled = false - - // Enable lazy loading - settings.syncWithLazyLoadOfRoomMembers = true - - settings.messageDetailsAllowSharing = BuildSettings.messageDetailsAllowShare - settings.messageDetailsAllowSaving = BuildSettings.messageDetailsAllowSave - settings.messageDetailsAllowCopyingMedia = BuildSettings.messageDetailsAllowCopyMedia - settings.messageDetailsAllowPastingMedia = BuildSettings.messageDetailsAllowPasteMedia - - MXKContactManager.shared().allowLocalContactsAccess = BuildSettings.allowLocalContactsAccess - } - - private func setupMatrixSDKSettings() { - let sdkOptions = MXSDKOptions.sharedInstance() - - sdkOptions.applicationGroupIdentifier = BuildSettings.applicationGroupIdentifier - - // Define the media cache version - sdkOptions.mediaCacheAppVersion = 0 - - // Enable e2e encryption for newly created MXSession - sdkOptions.enableCryptoWhenStartingMXSession = true - sdkOptions.computeE2ERoomSummaryTrust = false - - // Disable identicon use - sdkOptions.disableIdenticonUseForUserAvatar = true - - // Use UIKit BackgroundTask for handling background tasks in the SDK - sdkOptions.backgroundModeHandler = MXUIKitBackgroundModeHandler() - - // Pass httpAdditionalHeaders to the SDK - sdkOptions.httpAdditionalHeaders = BuildSettings.httpAdditionalHeaders - - // Disable key backup on common - sdkOptions.enableKeyBackupWhenStartingMXCrypto = false - } - - - // MARK: - Per matrix session settings - - func setupSettings(for matrixSession: MXSession) { - setupCallsSettings(for: matrixSession) - } - - private func setupCallsSettings(for matrixSession: MXSession) { - guard let callManager = matrixSession.callManager else { - // This means nothing happens if the project does not embed a VoIP stack - return - } - - // Let's call invite be valid for 1 minute - callManager.inviteLifetime = 60000 - - if RiotSettings.shared.allowStunServerFallback, let stunServerFallback = BuildSettings.stunServerFallbackUrlString { - callManager.fallbackSTUNServer = stunServerFallback - } - } - - - // MARK: - Per loaded matrix session settings - - func setupSettingsWhenLoaded(for matrixSession: MXSession) { - // Do not warn for unknown devices. We have cross-signing now - matrixSession.crypto.warnOnUnknowDevices = false - } - -} diff --git a/Tchap/target.yml b/Tchap/target.yml index cebd1706d0..92a4ea369c 100644 --- a/Tchap/target.yml +++ b/Tchap/target.yml @@ -63,6 +63,7 @@ targets: - path: ../Config/Project.xcconfig - path: ../Config/Project-Warnings.xcconfig - path: ../Config/AppIdentifiers.xcconfig + - path: ../Config/CommonConfiguration.swift - path: . excludes: - "Tools" diff --git a/TchapTests/target.yml b/TchapTests/target.yml index c739eb095d..e76c595b93 100644 --- a/TchapTests/target.yml +++ b/TchapTests/target.yml @@ -55,12 +55,12 @@ targets: sources: - path: . + - path: ../Config/CommonConfiguration.swift # Tchap - path: ../Tchap/Config/Configurable.swift - path: ../Tchap/Config/BuildSettings.swift - path: ../Tchap/Config/AppConfiguration.swift - - path: ../Tchap/Config/CommonConfiguration.swift # Riot - path: ../Riot/Categories/Bundle.swift diff --git a/changelog.d/528.bugfix b/changelog.d/528.bugfix new file mode 100644 index 0000000000..8071c7c79d --- /dev/null +++ b/changelog.d/528.bugfix @@ -0,0 +1 @@ +Unexpected logout From 506305a3c651eb73397854502396f4a5ee7c08ea Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 16 May 2022 16:26:42 +0200 Subject: [PATCH 2/5] Also remove duplicate Configurable.swift file --- Btchap/target.yml | 2 +- RiotShareExtension/target.yml | 2 +- Tchap/Config/Configurable.swift | 29 ----------------------------- Tchap/target.yml | 1 + TchapTests/target.yml | 2 +- 5 files changed, 4 insertions(+), 32 deletions(-) delete mode 100644 Tchap/Config/Configurable.swift diff --git a/Btchap/target.yml b/Btchap/target.yml index c33f9877e7..2b1ee0fa94 100644 --- a/Btchap/target.yml +++ b/Btchap/target.yml @@ -64,6 +64,7 @@ targets: - path: ../Config/Project-Warnings.xcconfig - path: ../Config/AppIdentifiers.xcconfig - path: ../Config/CommonConfiguration.swift + - path: ../Config/Configurable.swift - path: . excludes: - "**/*.strings" # Exclude all strings files @@ -262,7 +263,6 @@ targets: # Tchap - path: ../Tchap/Config/AppConfiguration.swift - - path: ../Tchap/Config/Configurable.swift # Resources - path: ../Riot/Assets/en.lproj/InfoPlist.strings diff --git a/RiotShareExtension/target.yml b/RiotShareExtension/target.yml index 335740f95b..26610a6404 100644 --- a/RiotShareExtension/target.yml +++ b/RiotShareExtension/target.yml @@ -41,6 +41,7 @@ targets: - "Shared/View/ShareRoomsRoomCell.*" - "Shared/View/ShareRoomsDiscussionCell.*" - path: ../Config/CommonConfiguration.swift + - path: ../Config/Configurable.swift - path: ../Riot/Categories/Bundle.swift - path: ../Riot/Categories/Character.swift - path: ../Riot/Categories/MXKImageView.swift @@ -87,7 +88,6 @@ targets: # Tchap - path: ../RiotShareExtension/BuildSettings.swift - - path: ../Tchap/Config/Configurable.swift - path: ../Tchap/Extensions - path: ../Tchap/Generated/Images_Riot.swift - path: ../Tchap/Generated/InfoPlist.swift diff --git a/Tchap/Config/Configurable.swift b/Tchap/Config/Configurable.swift deleted file mode 100644 index 80bee09d89..0000000000 --- a/Tchap/Config/Configurable.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// Copyright 2020 Vector Creations Ltd -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import Foundation - -/// Configurable expose settings app and its entensions must use. -@objc protocol Configurable { - // MARK: - Global settings - func setupSettings() - - // MARK: - Per matrix session settings - func setupSettings(for matrixSession: MXSession) - - // MARK: - Per loaded matrix session settings - func setupSettingsWhenLoaded(for matrixSession: MXSession) -} diff --git a/Tchap/target.yml b/Tchap/target.yml index 92a4ea369c..4b87f89138 100644 --- a/Tchap/target.yml +++ b/Tchap/target.yml @@ -64,6 +64,7 @@ targets: - path: ../Config/Project-Warnings.xcconfig - path: ../Config/AppIdentifiers.xcconfig - path: ../Config/CommonConfiguration.swift + - path: ../Config/Configurable.swift - path: . excludes: - "Tools" diff --git a/TchapTests/target.yml b/TchapTests/target.yml index e76c595b93..365f9fb1fc 100644 --- a/TchapTests/target.yml +++ b/TchapTests/target.yml @@ -56,9 +56,9 @@ targets: sources: - path: . - path: ../Config/CommonConfiguration.swift + - path: ../Config/Configurable.swift # Tchap - - path: ../Tchap/Config/Configurable.swift - path: ../Tchap/Config/BuildSettings.swift - path: ../Tchap/Config/AppConfiguration.swift From c504e35fa925f2b41b813c0d8285750e4538da7a Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 16 May 2022 16:39:18 +0200 Subject: [PATCH 3/5] And remove duplicate AppConfiguration.swift file --- Btchap/target.yml | 4 +- Config/AppConfiguration.swift | 11 ++++- Tchap/Config/AppConfiguration.swift | 75 ----------------------------- Tchap/target.yml | 1 + TchapTests/target.yml | 2 +- 5 files changed, 13 insertions(+), 80 deletions(-) delete mode 100644 Tchap/Config/AppConfiguration.swift diff --git a/Btchap/target.yml b/Btchap/target.yml index 2b1ee0fa94..eeaf10ac49 100644 --- a/Btchap/target.yml +++ b/Btchap/target.yml @@ -60,6 +60,7 @@ targets: sources: - path: ../Btchap/Config + - path: ../Config/AppConfiguration.swift - path: ../Config/Project.xcconfig - path: ../Config/Project-Warnings.xcconfig - path: ../Config/AppIdentifiers.xcconfig @@ -260,9 +261,6 @@ targets: - path: ../RiotShareExtension/Sources/ShareItemProtocol.swift - path: ../RiotShareExtension/Sources/ShareItemSender.h - path: ../RiotShareExtension/Sources/ShareItemSender.m - - # Tchap - - path: ../Tchap/Config/AppConfiguration.swift # Resources - path: ../Riot/Assets/en.lproj/InfoPlist.strings diff --git a/Config/AppConfiguration.swift b/Config/AppConfiguration.swift index 52b0416565..039d62ed94 100644 --- a/Config/AppConfiguration.swift +++ b/Config/AppConfiguration.swift @@ -28,12 +28,19 @@ class AppConfiguration: CommonConfiguration { private func setupAppSettings() { // Enable CallKit for app - MXKAppSettings.standard()?.isCallKitEnabled = true + //MXKAppSettings.standard()?.isCallKitEnabled = true // Get modular widget events in rooms histories MXKAppSettings.standard()?.addSupportedEventTypes([kWidgetMatrixEventTypeString, kWidgetModularEventTypeString]) + // Tchap: remove some state events from the rooms histories: creation, the history access, encryption, join rules + MXKAppSettings.standard()?.removeSupportedEventTypes([kMXEventTypeStringRoomCreate, + kMXEventTypeStringRoomHistoryVisibility, + kMXEventTypeStringRoomEncryption, + kMXEventTypeStringRoomGuestAccess, + kMXEventTypeStringRoomJoinRules]) + // Hide undecryptable messages that were sent while the user was not in the room MXKAppSettings.standard()?.hidePreJoinedUndecryptableEvents = true @@ -46,8 +53,10 @@ class AppConfiguration: CommonConfiguration { // Use UIKit BackgroundTask for handling background tasks in the SDK MXSDKOptions.sharedInstance().backgroundModeHandler = MXUIKitBackgroundModeHandler() + #if SUPPORT_KEYS_BACKUP // Enable key backup on app MXSDKOptions.sharedInstance().enableKeyBackupWhenStartingMXCrypto = true + #endif } diff --git a/Tchap/Config/AppConfiguration.swift b/Tchap/Config/AppConfiguration.swift deleted file mode 100644 index f5ccafc0f5..0000000000 --- a/Tchap/Config/AppConfiguration.swift +++ /dev/null @@ -1,75 +0,0 @@ -// -// Copyright 2020 Vector Creations Ltd -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import Foundation - -/// AppConfiguration is CommonConfiguration plus configurations dedicated to the app -class AppConfiguration: CommonConfiguration { - - // MARK: - Global settings - - override func setupSettings() { - super.setupSettings() - setupAppSettings() - } - - private func setupAppSettings() { - // Enable CallKit for app - //MXKAppSettings.standard()?.isCallKitEnabled = true - - // Get modular widget events in rooms histories - MXKAppSettings.standard()?.addSupportedEventTypes([kWidgetMatrixEventTypeString, - kWidgetModularEventTypeString]) - - // Tchap: remove some state events from the rooms histories: creation, the history access, encryption, join rules - MXKAppSettings.standard()?.removeSupportedEventTypes([kMXEventTypeStringRoomCreate, - kMXEventTypeStringRoomHistoryVisibility, - kMXEventTypeStringRoomEncryption, - kMXEventTypeStringRoomGuestAccess, - kMXEventTypeStringRoomJoinRules]) - - // Hide undecryptable messages that were sent while the user was not in the room - MXKAppSettings.standard()?.hidePreJoinedUndecryptableEvents = true - - // Enable long press on event in bubble cells - MXKRoomBubbleTableViewCell.disableLongPressGesture(onEvent: false) - - // Each room member will be considered as a potential contact. - MXKContactManager.shared().contactManagerMXRoomSource = MXKContactManagerMXRoomSource.all - - #if SUPPORT_KEYS_BACKUP - // Enable key backup on app - MXSDKOptions.sharedInstance().enableKeyBackupWhenStartingMXCrypto = true - #endif - } - - - // MARK: - Per matrix session settings - - override func setupSettings(for matrixSession: MXSession) { - super.setupSettings(for: matrixSession) - setupWidgetReadReceipts(for: matrixSession) - } - - private func setupWidgetReadReceipts(for matrixSession: MXSession) { - var acknowledgableEventTypes = matrixSession.acknowledgableEventTypes ?? [] - acknowledgableEventTypes.append(kWidgetMatrixEventTypeString) - acknowledgableEventTypes.append(kWidgetModularEventTypeString) - - matrixSession.acknowledgableEventTypes = acknowledgableEventTypes - } - -} diff --git a/Tchap/target.yml b/Tchap/target.yml index 4b87f89138..5b5eb0cdd7 100644 --- a/Tchap/target.yml +++ b/Tchap/target.yml @@ -60,6 +60,7 @@ targets: sources: - path: ../Tchap/Config + - path: ../Config/AppConfiguration.swift - path: ../Config/Project.xcconfig - path: ../Config/Project-Warnings.xcconfig - path: ../Config/AppIdentifiers.xcconfig diff --git a/TchapTests/target.yml b/TchapTests/target.yml index 365f9fb1fc..d5c78b4d13 100644 --- a/TchapTests/target.yml +++ b/TchapTests/target.yml @@ -55,12 +55,12 @@ targets: sources: - path: . + - path: ../Config/AppConfiguration.swift - path: ../Config/CommonConfiguration.swift - path: ../Config/Configurable.swift # Tchap - path: ../Tchap/Config/BuildSettings.swift - - path: ../Tchap/Config/AppConfiguration.swift # Riot - path: ../Riot/Categories/Bundle.swift From f78dcd5fb3c1ed1c816c22d8997b78b6a41871cf Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 16 May 2022 17:19:54 +0200 Subject: [PATCH 4/5] Remove a comment on AppConfiguration file --- Config/AppConfiguration.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config/AppConfiguration.swift b/Config/AppConfiguration.swift index 039d62ed94..d62d46f292 100644 --- a/Config/AppConfiguration.swift +++ b/Config/AppConfiguration.swift @@ -28,7 +28,7 @@ class AppConfiguration: CommonConfiguration { private func setupAppSettings() { // Enable CallKit for app - //MXKAppSettings.standard()?.isCallKitEnabled = true + MXKAppSettings.standard()?.isCallKitEnabled = false // Get modular widget events in rooms histories MXKAppSettings.standard()?.addSupportedEventTypes([kWidgetMatrixEventTypeString, From f58d17f1e0dadf24890b3f1e606a0f73f544cc71 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 16 May 2022 17:42:58 +0200 Subject: [PATCH 5/5] Update comment for CallKit --- Config/AppConfiguration.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config/AppConfiguration.swift b/Config/AppConfiguration.swift index d62d46f292..451dee5aad 100644 --- a/Config/AppConfiguration.swift +++ b/Config/AppConfiguration.swift @@ -27,7 +27,7 @@ class AppConfiguration: CommonConfiguration { } private func setupAppSettings() { - // Enable CallKit for app + // Tchap: Disable CallKit. MXKAppSettings.standard()?.isCallKitEnabled = false // Get modular widget events in rooms histories