MESSENGER-5892 refactoring

This commit is contained in:
JanNiklas Grabowski
2024-04-02 14:19:09 +02:00
parent 6de4679041
commit 2d05d9c0d5
4 changed files with 22 additions and 11 deletions

View File

@@ -772,8 +772,9 @@ class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
}
// bwi #4478: refresh wellknown a bit more often
self.currentMatrixSession?.refreshHomeserverWellknown(false, success: { _ in
self.currentMatrixSession?.refreshHomeserverWellknown(false, success: { wellknown in
// bwi: #5706 fix crash: only show matomo alert when wellknown is available
wellknown?.updateFederationStatus()
self.bwiCheckForMatomoPromt()
}, failure: nil)
}

View File

@@ -239,6 +239,7 @@ class AuthenticationService: NSObject {
// FRROT wellknown call for identity server after server selection
if let wellKnown = try? await wellKnown(for: homeserverURL) {
self.wellknown = wellKnown
wellknown?.updateFederationStatus()
if let baseURL = URL(string: wellKnown.homeServer.baseUrl) {
homeserverURL = baseURL

View File

@@ -93,6 +93,25 @@ public extension MXWellKnown {
return false
}
}
@objc func updateFederationStatus() {
do {
guard let bwiDict = self.jsonDictionary()["de.bwi"] as? [String : Any] else {
BWIBuildSettings.shared.isWellknownFederationEnabled = false
return
}
let bwi = try WellknownBWI(dict: bwiDict)
if let federation = bwi.federation {
BWIBuildSettings.shared.isWellknownFederationEnabled = federation.enable ?? false
} else {
BWIBuildSettings.shared.isWellknownFederationEnabled = false
}
}
catch {
BWIBuildSettings.shared.isWellknownFederationEnabled = false
}
}
// 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 {

View File

@@ -51,14 +51,4 @@ struct WellknownFederation: Decodable {
case enable
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
enable = try? container.decode(Bool.self, forKey: .enable)
showIntroduction = try? container.decode(Bool.self, forKey: .showIntroduction)
showAnnouncement = try? container.decode(Bool.self, forKey: .showAnnouncement)
// Save federation status in userDetaults
BWIBuildSettings.shared.isWellknownFederationEnabled = enable ?? false
}
}