Skip to content

Commit

Permalink
Merge pull request #893 from tchapgouv/861-modifier-le-texte-quand-le…
Browse files Browse the repository at this point in the history
…s-messages-sont-verrouilles

Add custom message and link to FAQ inside Tchap app
  • Loading branch information
NicolasBuquet authored Oct 18, 2023
2 parents 405408b + 12e9ad2 commit cea743b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Riot/Assets/fr.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2796,5 +2796,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
11 changes: 11 additions & 0 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4714,6 +4714,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<NSString*> *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
Expand Down
5 changes: 5 additions & 0 deletions Riot/Utils/EventFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
58 changes: 39 additions & 19 deletions Riot/Utils/EventFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
}
Expand Down
6 changes: 5 additions & 1 deletion Tchap/Assets/Localizations/fr.lproj/Tchap.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
7 changes: 3 additions & 4 deletions Tchap/Modules/WebSheet/WebSheetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cea743b

Please sign in to comment.