diff --git a/Riot/Assets/de.lproj/Bwi.strings b/Riot/Assets/de.lproj/Bwi.strings index 57f7a6465..6f2423bdf 100644 --- a/Riot/Assets/de.lproj/Bwi.strings +++ b/Riot/Assets/de.lproj/Bwi.strings @@ -51,7 +51,9 @@ "bwi_settings_developer_restrict_user" = "Nutzer einschränken"; "bwi_settings_developer_unrestrict_user" = "Nutzereinschränkung aufheben"; "bwi_settings_developer_unmark_banner" = "Banner als nicht gelesen markieren"; -"bwi_settings_developer_introduce_federation" = "Erklärung zur Föderation"; +"bwi_settings_developer_introduce_federation" = "Föderation"; +"bwi_settings_developer_introduce_federation_preview" = "Vorschau zeigen"; +"bwi_settings_developer_introduce_federation_reset" = "Account Data Flag urücksetzen"; "bwi_settings_developer_well_known" = "Well-Known"; "bwi_settings_developer_capabilities" = "Capabilities"; "bwi_settings_developer_maintenance" = "Maintenance"; diff --git a/Riot/Assets/en.lproj/Bwi.strings b/Riot/Assets/en.lproj/Bwi.strings index cd756b03d..7406e3db9 100644 --- a/Riot/Assets/en.lproj/Bwi.strings +++ b/Riot/Assets/en.lproj/Bwi.strings @@ -52,7 +52,9 @@ "bwi_settings_developer_restrict_user" = "Restrict user"; "bwi_settings_developer_unrestrict_user" = "Remove user restriction"; "bwi_settings_developer_unmark_banner" = "Unmark Feature Banner"; -"bwi_settings_developer_introduce_federation" = "Introduce Federation"; +"bwi_settings_developer_introduce_federation" = "Federation"; +"bwi_settings_developer_introduce_federation_preview" = "Show preview"; +"bwi_settings_developer_introduce_federation_reset" = "Reset account data flag"; "bwi_settings_developer_well_known" = "Well-Known"; "bwi_settings_developer_capabilities" = "Capabilities"; "bwi_settings_developer_maintenance" = "Maintenance"; diff --git a/Riot/Modules/Home/AllChats/AllChatsViewController.swift b/Riot/Modules/Home/AllChats/AllChatsViewController.swift index b827f8e8e..5a7503320 100644 --- a/Riot/Modules/Home/AllChats/AllChatsViewController.swift +++ b/Riot/Modules/Home/AllChats/AllChatsViewController.swift @@ -17,6 +17,7 @@ // swiftlint:disable file_length import UIKit +import SwiftUI import Reusable protocol AllChatsViewControllerDelegate: AnyObject { @@ -321,8 +322,31 @@ class AllChatsViewController: HomeViewController { } AppDelegate.theDelegate().checkAppVersion() - + } + + func presentFederationIntroductionSheet(completion: @escaping () -> Void) { + guard BWIBuildSettings.shared.isFederationEnabled else { + completion() + return + } + guard self.mainSession.homeserverWellknown.shouldShowFederationIntroduction() else { + completion() + return + } + + let notificationService = BWIAccountNotificationService(mxSession: self.mainSession) + guard notificationService.showFederationIntroductionFlag() else { + completion() + return + } + + let viewController = UIHostingController(rootView: IntroduceFederationView()) + viewController.modalPresentationStyle = .fullScreen + present(viewController, animated: true) { + notificationService.setShowFederationIntroductionFlag(false) + completion() + } } override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { @@ -487,6 +511,9 @@ class AllChatsViewController: HomeViewController { })) self.present(alert, animated: true) + + presentFederationIntroductionSheet { + } } // MARK: - Actions diff --git a/bwi/DeveloperSettings/DeveloperSettingsView.swift b/bwi/DeveloperSettings/DeveloperSettingsView.swift index 8effb1b1b..7cbcd003e 100644 --- a/bwi/DeveloperSettings/DeveloperSettingsView.swift +++ b/bwi/DeveloperSettings/DeveloperSettingsView.swift @@ -80,14 +80,23 @@ struct DeveloperSettingsView: View { .foregroundColor(Color(ThemeService.shared().theme.tintColor)) .font(.system(size: 17)) } + } + SwiftUI.Section(header: Text(BWIL10n.bwiSettingsDeveloperIntroduceFederation)) { Button(action: { showIntroduceFederation = true }) { - Text(BWIL10n.bwiSettingsDeveloperIntroduceFederation) + Text(BWIL10n.bwiSettingsDeveloperIntroduceFederationPreview) .foregroundColor(Color(ThemeService.shared().theme.tintColor)) .font(.system(size: 17)) } .sheet(isPresented: $showIntroduceFederation) { IntroduceFederationView() - .interactiveDismissDisabled() + .interactiveDismissDisabled() + } + if let session = session { + Button(action: { BWIAccountNotificationService(mxSession: session).setShowFederationIntroductionFlag(true) }) { + Text(BWIL10n.bwiSettingsDeveloperIntroduceFederationReset) + .foregroundColor(Color(ThemeService.shared().theme.tintColor)) + .font(.system(size: 17)) + } } } if BWIBuildSettings.shared.permalinkPrefixSettings && !BWIBuildSettings.shared.permalinkPrefixes.isEmpty { @@ -139,12 +148,12 @@ struct DeveloperSettingsView: View { } -@available(iOS 14.0, *) -struct DeveloperSettingsView_Previews: PreviewProvider { - static var previews: some View { - DeveloperSettingsView(session: nil) - } -} +//@available(iOS 14.0, *) +//struct DeveloperSettingsView_Previews: PreviewProvider { +// static var previews: some View { +// DeveloperSettingsView(session: nil) +// } +//} // MARK: - Button Actions diff --git a/bwi/Tools/BWIAccountNotificationService.swift b/bwi/Tools/BWIAccountNotificationService.swift index 57029b41c..f906cd610 100644 --- a/bwi/Tools/BWIAccountNotificationService.swift +++ b/bwi/Tools/BWIAccountNotificationService.swift @@ -24,13 +24,17 @@ import Foundation enum CodingKeys: String, CodingKey { case analyticsPromt = "should_show_analytics_consent_dialog" case birthdayPromt = "should_show_ios_birthday_notification" + case federationAnnouncement = "should_show_federation_announcement" + case federationIntroduction = "should_show_federation_introduction" } let analyticsPromt: Bool let birthdayPromt: Bool + let federationAnnouncement: Bool + let federationIntroduction: Bool init(_ dict: [String: Any]) { - + if let analyticsVal = dict[AccountNotifications.CodingKeys.analyticsPromt.rawValue] as? Bool { analyticsPromt = analyticsVal } else { @@ -41,6 +45,16 @@ import Foundation } else { birthdayPromt = false } + if let federationAnnouncementVal = dict[AccountNotifications.CodingKeys.federationAnnouncement.rawValue] as? Bool { + federationAnnouncement = federationAnnouncementVal + } else { + federationAnnouncement = false + } + if let federationIntroductionVal = dict[AccountNotifications.CodingKeys.federationIntroduction.rawValue] as? Bool { + federationIntroduction = federationIntroductionVal + } else { + federationIntroduction = false + } } } @@ -70,4 +84,37 @@ import Foundation session.setAccountData(notificationsDict, forType: AccountDataTypes.notifications, success: nil, failure: nil) } + + func showFederationAnnouncementFlag() -> Bool { + guard let notificationsDict = session.accountData.accountData(forEventType: AccountDataTypes.notifications) as? [String: Any] else { + return false + } + + let notifications = AccountNotifications(notificationsDict) + return notifications.federationAnnouncement + } + + func setShowFederationAnnouncementFlag(_ value: Bool) { + var notificationsDict = session.accountData.accountData(forEventType: AccountDataTypes.notifications) ?? [:] + notificationsDict[AccountNotifications.CodingKeys.federationAnnouncement.rawValue] = value + + session.setAccountData(notificationsDict, forType: AccountDataTypes.notifications, success: nil, failure: nil) + } + + func showFederationIntroductionFlag() -> Bool { + guard let notificationsDict = session.accountData.accountData(forEventType: AccountDataTypes.notifications) as? [String: Any] else { + return false + } + + let notifications = AccountNotifications(notificationsDict) + return notifications.federationIntroduction + } + + func setShowFederationIntroductionFlag(_ value: Bool) { + var notificationsDict = session.accountData.accountData(forEventType: AccountDataTypes.notifications) ?? [:] + notificationsDict[AccountNotifications.CodingKeys.federationIntroduction.rawValue] = value + + session.setAccountData(notificationsDict, forType: AccountDataTypes.notifications, success: nil, failure: nil) + } + } diff --git a/bwi/Wellknown/Wellknown+Bwi.swift b/bwi/Wellknown/Wellknown+Bwi.swift index ae290aada..598e20325 100644 --- a/bwi/Wellknown/Wellknown+Bwi.swift +++ b/bwi/Wellknown/Wellknown+Bwi.swift @@ -66,6 +66,16 @@ public extension MXWellKnown { } } + // returns true if the federation introduction screen should be presented to the new users + @objc func shouldShowFederationIntroduction() -> Bool { + do { + let bwi = try WellknownBWI(dict: self.jsonDictionary()["de.bwi"] as! [String : Any]) + return bwi.federation?.showIntroduction ?? false + } catch { + return true + } + } + // returns true if there is a valid url or no url, only the case "is url" but not valid is wrong @objc func isValidDataPrivacyURL() -> Bool { do { diff --git a/bwi/Wellknown/WellknownBWI.swift b/bwi/Wellknown/WellknownBWI.swift index 6b166a20a..23d2a05f9 100644 --- a/bwi/Wellknown/WellknownBWI.swift +++ b/bwi/Wellknown/WellknownBWI.swift @@ -17,20 +17,32 @@ import Foundation -struct WellknownBWI { +struct WellknownBWI: Decodable { let dataPrivacyURL: String? let imprintURL: String? + let federation: Federation? init(dict: [String: Any]) throws { let jsonData = try JSONSerialization.data(withJSONObject: dict, options: []) let decoder = JSONDecoder() self = try decoder.decode(Self.self, from: jsonData) } -} - -extension WellknownBWI: Decodable { + enum CodingKeys: String, CodingKey { case dataPrivacyURL = "data_privacy_url" case imprintURL = "imprint_url" + case federation + } +} + +struct Federation: Decodable { + let showAnnouncement: Bool? + let showIntroduction: Bool? + let enable: Bool? + + enum CodingKeys: String, CodingKey { + case showAnnouncement = "show_announcement" + case showIntroduction = "show_introduction" + case enable } }