From ace49da458261a43317b756ed7e1c7ab138e16e5 Mon Sep 17 00:00:00 2001 From: JanNiklas Grabowski Date: Wed, 26 Jul 2023 13:07:22 +0000 Subject: [PATCH] MESSENGER-4295 add additional information for maintenance --- Config/BWIBuildSettings.swift | 1 + .../BuM-Beta/BWIBuildSettings+BuM-Beta.swift | 1 + Riot/Assets/de.lproj/Bwi.strings | 3 +- Riot/Assets/en.lproj/Bwi.strings | 3 +- .../Modules/Settings/SettingsViewController.m | 11 +- .../ServerDownTimeService.swift | 7 +- .../ServerDowntimeDefaultService.swift | 127 +++++++++++------- bwi/ServerMaintenance/exampleDowntime.json | 21 +-- .../View/OnboardingBwiSplashScreen.swift | 32 +++-- 9 files changed, 125 insertions(+), 81 deletions(-) diff --git a/Config/BWIBuildSettings.swift b/Config/BWIBuildSettings.swift index da1e81879..ccc85a732 100644 --- a/Config/BWIBuildSettings.swift +++ b/Config/BWIBuildSettings.swift @@ -615,6 +615,7 @@ class BWIBuildSettings: NSObject { // MARK: - Maintenance var enableMaintenanceInfoOnWelcomeScreen = false + var showMaintenanceInfoMessageType = false // MARK: User Search var sortUserSearchResultsAlphabetically = true diff --git a/Config/BuM-Beta/BWIBuildSettings+BuM-Beta.swift b/Config/BuM-Beta/BWIBuildSettings+BuM-Beta.swift index 89b8b2835..933282ecc 100644 --- a/Config/BuM-Beta/BWIBuildSettings+BuM-Beta.swift +++ b/Config/BuM-Beta/BWIBuildSettings+BuM-Beta.swift @@ -37,6 +37,7 @@ extension BWIBuildSettings { enableLabFeatureVoiceBroadcasts = true enableNewSessionManagerByDefault = true enableLabFeatureWYSIWYG = true + showMaintenanceInfoMessageType = true } } diff --git a/Riot/Assets/de.lproj/Bwi.strings b/Riot/Assets/de.lproj/Bwi.strings index 7feabc31e..ab99c5aa4 100644 --- a/Riot/Assets/de.lproj/Bwi.strings +++ b/Riot/Assets/de.lproj/Bwi.strings @@ -30,7 +30,8 @@ "downtime_title" = "⚠ Server nicht erreichbar"; "downtime_default_message" = "Wir führen gerade Wartungsarbeiten durch. Bitte versuche es später erneut."; -"downtime_alert_dismiss_button" = "Zurück"; +"downtime_alert_dismiss_button" = "Ok"; +"blocking_downtime_alert_dismiss_button" = "Zurück"; "settings_downtime_message_same_day" = "Der %@ steht am %@, %@ von %@ bis %@ Uhr (UTC%@) nicht zur Verfügung. Nachrichten können in dieser Zeit nicht verschickt oder empfangen werden."; "settings_downtime_message_different_days" = "Der %@ steht von %@, %@ Uhr (UTC%@) bis %@, %@ Uhr (UTC%@) nicht zur Verfügung. Nachrichten können in dieser Zeit nicht verschickt oder empfangen werden."; "settings_copyright" = "Copyright"; diff --git a/Riot/Assets/en.lproj/Bwi.strings b/Riot/Assets/en.lproj/Bwi.strings index f1fef0bd9..04f634ee0 100644 --- a/Riot/Assets/en.lproj/Bwi.strings +++ b/Riot/Assets/en.lproj/Bwi.strings @@ -30,7 +30,8 @@ "downtime_title" = "⚠ Server not available"; "downtime_default_message" = "We are working on our maintenance. Please try again later."; -"downtime_alert_dismiss_button" = "Back"; +"downtime_alert_dismiss_button" = "Ok"; +"blocking_downtime_alert_dismiss_button" = "Back"; "settings_downtime_message_same_day" = "The %@ is not available on %@, %@ between %@ and %@ (UTC%@). Messages may not be sent or received during that time."; "settings_downtime_message_different_days" = "The %@ is not available from %@, %@ (UTC%@) to %@, %@ (UTC%@). Messages may not be sent or received during that time."; "settings_copyright" = "Copyright"; diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 751ab69c0..1441c3c12 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -3026,12 +3026,7 @@ ChangePasswordCoordinatorBridgePresenterDelegate> downtimeCell.textLabel.text = [self bwiDowntimeCellText]; downtimeCell.textLabel.textColor = [self bwiDowntimeTextColor]; downtimeCell.textLabel.lineBreakMode = NSLineBreakByWordWrapping; - // bwi: with descriptions coming soon we need to do this dynamically - if ([[[ServerDowntimeDefaultService alloc] init] isSameDay]) { - downtimeCell.textLabel.numberOfLines = 6; - } else { - downtimeCell.textLabel.numberOfLines = 7; - } + downtimeCell.textLabel.numberOfLines = 0; cell = downtimeCell; @@ -3048,7 +3043,7 @@ ChangePasswordCoordinatorBridgePresenterDelegate> downtimeCell.textLabel.text = [BWIL10n bwiOutdatedSettingsMessage:AppInfo.current.displayName]; downtimeCell.textLabel.textColor = [UIColor blackColor]; downtimeCell.textLabel.lineBreakMode = NSLineBreakByWordWrapping; - downtimeCell.textLabel.numberOfLines = 5; + downtimeCell.textLabel.numberOfLines = 0; cell = downtimeCell; } @@ -5255,7 +5250,7 @@ ChangePasswordCoordinatorBridgePresenterDelegate> #pragma mark - bwi Messenger Additions - (NSString*) bwiDowntimeCellText { - NSString *downtimeText = [NSString stringWithFormat:@"\n%@\n\n", [[[ServerDowntimeDefaultService alloc] init] downtimeText]]; + NSString *downtimeText = [NSString stringWithFormat:@"\n%@\n", [[[ServerDowntimeDefaultService alloc] init] downtimeText]]; return downtimeText; } diff --git a/bwi/ServerMaintenance/ServerDownTimeService.swift b/bwi/ServerMaintenance/ServerDownTimeService.swift index 57118a62c..b072f914e 100644 --- a/bwi/ServerMaintenance/ServerDownTimeService.swift +++ b/bwi/ServerMaintenance/ServerDownTimeService.swift @@ -17,12 +17,17 @@ import Foundation -enum ServerDowntimeType { +enum ServerDowntimeStatus { case none case warning case ongoing } +enum ServerDowntimeType: String { + case adhocMessage = "ADHOC_MESSAGE" + case maintenance = "MAINTENANCE" +} + protocol ServerDowntimeService { func fetchDowntimes(session: MXSession, completion: @escaping () -> Void) func isDowntimePresentable() -> Bool diff --git a/bwi/ServerMaintenance/ServerDowntimeDefaultService.swift b/bwi/ServerMaintenance/ServerDowntimeDefaultService.swift index 3c3a2f8d2..ce41bb019 100644 --- a/bwi/ServerMaintenance/ServerDowntimeDefaultService.swift +++ b/bwi/ServerMaintenance/ServerDowntimeDefaultService.swift @@ -27,7 +27,7 @@ fileprivate let exampleFile = "exampleDowntime" fileprivate let maintenanceURL = "/_matrix/cmaintenance" @objcMembers class ServerDowntimeDefaultService : NSObject { - var isCurrentDowntime: ServerDowntimeType = .none + var isCurrentDowntime: ServerDowntimeStatus = .none /// Find the next relevant downtime /// - Returns: ServerDowntime or nil, if there is no downtime in the future or the warning date is still in the future @@ -69,7 +69,7 @@ fileprivate let maintenanceURL = "/_matrix/cmaintenance" /// Check the state of the next downtime /// - Returns: ongoing, warning or none - func nextDowntimeType() -> ServerDowntimeType { + func nextDowntimeStatus() -> ServerDowntimeStatus { guard let downTime = self.nextDowntime() else { return .none } @@ -193,54 +193,62 @@ extension ServerDowntimeDefaultService : ServerDowntimeService { // MARK: - @objc func isDowntimePresentable() -> Bool { - return nextDowntimeType() != .none + return nextDowntimeStatus() != .none } @objc func downtimeText() -> String { - guard let downTime = self.nextDowntime(), let startDate = downTime.startTime.iso8601LocalDate, let endDate = downTime.endTime.iso8601LocalDate else { + guard let downTime = self.nextDowntime() else { return "" } - - let dayOfWeekFormatter = DateFormatter() - dayOfWeekFormatter.dateFormat = "EEEE" - dayOfWeekFormatter.timeZone = TimeZone.current - dayOfWeekFormatter.calendar = Calendar.current - - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "dd.MM.yyyy" - dateFormatter.timeZone = TimeZone.current - dateFormatter.calendar = Calendar.current - - let dateTimeFormatter = DateFormatter() - dateTimeFormatter.dateFormat = "dd.MM.yyyy HH:mm" - dateTimeFormatter.timeZone = TimeZone.current - dateTimeFormatter.calendar = Calendar.current - - let timeFormatter = DateFormatter() - timeFormatter.dateFormat = "HH:mm" - timeFormatter.timeZone = TimeZone.current - timeFormatter.calendar = Calendar.current - - let utcFormatter = DateFormatter() - utcFormatter.dateFormat = "ZZZZZ" - utcFormatter.timeZone = TimeZone.current - utcFormatter.calendar = Calendar.current - - if self.isSameDay() { - return BWIL10n.settingsDowntimeMessageSameDay(AppInfo.current.displayName, - dayOfWeekFormatter.string(from: startDate), - dateFormatter.string(from: startDate), - timeFormatter.string(from: startDate), - timeFormatter.string(from: endDate), - utcFormatter.string(from: startDate)) - } else { - return BWIL10n.settingsDowntimeMessageDifferentDays(AppInfo.current.displayName, + switch downtimeType() { + case .adhocMessage: + return downTime.description + case .maintenance: + guard let startDate = downTime.startTime.iso8601LocalDate, let endDate = downTime.endTime.iso8601LocalDate else { + return "" + } + + let dayOfWeekFormatter = DateFormatter() + dayOfWeekFormatter.dateFormat = "EEEE" + dayOfWeekFormatter.timeZone = TimeZone.current + dayOfWeekFormatter.calendar = Calendar.current + + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "dd.MM.yyyy" + dateFormatter.timeZone = TimeZone.current + dateFormatter.calendar = Calendar.current + + let dateTimeFormatter = DateFormatter() + dateTimeFormatter.dateFormat = "dd.MM.yyyy HH:mm" + dateTimeFormatter.timeZone = TimeZone.current + dateTimeFormatter.calendar = Calendar.current + + let timeFormatter = DateFormatter() + timeFormatter.dateFormat = "HH:mm" + timeFormatter.timeZone = TimeZone.current + timeFormatter.calendar = Calendar.current + + let utcFormatter = DateFormatter() + utcFormatter.dateFormat = "ZZZZZ" + utcFormatter.timeZone = TimeZone.current + utcFormatter.calendar = Calendar.current + + if self.isSameDay() { + return BWIL10n.settingsDowntimeMessageSameDay(AppInfo.current.displayName, dayOfWeekFormatter.string(from: startDate), - dateTimeFormatter.string(from: startDate), - utcFormatter.string(from: startDate), - dayOfWeekFormatter.string(from: endDate), - dateTimeFormatter.string(from: endDate), - utcFormatter.string(from: endDate)) + dateFormatter.string(from: startDate), + timeFormatter.string(from: startDate), + timeFormatter.string(from: endDate), + utcFormatter.string(from: startDate)).appending(BWIBuildSettings.shared.showMaintenanceInfoMessageType ? "\n\n\(downTime.description)" : "") + } else { + return BWIL10n.settingsDowntimeMessageDifferentDays(AppInfo.current.displayName, + dayOfWeekFormatter.string(from: startDate), + dateTimeFormatter.string(from: startDate), + utcFormatter.string(from: startDate), + dayOfWeekFormatter.string(from: endDate), + dateTimeFormatter.string(from: endDate), + utcFormatter.string(from: endDate)).appending(BWIBuildSettings.shared.showMaintenanceInfoMessageType ? "\n\n\(downTime.description)" : "") + } } } @@ -252,27 +260,46 @@ extension ServerDowntimeDefaultService : ServerDowntimeService { } @objc func downtimeColor() -> UIColor { - switch nextDowntimeType() { + switch nextDowntimeStatus() { case .warning: return .yellow case .ongoing: - return .red + if isBlocking() { + return .red + } else { + return .yellow + } default: return .clear } } @objc func downtimeTextColor() -> UIColor { - switch nextDowntimeType() { + switch nextDowntimeStatus() { case .warning: return .black case .ongoing: - return .white + if isBlocking() { + return .white + } else { + return .black + } default: return .clear } } + func downtimeType() -> ServerDowntimeType { + guard let downTime = self.nextDowntime() else { + return ServerDowntimeType.maintenance + } + if BWIBuildSettings.shared.showMaintenanceInfoMessageType && downTime.type.elementsEqual(ServerDowntimeType.adhocMessage.rawValue) { + return ServerDowntimeType.adhocMessage + } else { + return ServerDowntimeType.maintenance + } + } + @objc func isSameDay() -> Bool { guard let downTime = self.nextDowntime(), let startDate = downTime.startTime.iso8601LocalDate, let endDate = downTime.endTime.iso8601LocalDate else { return false @@ -290,10 +317,10 @@ extension ServerDowntimeDefaultService : ServerDowntimeService { } @objc func saveCurrentStatus() { - self.isCurrentDowntime = nextDowntimeType() + self.isCurrentDowntime = nextDowntimeStatus() } @objc func isChanged() -> Bool { - return nextDowntimeType() != self.isCurrentDowntime + return nextDowntimeStatus() != self.isCurrentDowntime } } diff --git a/bwi/ServerMaintenance/exampleDowntime.json b/bwi/ServerMaintenance/exampleDowntime.json index b8e88fa05..d1265ab84 100644 --- a/bwi/ServerMaintenance/exampleDowntime.json +++ b/bwi/ServerMaintenance/exampleDowntime.json @@ -2,18 +2,19 @@ "downtime": [ { "warning_start_time": "2023-04-01T00:00:00Z", - "start_time": "2023-04-01T22:30:00Z", - "end_time": "2023-05-01T22:30:00Z", - "type": "MAINTANANCE_STANDARD", - "description": "Dauerwartung 2022", - "blocking": true + "start_time": "2023-07-17T22:30:00Z", + "end_time": "2023-08-01T22:30:00Z", + "type": "ADHOC_MESSAGE", + "description": "Spezifischer Fehlertext.", + "blocking": false }, { - "warning_start_time": "2021-12-23T10:00:00Z", - "start_time": "2021-12-23T11:00:00Z", - "end_time": "2021-12-24T20:00:00Z", - "type": "MAINTANANCE_STANDARD", - "description": "Weihnachtwartung 2021" + "warning_start_time": "2023-04-01T00:00:00Z", + "start_time": "2023-04-01T22:30:00Z", + "end_time": "2023-05-01T22:30:00Z", + "type": "MAINTANANCE", + "description": "Dauerwartung 2022", + "blocking": false }, { "warning_start_time": "2022-03-01T15:00:00Z", diff --git a/bwi/SplashScreen/View/OnboardingBwiSplashScreen.swift b/bwi/SplashScreen/View/OnboardingBwiSplashScreen.swift index 69722ed24..2f8976beb 100644 --- a/bwi/SplashScreen/View/OnboardingBwiSplashScreen.swift +++ b/bwi/SplashScreen/View/OnboardingBwiSplashScreen.swift @@ -17,7 +17,7 @@ import SwiftUI enum OnBoardingSplashScreenAlertType { - case showServerMaintenanceAlert, showServerMaintenanceDefaultAlert, showInvalidAppVersionAlert, showDowntimeTimeAlert + case showServerMaintenanceInfoMessageAlert, showServerMaintenanceDefaultAlert, showInvalidAppVersionAlert, showDowntimeTimeAlert } @available(iOS 14.0, *) @@ -90,14 +90,22 @@ struct OnboardingBwiSplashScreen: View { case .showDowntimeTimeAlert: return Alert(title: Text(BWIL10n.downtimeTitle), message: Text(ServerDowntimeDefaultService().downtimeText() != "" ? BWIL10n.downtimeDefaultMessage + "\n\n" + ServerDowntimeDefaultService().downtimeText() : BWIL10n.downtimeDefaultMessage), - dismissButton: .destructive(Text(BWIL10n.downtimeAlertDismissButton)) { - return - }) - case .showServerMaintenanceAlert: - return Alert(title: Text(BWIL10n.downtimeTitle), + dismissButton: .destructive(Text(service.isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) { + if service.isBlocking() { + return + } else { + viewModel.send(viewAction: .login) + } + }) + case .showServerMaintenanceInfoMessageAlert: + return Alert(title: Text(""), message: Text(ServerDowntimeDefaultService().downtimeText()), - dismissButton: .destructive(Text(BWIL10n.downtimeAlertDismissButton)) { - viewModel.send(viewAction: .login) + dismissButton: .destructive(Text(service.isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) { + if service.isBlocking() { + return + } else { + viewModel.send(viewAction: .login) + } }) case .showServerMaintenanceDefaultAlert: return Alert(title: Text(BWIL10n.downtimeTitle), @@ -138,13 +146,17 @@ struct OnboardingBwiSplashScreen: View { private func showAlertIfNeeded() { - switch service.nextDowntimeType() { + switch service.nextDowntimeStatus() { case .none: viewModel.send(viewAction: .login) break case .ongoing: + if service.downtimeType() == .adhocMessage { + activeAlert = .showServerMaintenanceInfoMessageAlert + } else { + activeAlert = .showDowntimeTimeAlert + } showAlert = true - activeAlert = .showDowntimeTimeAlert break case .warning: // only show active downtimes