From fa8ba86f3facf32a9e13c734809afff2fe96468b Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Tue, 23 Jan 2024 16:19:06 +0100 Subject: [PATCH 1/3] Refactor Feature Flag variables names --- Btchap/Config/BuildSettings.swift | 2 +- DevTchap/Config/BuildSettings.swift | 2 +- Tchap/Config/BuildSettings.swift | 9 ++++++++- Tchap/Extensions/Account+Tchap.swift | 6 +++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Btchap/Config/BuildSettings.swift b/Btchap/Config/BuildSettings.swift index be2ba7f63..f577db02a 100644 --- a/Btchap/Config/BuildSettings.swift +++ b/Btchap/Config/BuildSettings.swift @@ -237,7 +237,7 @@ final class BuildSettings: NSObject { static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" // Tchap: in pre-prod, allow any feature to any instance. - static var tchapFeatureByHomeServer: [String: [String]] = [ + static var tchapFeaturesAllowedHomeServersForFeature: [String: [String]] = [ tchapFeatureAnyFeature: [ tchapFeatureAnyHomeServer ] ] diff --git a/DevTchap/Config/BuildSettings.swift b/DevTchap/Config/BuildSettings.swift index f85634943..58ee2009f 100644 --- a/DevTchap/Config/BuildSettings.swift +++ b/DevTchap/Config/BuildSettings.swift @@ -238,7 +238,7 @@ final class BuildSettings: NSObject { static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" // Tchap: in Dev, allow any feature to any instance. - static var tchapFeatureByHomeServer: [String: [String]] = [ + static var tchapFeaturesAllowedHomeServersForFeature: [String: [String]] = [ tchapFeatureAnyFeature: [ tchapFeatureAnyHomeServer ] ] diff --git a/Tchap/Config/BuildSettings.swift b/Tchap/Config/BuildSettings.swift index e5e60bd55..15bd01100 100644 --- a/Tchap/Config/BuildSettings.swift +++ b/Tchap/Config/BuildSettings.swift @@ -267,10 +267,17 @@ final class BuildSettings: NSObject { static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" - static var tchapFeatureByHomeServer: [String: [String]] = [ + static var tchapFeaturesAllowedHomeServersForFeature: [String: [String]] = [ tchapFeatureNotificationByEmail: [ "agent.dinum.tchap.gouv.fr" + ], + tchapFeatureVoiceOverIP: [ + "agent.dinum.tchap.gouv.fr" ] + // No activation of video calls actually in Tchap Production. +// tchapFeatureVideoOverIP: [ +// "agent.dinum.tchap.gouv.fr" +// ], ] // MARK: - Side Menu diff --git a/Tchap/Extensions/Account+Tchap.swift b/Tchap/Extensions/Account+Tchap.swift index 9223e9cd3..ef21323c9 100644 --- a/Tchap/Extensions/Account+Tchap.swift +++ b/Tchap/Extensions/Account+Tchap.swift @@ -19,11 +19,11 @@ import Foundation @objc extension MXKAccount { func isFeatureActivated(_ featureId: String) -> Bool { - guard let targetedFeature = BuildSettings.tchapFeatureByHomeServer[featureId] ?? BuildSettings.tchapFeatureByHomeServer[BuildSettings.tchapFeatureAnyFeature] else { + guard let allowedHomeServers = BuildSettings.tchapFeaturesAllowedHomeServersForFeature[featureId] ?? BuildSettings.tchapFeaturesAllowedHomeServersForFeature[BuildSettings.tchapFeatureAnyFeature] else { return false } - if targetedFeature.contains(BuildSettings.tchapFeatureAnyHomeServer) { + if allowedHomeServers.contains(BuildSettings.tchapFeatureAnyHomeServer) { return true } @@ -33,6 +33,6 @@ import Foundation let homeServerDomain = homeServerURL.replacingOccurrences(of: BuildSettings.serverUrlPrefix, with: "") - return targetedFeature.contains(homeServerDomain) + return allowedHomeServers.contains(homeServerDomain) } } From aed576c85d1fdeb82e396ffed5c856a7796cc8f0 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Tue, 23 Jan 2024 16:20:00 +0100 Subject: [PATCH 2/3] Use features Flag to activate VoIP feature for DINUM only --- .../Room/RoomDisplayConfiguration.swift | 13 ++------ Riot/Modules/Room/RoomViewController.m | 33 +++++++++++-------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Riot/Modules/Room/RoomDisplayConfiguration.swift b/Riot/Modules/Room/RoomDisplayConfiguration.swift index 40635fb36..e3d4a82ea 100644 --- a/Riot/Modules/Room/RoomDisplayConfiguration.swift +++ b/Riot/Modules/Room/RoomDisplayConfiguration.swift @@ -27,20 +27,13 @@ class RoomDisplayConfiguration: NSObject { guard _tchapCallsEnabled, let account = MXKAccountManager.shared().activeAccounts.first else { return false } - // Tchap: allow VoIP for Pre-prod and Dev version - if ["fr.gouv.btchap", "fr.gouv.tchap.dev"].contains(BuildSettings.baseBundleIdentifier) - { + // Tchap: actually, only allow VoIP for DINUM homeServer. + if (account.isFeatureActivated(BuildSettings.tchapFeatureVoiceOverIP) || account.isFeatureActivated(BuildSettings.tchapFeatureVideoOverIP)) { return true } - // Tchap: actually, only allow VoIP for DINUM homeServer. - let allowedHomeServersForCalls = ["agent.dinum.tchap.gouv.fr"] - guard let currentHomeServerName = account.mxSession.credentials.homeServerName() else { + else { return false } - let callsAreEnabled = allowedHomeServersForCalls.firstIndex { - currentHomeServerName.hasSuffix($0) - } != nil - return callsAreEnabled } let integrationsEnabled: Bool diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 3e0691f62..63a47078e 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -1955,20 +1955,27 @@ - (void)refreshRoomTitle && self.roomDataSource.room.isDirect && !self.mainSession.vc_homeserverConfiguration.jitsi.useFor1To1Calls) { - // voice call button for Matrix call - UIBarButtonItem *itemVoice = [[UIBarButtonItem alloc] initWithImage:AssetImages.voiceCallHangonIcon.image - style:UIBarButtonItemStylePlain - target:self - action:@selector(onVoiceCallPressed:)]; - itemVoice.accessibilityLabel = [VectorL10n roomAccessibilityCall]; - itemVoice.enabled = !self.isCallActive; - [rightBarButtonItems addObject:itemVoice]; + MXKAccount *account = MXKAccountManager.sharedManager.activeAccounts.firstObject; - // video call button for Matrix call -// Tchap: Disable video call actually -// UIBarButtonItem *itemVideo = [self videoCallBarButtonItem]; -// itemVideo.enabled = !self.isCallActive; -// [rightBarButtonItems addObject:itemVideo]; + if (account != nil && [account isFeatureActivated:BuildSettings.tchapFeatureVoiceOverIP]) + { + // voice call button for Matrix call + UIBarButtonItem *itemVoice = [[UIBarButtonItem alloc] initWithImage:AssetImages.voiceCallHangonIcon.image + style:UIBarButtonItemStylePlain + target:self + action:@selector(onVoiceCallPressed:)]; + itemVoice.accessibilityLabel = [VectorL10n roomAccessibilityCall]; + itemVoice.enabled = !self.isCallActive; + [rightBarButtonItems addObject:itemVoice]; + } + + if (account != nil && [account isFeatureActivated:BuildSettings.tchapFeatureVideoOverIP]) + { + // video call button for Matrix call + UIBarButtonItem *itemVideo = [self videoCallBarButtonItem]; + itemVideo.enabled = !self.isCallActive; + [rightBarButtonItems addObject:itemVideo]; + } } else { From d0561d0b8c74f10f8e9c3dce7e155ea92b4efd3a Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Tue, 23 Jan 2024 16:20:58 +0100 Subject: [PATCH 3/3] Add changelog --- changelog.d/957.change | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/957.change diff --git a/changelog.d/957.change b/changelog.d/957.change new file mode 100644 index 000000000..ccadf25a5 --- /dev/null +++ b/changelog.d/957.change @@ -0,0 +1 @@ +Utiliser les Features Flags pour activer la VoIP pour la Dinum \ No newline at end of file