mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 15:09:31 +02:00
MESSENGER-5556 refactoring
This commit is contained in:
@@ -737,7 +737,7 @@ class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest(completion: { success in
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest(completion: { success, _, _, _ in
|
||||
self.createLeftButtonItem(for: self.allChatsViewController)
|
||||
|
||||
if ServerDowntimeDefaultService.shared.isBlocking() && ServerDowntimeDefaultService.shared.isDowntimeNow() && !ServerDowntimeDefaultService.shared.isManuallyIgnored() {
|
||||
|
||||
@@ -285,7 +285,7 @@ struct AuthenticationServerSelectionScreen: View {
|
||||
self.showAlertIfNeeded()
|
||||
}
|
||||
} else {
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest(localUrlString:viewModel.homeserverAddress) { success in
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest(localUrlString:viewModel.homeserverAddress) { success, _, _, _ in
|
||||
DispatchQueue.main.async {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
if success {
|
||||
|
||||
@@ -108,9 +108,9 @@ struct MaintenanceView: View {
|
||||
private func fetchDataFromServer() async {
|
||||
isFetching = true
|
||||
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest(localUrlString: nil) { data, response, error in
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest(localUrlString: nil) { _, response, data, error in
|
||||
isFetching = false
|
||||
guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {
|
||||
guard let response = response, response.statusCode == 200 else {
|
||||
if let error = error {
|
||||
jsonStringFromServer = error.localizedDescription
|
||||
} else {
|
||||
|
||||
@@ -275,30 +275,7 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
|
||||
try copyServerDowntimesToUserDefaults(downtimes: downtimes)
|
||||
}
|
||||
|
||||
func fetchDowntimesWithDirectRequest(localUrlString: String? = nil, completion: @escaping (Bool) -> Void) {
|
||||
fetchDowntimesWithDirectRequest(localUrlString: localUrlString) { data, response, _ in
|
||||
|
||||
guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {
|
||||
completion(false)
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
if let data = data, let fetchResult = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
|
||||
try self.copyFetchResultToUserDefaults(fetchResult: fetchResult)
|
||||
completion(true)
|
||||
} else {
|
||||
completion(false)
|
||||
}
|
||||
} catch {
|
||||
print(error.localizedDescription)
|
||||
completion(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func fetchDowntimesWithDirectRequest(localUrlString: String? = nil, requestCompletion: @escaping (Data?, URLResponse?, Error?) -> Void) {
|
||||
func fetchDowntimesWithDirectRequest(localUrlString: String? = nil, completion: @escaping (Bool,HTTPURLResponse?,Data?,Error?) -> Void) {
|
||||
var urlString = AppConfigService.shared.serverUrl()
|
||||
|
||||
if let localUrlString = localUrlString {
|
||||
@@ -306,7 +283,7 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
|
||||
}
|
||||
|
||||
guard let url = URL(string: urlString + maintenanceURL) else {
|
||||
requestCompletion(nil, nil, nil)
|
||||
completion(false, nil, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -316,7 +293,20 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
|
||||
let session : URLSession = URLSession(configuration: config)
|
||||
|
||||
let task = session.dataTask(with: url) { data, response, error in
|
||||
requestCompletion(data, response, error)
|
||||
guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {
|
||||
completion(false, nil, data, error)
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
if let data = data, let fetchResult = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
|
||||
try self.copyFetchResultToUserDefaults(fetchResult: fetchResult)
|
||||
}
|
||||
} catch {
|
||||
print(error.localizedDescription)
|
||||
}
|
||||
|
||||
completion(true, response, data, error)
|
||||
}
|
||||
task.resume()
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ struct OnboardingBwiSplashScreen: View {
|
||||
self.showAlertIfNeeded()
|
||||
}
|
||||
} else {
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest { success in
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest { success, _, _, _ in
|
||||
DispatchQueue.main.async {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
if success {
|
||||
|
||||
@@ -96,7 +96,7 @@ fileprivate struct Page: View {
|
||||
self.showAlertIfNeeded()
|
||||
}
|
||||
} else {
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest { success in
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest { success, _, _, _ in
|
||||
DispatchQueue.main.async {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
if success {
|
||||
|
||||
Reference in New Issue
Block a user