diff --git a/Config/AppConfig.swift b/Config/AppConfig.swift index f0a9bff38..971971d5e 100644 --- a/Config/AppConfig.swift +++ b/Config/AppConfig.swift @@ -17,57 +17,19 @@ import Foundation import MatrixKit -/// AppConfig is the central point to setup settings for MatrixSDK, MatrixKit and the app. -@objcMembers -final class AppConfig: NSObject { - - static let shared = AppConfig() +/// AppConfig is Config plus configuration dedicated to the app +@objcMembers class AppConfig: Config { + static let sharedAppConfig = AppConfig() // MARK: - Global settings - func setupSettings() { - setupMatrixKitSettings() - setupMatrixSDKSettings() + override func setupSettings() { + super.setupSettings() setupAppSettings() } - private func setupMatrixKitSettings() { - guard let settings = MXKAppSettings.standard() else { - return - } - - // Customize the localized string table - Bundle.mxk_customizeLocalizedStringTableName("Vector") - - // Disable CallKit - settings.isCallKitEnabled = false - - // Enable lazy loading - settings.syncWithLazyLoadOfRoomMembers = true - } - - private func setupMatrixSDKSettings() { - let sdkOptions = MXSDKOptions.sharedInstance() - - sdkOptions.applicationGroupIdentifier = "group.im.vector" - - // Define the media cache version - sdkOptions.mediaCacheAppVersion = 0 - - // Enable e2e encryption for newly created MXSession - sdkOptions.enableCryptoWhenStartingMXSession = true - sdkOptions.computeE2ERoomSummaryTrust = true - - // Disable identicon use - sdkOptions.disableIdenticonUseForUserAvatar = true - - // Use UIKit BackgroundTask for handling background tasks in the SDK - sdkOptions.backgroundModeHandler = MXUIKitBackgroundModeHandler() - } - private func setupAppSettings() { - // Enable long press on event in bubble cells MXKRoomBubbleTableViewCell.disableLongPressGesture(onEvent: false) @@ -78,40 +40,17 @@ final class AppConfig: NSObject { // MARK: - Per matrix session settings - func setupSettings(for matrixSession: MXSession) { - setupCallsSettings(for: matrixSession) + override func setupSettings(for matrixSession: MXSession) { + super.setupSettings(for: matrixSession) setupWidgetReadReceipts(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 = RiotSettings.shared.stunServerFallback { - callManager.fallbackSTUNServer = stunServerFallback - } - } - + private func setupWidgetReadReceipts(for matrixSession: MXSession) { -// TODO -// var acknowledgableEventTypes = matrixSession.acknowledgableEventTypes ?? [] -// acknowledgableEventTypes.append(kWidgetMatrixEventTypeString) -// acknowledgableEventTypes.append(kWidgetModularEventTypeString) -// -// matrixSession.acknowledgableEventTypes = acknowledgableEventTypes - } - - - // 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 + var acknowledgableEventTypes = matrixSession.acknowledgableEventTypes ?? [] + acknowledgableEventTypes.append(kWidgetMatrixEventTypeString) + acknowledgableEventTypes.append(kWidgetModularEventTypeString) + + matrixSession.acknowledgableEventTypes = acknowledgableEventTypes } } diff --git a/Config/Config.swift b/Config/Config.swift new file mode 100644 index 000000000..709e8203d --- /dev/null +++ b/Config/Config.swift @@ -0,0 +1,96 @@ +// +// 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 +import MatrixKit + +/// Config is the central point to setup settings for MatrixSDK, MatrixKit. +@objcMembers class Config: NSObject { + + static let shared = Config() + + + // MARK: - Global settings + + func setupSettings() { + setupMatrixKitSettings() + setupMatrixSDKSettings() + } + + private func setupMatrixKitSettings() { + guard let settings = MXKAppSettings.standard() else { + return + } + + // Customize the localized string table + Bundle.mxk_customizeLocalizedStringTableName("Vector") + + // Disable CallKit + settings.isCallKitEnabled = false + + // Enable lazy loading + settings.syncWithLazyLoadOfRoomMembers = true + } + + private func setupMatrixSDKSettings() { + let sdkOptions = MXSDKOptions.sharedInstance() + + sdkOptions.applicationGroupIdentifier = "group.im.vector" + + // Define the media cache version + sdkOptions.mediaCacheAppVersion = 0 + + // Enable e2e encryption for newly created MXSession + sdkOptions.enableCryptoWhenStartingMXSession = true + sdkOptions.computeE2ERoomSummaryTrust = true + + // Disable identicon use + sdkOptions.disableIdenticonUseForUserAvatar = true + + // Use UIKit BackgroundTask for handling background tasks in the SDK + sdkOptions.backgroundModeHandler = MXUIKitBackgroundModeHandler() + } + + + // 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 = RiotSettings.shared.stunServerFallback { + 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/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index d206de2ca..40eb41639 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -116,12 +116,14 @@ 32F6B96C2270623100BBA352 /* KeyVerificationDataLoadingCoordinatorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32F6B9662270623100BBA352 /* KeyVerificationDataLoadingCoordinatorType.swift */; }; 32F6B96D2270623100BBA352 /* KeyVerificationDataLoadingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32F6B9672270623100BBA352 /* KeyVerificationDataLoadingViewModel.swift */; }; 32F6B96E2270623100BBA352 /* KeyVerificationDataLoadingViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32F6B9682270623100BBA352 /* KeyVerificationDataLoadingViewModelType.swift */; }; - 32FD754724D06B4200BA7B37 /* AppConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 328E410524CB168500DC4490 /* AppConfig.swift */; }; - 32FD754824D06DCC00BA7B37 /* AppConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 328E410524CB168500DC4490 /* AppConfig.swift */; }; - 32FD754924D06DDB00BA7B37 /* AppConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 328E410524CB168500DC4490 /* AppConfig.swift */; }; - 32FD754B24D06EA600BA7B37 /* AppConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 328E410524CB168500DC4490 /* AppConfig.swift */; }; 32FD754C24D06EBE00BA7B37 /* RiotSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1B5597F20EFC3DF00210D55 /* RiotSettings.swift */; }; 32FD754D24D06EBF00BA7B37 /* RiotSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1B5597F20EFC3DF00210D55 /* RiotSettings.swift */; }; + 32FD755024D074C700BA7B37 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32FD754F24D074C700BA7B37 /* Config.swift */; }; + 32FD755124D074C700BA7B37 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32FD754F24D074C700BA7B37 /* Config.swift */; }; + 32FD755224D074C700BA7B37 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32FD754F24D074C700BA7B37 /* Config.swift */; }; + 32FD755324D074C700BA7B37 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32FD754F24D074C700BA7B37 /* Config.swift */; }; + 32FD755424D074C700BA7B37 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32FD754F24D074C700BA7B37 /* Config.swift */; }; + 32FD755524D0754500BA7B37 /* AppConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 328E410524CB168500DC4490 /* AppConfig.swift */; }; 32FDC1CD2386CD390084717A /* RiotSettingIntegrationProvisioning.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32FDC1CC2386CD390084717A /* RiotSettingIntegrationProvisioning.swift */; }; 39D49C6524B8D40500FEDBC8 /* ElementViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39D49C6224B8D40500FEDBC8 /* ElementViewController.swift */; }; 39D49C6624B8D40500FEDBC8 /* Timeline_1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39D49C6324B8D40500FEDBC8 /* Timeline_1.swift */; }; @@ -1002,6 +1004,7 @@ 32F6B9662270623100BBA352 /* KeyVerificationDataLoadingCoordinatorType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyVerificationDataLoadingCoordinatorType.swift; sourceTree = ""; }; 32F6B9672270623100BBA352 /* KeyVerificationDataLoadingViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyVerificationDataLoadingViewModel.swift; sourceTree = ""; }; 32F6B9682270623100BBA352 /* KeyVerificationDataLoadingViewModelType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyVerificationDataLoadingViewModelType.swift; sourceTree = ""; }; + 32FD754F24D074C700BA7B37 /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = ""; }; 32FDC1CC2386CD390084717A /* RiotSettingIntegrationProvisioning.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RiotSettingIntegrationProvisioning.swift; sourceTree = ""; }; 3942DD65EBEB7AE647C6392A /* Pods-RiotPods-SiriIntents.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiotPods-SiriIntents.debug.xcconfig"; path = "Target Support Files/Pods-RiotPods-SiriIntents/Pods-RiotPods-SiriIntents.debug.xcconfig"; sourceTree = ""; }; 39D49C6224B8D40500FEDBC8 /* ElementViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ElementViewController.swift; sourceTree = ""; }; @@ -2295,6 +2298,7 @@ 32FD754E24D073E400BA7B37 /* Config */ = { isa = PBXGroup; children = ( + 32FD754F24D074C700BA7B37 /* Config.swift */, 328E410524CB168500DC4490 /* AppConfig.swift */, ); path = Config; @@ -5472,9 +5476,9 @@ B1664BCF20F4E67600808783 /* ShareExtensionManager.m in Sources */, B1DB4F0722301AF20065DBFA /* Character.swift in Sources */, 3209451321F1C1D50088CAA2 /* BlackTheme.swift in Sources */, - 32FD754824D06DCC00BA7B37 /* AppConfig.swift in Sources */, 24EEE5A21F23A8B400B3C705 /* MXRoom+Riot.m in Sources */, B1664BC720F4E67600808783 /* SharePresentingViewController.m in Sources */, + 32FD755224D074C700BA7B37 /* Config.swift in Sources */, B1DB4F0F223170000065DBFA /* UserNameColorGenerator.swift in Sources */, F0A8955F1F7D1FEA00BD6C2A /* MXRoomSummary+Riot.m in Sources */, 32242F1721E8FBE500725742 /* Theme.swift in Sources */, @@ -5495,8 +5499,8 @@ buildActionMask = 2147483647; files = ( 92726A471F58737A004AD26F /* IntentHandler.m in Sources */, + 32FD755324D074C700BA7B37 /* Config.swift in Sources */, 32FD754C24D06EBE00BA7B37 /* RiotSettings.swift in Sources */, - 32FD754B24D06EA600BA7B37 /* AppConfig.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -5507,8 +5511,8 @@ EC85D74F2477E8EB002C44C9 /* RiotSettings.swift in Sources */, EC85D757247E700F002C44C9 /* NSEMemoryStore.swift in Sources */, EC2B4EF224A1EF34005EB739 /* DataProtectionHelper.swift in Sources */, - 32FD754724D06B4200BA7B37 /* AppConfig.swift in Sources */, EC85D7462477E5F7002C44C9 /* NotificationService.swift in Sources */, + 32FD755424D074C700BA7B37 /* Config.swift in Sources */, EC85D752247C0F52002C44C9 /* UNUserNotificationCenter.swift in Sources */, EC85D755247C0F84002C44C9 /* Constants.swift in Sources */, ); @@ -5779,6 +5783,7 @@ B1B5593C20EF7BAC00210D55 /* TableViewCellWithCheckBoxes.m in Sources */, 32891D6B2264CBA300C82226 /* SimpleScreenTemplateViewController.swift in Sources */, EC711B7924A63B37008F830C /* SecretsSetupRecoveryKeyViewController.swift in Sources */, + 32FD755024D074C700BA7B37 /* Config.swift in Sources */, B1CA3A2721EF6914000D1D89 /* UIViewController.swift in Sources */, 322C110822BBC6F80043FEAC /* WidgetManagerConfig.swift in Sources */, F0D2ADA11F6AA5FD00A7097D /* MXRoomSummary+Riot.m in Sources */, @@ -6109,7 +6114,8 @@ buildActionMask = 2147483647; files = ( 32FD754D24D06EBF00BA7B37 /* RiotSettings.swift in Sources */, - 32FD754924D06DDB00BA7B37 /* AppConfig.swift in Sources */, + 32FD755524D0754500BA7B37 /* AppConfig.swift in Sources */, + 32FD755124D074C700BA7B37 /* Config.swift in Sources */, F083BEA51E70356E00A9B29C /* RiotTests.m in Sources */, B152C73122DF561E0041315A /* EmojiServiceTests.swift in Sources */, ); diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index 181ba5a9f..5c7feebd1 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -250,7 +250,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni NSLog(@"[AppDelegate] initialize"); // Set static application settings - [AppConfig.shared setupSettings]; + [AppConfig.sharedAppConfig setupSettings]; // Redirect NSLogs to files only if we are not debugging if (!isatty(STDERR_FILENO)) @@ -1857,7 +1857,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni [self enableNoVoIPOnMatrixSession:mxSession]; } - [AppConfig.shared setupSettingsFor:mxSession]; + [AppConfig.sharedAppConfig setupSettingsFor:mxSession]; } else if (mxSession.state == MXSessionStateStoreDataReady) { @@ -1876,7 +1876,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni } } - [AppConfig.shared setupSettingsWhenLoadedFor:mxSession]; + [AppConfig.sharedAppConfig setupSettingsWhenLoadedFor:mxSession]; // Register to user new device sign in notification [self registerUserDidSignInOnNewDeviceNotificationForSession:mxSession]; diff --git a/RiotNSE/NotificationService.swift b/RiotNSE/NotificationService.swift index 987d902e7..7eb870686 100644 --- a/RiotNSE/NotificationService.swift +++ b/RiotNSE/NotificationService.swift @@ -35,7 +35,7 @@ class NotificationService: UNNotificationServiceExtension { override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { // Set static application settings - AppConfig.shared.setupSettings() + Config.shared.setupSettings() if DataProtectionHelper.isDeviceInRebootedAndLockedState(appGroupIdentifier: MXSDKOptions.sharedInstance().applicationGroupIdentifier) { // kill the process in this state, this leads for the notification to be displayed as came from APNS diff --git a/RiotShareExtension/Managers/ShareExtensionManager.m b/RiotShareExtension/Managers/ShareExtensionManager.m index e718c8cb4..e54463d08 100644 --- a/RiotShareExtension/Managers/ShareExtensionManager.m +++ b/RiotShareExtension/Managers/ShareExtensionManager.m @@ -75,7 +75,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) [NSNotificationCenter.defaultCenter addObserver:sharedInstance selector:@selector(didReceiveMemoryWarning:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; // Set static application settings - [AppConfig.shared setupSettings]; + [Config.shared setupSettings]; // NSLog -> console.log file when not debugging the app if (!isatty(STDERR_FILENO)) diff --git a/SiriIntents/IntentHandler.m b/SiriIntents/IntentHandler.m index fa23db9ae..4eaf02c2b 100644 --- a/SiriIntents/IntentHandler.m +++ b/SiriIntents/IntentHandler.m @@ -36,7 +36,7 @@ if (self) { // Set static application settings - [AppConfig.shared setupSettings]; + [Config.shared setupSettings]; // NSLog -> console.log file when not debugging the app if (!isatty(STDERR_FILENO))