From 12e9ad2770b3ad38a388c133d3f14409db611d60 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Mon, 16 Oct 2023 19:19:22 +0200 Subject: [PATCH] Add custom message and link to FAQ inside Tchap app --- Riot/Assets/fr.lproj/Vector.strings | 4 +- Riot/Modules/Room/RoomViewController.m | 11 ++++ Riot/Utils/EventFormatter.h | 5 ++ Riot/Utils/EventFormatter.m | 58 +++++++++++++------ .../Localizations/fr.lproj/Tchap.strings | 6 +- .../WebSheet/WebSheetViewController.swift | 7 +-- Tools/SwiftGen/swiftgen-config.yml | 5 +- 7 files changed, 68 insertions(+), 28 deletions(-) diff --git a/Riot/Assets/fr.lproj/Vector.strings b/Riot/Assets/fr.lproj/Vector.strings index bf79e622e0..adcd8567db 100644 --- a/Riot/Assets/fr.lproj/Vector.strings +++ b/Riot/Assets/fr.lproj/Vector.strings @@ -2792,5 +2792,5 @@ // Contacts "local_contacts_access_discovery_warning" = "Afin d’afficher qui parmi vos contacts utilise déjà Tchap, nous pouvons exploiter les adresses e-mails de votre carnet d'adresse. Ces données ne seront pas mémorisées. Pour plus d'informations, veuillez consulter les Termes et Conditions disponibles dans les paramètres de l'application."; // Events formatter -"notice_crypto_unable_to_decrypt" = "** Echec de déchiffrement : %@ **"; -"notice_crypto_error_unknown_inbound_session_id" = "Veuillez ouvrir Tchap sur vos autres appareils afin d'autoriser le partage de clés."; +"notice_crypto_unable_to_decrypt" = "Message verrouillé."; // Tchap +"notice_crypto_error_unknown_inbound_session_id" = "Ouvrez Tchap sur un autre appareil pour récupérer vos messages."; // Tchap diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 7e7acba0c5..44912b142e 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -4703,6 +4703,17 @@ - (BOOL)dataSource:(MXKDataSource *)dataSource shouldDoAction:(NSString *)action } shouldDoAction = NO; } + else if ([absoluteURLString hasPrefix:EventFormatterFaqLinkAction]) // Tchap: custom Link to FAQ in case of crypto error on room's messages + { + NSArray *arguments = [absoluteURLString componentsSeparatedByString:EventFormatterLinkActionSeparator]; + if (arguments.count > 1) + { + NSString *faqUrl = [[arguments subarrayWithRange:NSMakeRange(1, arguments.count-1)] componentsJoinedByString:@"/"]; + WebSheetViewController *webCtrl = [[WebSheetViewController alloc] initWithTargetUrl:[NSURL URLWithString:faqUrl]]; + [self presentViewController:webCtrl animated:YES completion:nil]; + } + shouldDoAction = NO; + } else if (url && urlItemInteractionValue) { // Fallback case for external links diff --git a/Riot/Utils/EventFormatter.h b/Riot/Utils/EventFormatter.h index 3d7a39b1e3..185ecc0f4b 100644 --- a/Riot/Utils/EventFormatter.h +++ b/Riot/Utils/EventFormatter.h @@ -31,6 +31,11 @@ FOUNDATION_EXPORT NSString *const EventFormatterLinkActionSeparator; */ FOUNDATION_EXPORT NSString *const EventFormatterEditedEventLinkAction; +/** + Link string used in attributed strings to mark a Tchap FAQ article event action. + */ +FOUNDATION_EXPORT NSString *const EventFormatterFaqLinkAction; // Tchap + /** `EventFormatter` class inherits from `MXKEventFormatter` to define Vector formatting */ diff --git a/Riot/Utils/EventFormatter.m b/Riot/Utils/EventFormatter.m index 8ef98d0a57..7bdcad6df1 100644 --- a/Riot/Utils/EventFormatter.m +++ b/Riot/Utils/EventFormatter.m @@ -32,6 +32,7 @@ NSString *const EventFormatterOnReRequestKeysLinkAction = @"EventFormatterOnReRequestKeysLinkAction"; NSString *const EventFormatterLinkActionSeparator = @"/"; NSString *const EventFormatterEditedEventLinkAction = @"EventFormatterEditedEventLinkAction"; +NSString *const EventFormatterFaqLinkAction = @"EventFormatterFaqLinkAction"; // Tchap NSString *const FunctionalMembersStateEventType = @"io.element.functional_members"; NSString *const FunctionalMembersServiceMembersKey = @"service_members"; @@ -340,31 +341,50 @@ - (NSAttributedString *)unsafeAttributedStringFromEvent:(MXEvent *)event if (event.decryptionError.code == MXDecryptingErrorUnknownInboundSessionIdCode) { + // Tchap: remove english message coming from server + // and add to custom message with a clickable part with a link to FAQ. + // Append to the displayed error an attibuted string with a tappable link // so that the user can try to fix the UTD - NSMutableAttributedString *attributedStringWithRerequestMessage = [attributedString mutableCopy]; - [attributedStringWithRerequestMessage appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]]; +// NSMutableAttributedString *attributedStringWithRerequestMessage = [attributedString mutableCopy]; +// [attributedStringWithRerequestMessage appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]]; +// +// NSString *linkActionString = [NSString stringWithFormat:@"%@%@%@", EventFormatterOnReRequestKeysLinkAction, +// EventFormatterLinkActionSeparator, +// event.eventId]; +// +// [attributedStringWithRerequestMessage appendAttributedString: +// [[NSAttributedString alloc] initWithString:[VectorL10n eventFormatterRerequestKeysPart1Link] +// attributes:@{ +// NSLinkAttributeName: linkActionString, +// NSForegroundColorAttributeName: self.sendingTextColor, +// NSFontAttributeName: self.encryptedMessagesTextFont, +// NSUnderlineStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle] +// }]]; +// +// [attributedStringWithRerequestMessage appendAttributedString: +// [[NSAttributedString alloc] initWithString:[VectorL10n eventFormatterRerequestKeysPart2] +// attributes:@{ +// NSForegroundColorAttributeName: self.sendingTextColor, +// NSFontAttributeName: self.encryptedMessagesTextFont +// }]]; - NSString *linkActionString = [NSString stringWithFormat:@"%@%@%@", EventFormatterOnReRequestKeysLinkAction, + NSMutableAttributedString *attributedStringWithRerequestMessage = [attributedString mutableCopy]; + + [attributedStringWithRerequestMessage appendString:[NSString stringWithFormat:@" %@\n", VectorL10n.noticeCryptoErrorUnknownInboundSessionId]]; + NSString *linkActionString = [NSString stringWithFormat:@"%@%@%@", EventFormatterFaqLinkAction, EventFormatterLinkActionSeparator, - event.eventId]; - - [attributedStringWithRerequestMessage appendAttributedString: - [[NSAttributedString alloc] initWithString:[VectorL10n eventFormatterRerequestKeysPart1Link] - attributes:@{ - NSLinkAttributeName: linkActionString, - NSForegroundColorAttributeName: self.sendingTextColor, - NSFontAttributeName: self.encryptedMessagesTextFont, - NSUnderlineStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle] - }]]; - + @"https://aide.tchap.beta.gouv.fr/fr/article/dechiffrement-impossible-de-mes-messages-comment-y-remedier-iphone-xotgv1"]; + [attributedStringWithRerequestMessage appendAttributedString: - [[NSAttributedString alloc] initWithString:[VectorL10n eventFormatterRerequestKeysPart2] + [[NSAttributedString alloc] initWithString: [TchapL10n roomDecryptionErrorFaqLinkMessage] attributes:@{ - NSForegroundColorAttributeName: self.sendingTextColor, - NSFontAttributeName: self.encryptedMessagesTextFont - }]]; - + NSLinkAttributeName: linkActionString, + NSForegroundColorAttributeName: self.sendingTextColor, + NSFontAttributeName: self.encryptedMessagesTextFont, + NSUnderlineStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle] + }]]; + attributedString = attributedStringWithRerequestMessage; } } diff --git a/Tchap/Assets/Localizations/fr.lproj/Tchap.strings b/Tchap/Assets/Localizations/fr.lproj/Tchap.strings index 7a68d8800e..2e57531f31 100644 --- a/Tchap/Assets/Localizations/fr.lproj/Tchap.strings +++ b/Tchap/Assets/Localizations/fr.lproj/Tchap.strings @@ -302,6 +302,10 @@ "side_menu_action_invite_friends" = "Inviter à rejoindre Tchap"; //////////////////////////////////////////////////////////////////////////////// -// MARK: Device verification +// MARK: Secret Setup Recovery Key "secrets_setup_recovery_key_export_action_done" = "Clé copiée"; "secrets_setup_recovery_key_warning" = "Attention : c'est la seule fois que votre code est affiché !"; // Tchap + +//////////////////////////////////////////////////////////////////////////////// +// MARK: Room Decryption error +"room_decryption_error_faq_link_message" = "Sinon, consulter cet article de FAQ."; diff --git a/Tchap/Modules/WebSheet/WebSheetViewController.swift b/Tchap/Modules/WebSheet/WebSheetViewController.swift index c48d0ab44f..347b522c10 100644 --- a/Tchap/Modules/WebSheet/WebSheetViewController.swift +++ b/Tchap/Modules/WebSheet/WebSheetViewController.swift @@ -16,7 +16,7 @@ import Foundation -class WebSheetViewController: UIViewController, WKUIDelegate { +@objc class WebSheetViewController: UIViewController, WKUIDelegate { private lazy var webview: WKWebView = { [unowned self] in let conf = WKWebViewConfiguration() @@ -69,7 +69,7 @@ class WebSheetViewController: UIViewController, WKUIDelegate { self.closeButtonIsHidden = false } - convenience init(targetUrl: URL) { + @objc convenience init(targetUrl: URL) { self.init() // set targetUrl before configuring else viewDidLoad will be called with an empty targetUrl. self.targetUrl = targetUrl @@ -141,13 +141,12 @@ extension WebSheetViewController: WKNavigationDelegate { func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { // Decides whether to allow or cancel a navigation. -// print("webView decidePolicyFor navigationAction: " + (webView.url?.absoluteString ?? "???")) // Test if target is _blank if navigationAction.targetFrame == nil { // If target is _blank, open page in external navigator if let targetUrl = navigationAction.request.url { - UIApplication.shared.openURL(targetUrl) + UIApplication.shared.open(targetUrl, options: [:], completionHandler: nil) } decisionHandler(.cancel) } else { diff --git a/Tools/SwiftGen/swiftgen-config.yml b/Tools/SwiftGen/swiftgen-config.yml index 18ba80afd6..654a3bec14 100755 --- a/Tools/SwiftGen/swiftgen-config.yml +++ b/Tools/SwiftGen/swiftgen-config.yml @@ -33,10 +33,11 @@ ib: strings: inputs: Tchap/Assets/Localizations/fr.lproj/Tchap.strings outputs: - - templateName: flat-swift4 + templatePath: Templates/Strings/flat-swift4-vector.stencil output: Tchap/Generated/Strings.swift params: - enumName: TchapL10n + className: TchapL10n + publicAccess: true xcassets: - inputs: - Tchap/Assets/Images.xcassets