From 0f45dc100df0f92e60dc94523bbbb318a11b5900 Mon Sep 17 00:00:00 2001 From: Sam Steele Date: Fri, 11 Dec 2020 08:55:29 -0500 Subject: [PATCH] Add a send feedback button to the login/signup failure dialogs --- IRCCloud/Classes/LoginSplashViewController.h | 3 +- IRCCloud/Classes/LoginSplashViewController.m | 14 ++++ IRCCloud/Classes/MainViewController.m | 58 +---------------- IRCCloud/Classes/NetworkConnection.h | 1 + IRCCloud/Classes/NetworkConnection.m | 67 ++++++++++++++++++++ 5 files changed, 85 insertions(+), 58 deletions(-) diff --git a/IRCCloud/Classes/LoginSplashViewController.h b/IRCCloud/Classes/LoginSplashViewController.h index ada584f94..c34a10bf7 100644 --- a/IRCCloud/Classes/LoginSplashViewController.h +++ b/IRCCloud/Classes/LoginSplashViewController.h @@ -16,8 +16,9 @@ #import +#import -@interface LoginSplashViewController : UIViewController { +@interface LoginSplashViewController : UIViewController { IBOutlet UIImageView *logo; IBOutlet UILabel *IRC; IBOutlet UILabel *Cloud; diff --git a/IRCCloud/Classes/LoginSplashViewController.m b/IRCCloud/Classes/LoginSplashViewController.m index 8da737a2e..4058142fb 100644 --- a/IRCCloud/Classes/LoginSplashViewController.m +++ b/IRCCloud/Classes/LoginSplashViewController.m @@ -729,6 +729,9 @@ -(IBAction)loginButtonPressed:(id)sender { [UIView commitAnimations]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Communication Error" message:@"Unable to fetch configuration. Please try again shortly." preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleCancel handler:nil]]; + [alert addAction:[UIAlertAction actionWithTitle:@"Send Feedback" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [[NetworkConnection sharedInstance] sendFeedbackReport:self]; + }]]; [self presentViewController:alert animated:YES completion:nil]; }); return; @@ -785,6 +788,7 @@ -(IBAction)loginButtonPressed:(id)sender { self->forgotPasswordSignup.alpha = 0; [((AppDelegate *)([UIApplication sharedApplication].delegate)) showMainView:YES]; } else { + CLS_LOG(@"Failure: %@", result); [UIView beginAnimations:nil context:nil]; self->loginView.alpha = 1; self->loadingView.alpha = 0; @@ -813,6 +817,9 @@ -(IBAction)loginButtonPressed:(id)sender { message = @"Your IP address has been blacklisted."; UIAlertController *alert = [UIAlertController alertControllerWithTitle:self->name.alpha?@"Sign Up Failed":@"Login Failed" message:message preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleCancel handler:nil]]; + [alert addAction:[UIAlertAction actionWithTitle:@"Send Feedback" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [[NetworkConnection sharedInstance] sendFeedbackReport:self]; + }]]; [self presentViewController:alert animated:YES completion:nil]; #ifndef ENTERPRISE if(nameAlpha) { @@ -851,6 +858,7 @@ -(IBAction)loginButtonPressed:(id)sender { else [[NetworkConnection sharedInstance] login:user password:pass token:[result objectForKey:@"token"] handler:handler]; } else { + CLS_LOG(@"Failure: %@", result); [UIView beginAnimations:nil context:nil]; self->loginView.alpha = 1; self->loadingView.alpha = 0; @@ -858,6 +866,9 @@ -(IBAction)loginButtonPressed:(id)sender { NSString *message = @"Unable to communicate with the IRCCloud servers. Please try again shortly."; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Login Failed" message:message preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleCancel handler:nil]]; + [alert addAction:[UIAlertAction actionWithTitle:@"Send Feedback" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [[NetworkConnection sharedInstance] sendFeedbackReport:self]; + }]]; [self presentViewController:alert animated:YES completion:nil]; } }]; @@ -887,4 +898,7 @@ -(SupportedOrientationsReturnType)supportedInterfaceOrientations { return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)?UIInterfaceOrientationMaskPortrait:UIInterfaceOrientationMaskAll; } +-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { + [self dismissViewControllerAnimated:YES completion:nil]; +} @end diff --git a/IRCCloud/Classes/MainViewController.m b/IRCCloud/Classes/MainViewController.m index c25d1bb72..7867937d9 100644 --- a/IRCCloud/Classes/MainViewController.m +++ b/IRCCloud/Classes/MainViewController.m @@ -4976,63 +4976,7 @@ -(void)actionSheetActionClicked:(NSString *)action { [[NetworkConnection sharedInstance] whois:self->_buffer.name server:ircserver.length?ircserver:nil cid:self->_buffer.cid handler:nil]; } } else if([action isEqualToString:@"Send Feedback"]) { - CLS_LOG(@"Feedback Requested"); - NSString *version = [NSString stringWithFormat:@"%@ (%@)",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]; - NSMutableString *report = [[NSMutableString alloc] initWithFormat: -@"Briefly describe the issue below:\n\ -\n\ -\n\ -\n\ -==========\n\ -UID: %@\n\ -App Version: %@\n\ -OS Version: %@\n\ -Device type: %@\n\ -Network type: %@\n", - [[NetworkConnection sharedInstance].userInfo objectForKey:@"id"],version,[UIDevice currentDevice].systemVersion,[UIDevice currentDevice].model,[NetworkConnection sharedInstance].isWifi ? @"Wi-Fi" : @"Mobile"]; - [report appendString:@"==========\nPrefs:\n"]; - [report appendFormat:@"%@\n", [[NetworkConnection sharedInstance] prefs]]; - [report appendString:@"==========\nNSUserDefaults:\n"]; - NSMutableDictionary *d = [NSUserDefaults standardUserDefaults].dictionaryRepresentation.mutableCopy; - [d removeObjectForKey:@"logs_cache"]; - [d removeObjectForKey:@"AppleITunesStoreItemKinds"]; - [report appendFormat:@"%@\n", d]; - -#ifdef ENTERPRISE - NSURL *sharedcontainer = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.irccloud.enterprise.share"]; -#else - NSURL *sharedcontainer = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.irccloud.share"]; -#endif - if(sharedcontainer) { - fflush(stderr); - NSURL *logfile = [[[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] objectAtIndex:0] URLByAppendingPathComponent:@"log.txt"]; - - [report appendString:@"==========\nConsole log:\n"]; - [report appendFormat:@"%@\n", [NSString stringWithContentsOfURL:logfile encoding:NSUTF8StringEncoding error:nil]]; - } - - if(report.length) { - MFMailComposeViewController *mfmc = [MFMailComposeViewController canSendMail] ? [[MFMailComposeViewController alloc] init] : nil; - if(mfmc) { - mfmc.mailComposeDelegate = self; - [mfmc setToRecipients:@[@"team@irccloud.com"]]; - [mfmc setSubject:@"IRCCloud for iOS"]; - [mfmc setMessageBody:report isHTML:NO]; - if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && ![[UIDevice currentDevice] isBigPhone]) - mfmc.modalPresentationStyle = UIModalPresentationFormSheet; - else - mfmc.modalPresentationStyle = UIModalPresentationCurrentContext; - [self presentViewController:mfmc animated:YES completion:nil]; - } else { - UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Email Unavailable" message:@"Email is not configured on this device. Please copy the report to the clipboard and send it to team@irccloud.com." preferredStyle:UIAlertControllerStyleAlert]; - [alert addAction:[UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleCancel handler:nil]]; - [alert addAction:[UIAlertAction actionWithTitle:@"Copy to Clipboard" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - UIPasteboard *pb = [UIPasteboard generalPasteboard]; - [pb setValue:report forPasteboardType:(NSString *)kUTTypeUTF8PlainText]; - }]]; - [self presentViewController:alert animated:YES completion:nil]; - } - } + [[NetworkConnection sharedInstance] sendFeedbackReport:self]; } if(!_selectedUser || !_selectedUser.nick || _selectedUser.nick.length < 1) diff --git a/IRCCloud/Classes/NetworkConnection.h b/IRCCloud/Classes/NetworkConnection.h index ec94f02ed..2766a5e98 100644 --- a/IRCCloud/Classes/NetworkConnection.h +++ b/IRCCloud/Classes/NetworkConnection.h @@ -208,6 +208,7 @@ typedef void (^IRCCloudAPIResultHandler)(IRCCloudJSONObject *result); -(void)requestArchives:(int)cid; -(void)setLastSelectedBID:(int)bid; -(void)parse:(NSDictionary *)object backlog:(BOOL)backlog; +-(void)sendFeedbackReport:(UIViewController *)delegate; //WebSocket -(int)say:(NSString *)message to:(NSString *)to cid:(int)cid handler:(IRCCloudAPIResultHandler)handler; diff --git a/IRCCloud/Classes/NetworkConnection.m b/IRCCloud/Classes/NetworkConnection.m index d5686866b..d4662f7d6 100644 --- a/IRCCloud/Classes/NetworkConnection.m +++ b/IRCCloud/Classes/NetworkConnection.m @@ -15,12 +15,15 @@ // limitations under the License. #import +#import +#import #import "NetworkConnection.h" #import "HandshakeHeader.h" #import "IRCCloudJSONObject.h" #import "UIColor+IRCCloud.h" #import "ImageCache.h" #import "TrustKit.h" +#import "UIDevice+UIDevice_iPhone6Hax.h" @import Firebase; @import FirebasePerformance; @@ -1383,6 +1386,7 @@ -(void)_get:(NSURL *)url handler:(IRCCloudAPIResultHandler)resultHandler { } -(void)requestConfigurationWithHandler:(IRCCloudAPIResultHandler)handler { + CLS_LOG(@"Requesting configuration"); [self _get:[NSURL URLWithString:[NSString stringWithFormat:@"https://%@/config", IRCCLOUD_HOST]] handler:^(IRCCloudJSONObject *object) { if(object) { self->_config = object.dictionary; @@ -1418,6 +1422,8 @@ -(void)_configLoaded { [[NSUserDefaults standardUserDefaults] setObject:IRCCLOUD_HOST forKey:@"host"]; [[NSUserDefaults standardUserDefaults] synchronize]; } + + CLS_LOG(@"API Host: %@", IRCCLOUD_HOST); } -(void)propertiesForFile:(NSString *)fileID handler:(IRCCloudAPIResultHandler)handler { @@ -2680,4 +2686,65 @@ -(FIRHTTPMetric *)httpMetric { -(void)setHttpMetric:(FIRHTTPMetric *)metric { self->_httpMetric = metric; } + +-(void)sendFeedbackReport:(UIViewController *)delegate { + CLS_LOG(@"Feedback Requested"); + NSString *version = [NSString stringWithFormat:@"%@ (%@)",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]; + NSMutableString *report = [[NSMutableString alloc] initWithFormat: +@"Briefly describe the issue below:\n\ +\n\ +\n\ +\n\ +==========\n\ +UID: %@\n\ +App Version: %@\n\ +OS Version: %@\n\ +Device type: %@\n\ +Network type: %@\n", + [[NetworkConnection sharedInstance].userInfo objectForKey:@"id"],version,[UIDevice currentDevice].systemVersion,[UIDevice currentDevice].model,[NetworkConnection sharedInstance].isWifi ? @"Wi-Fi" : @"Mobile"]; + [report appendString:@"==========\nPrefs:\n"]; + [report appendFormat:@"%@\n", [[NetworkConnection sharedInstance] prefs]]; + [report appendString:@"==========\nNSUserDefaults:\n"]; + NSMutableDictionary *d = [NSUserDefaults standardUserDefaults].dictionaryRepresentation.mutableCopy; + [d removeObjectForKey:@"logs_cache"]; + [d removeObjectForKey:@"AppleITunesStoreItemKinds"]; + [report appendFormat:@"%@\n", d]; + +#ifdef ENTERPRISE + NSURL *sharedcontainer = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.irccloud.enterprise.share"]; +#else + NSURL *sharedcontainer = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.irccloud.share"]; +#endif + if(sharedcontainer) { + fflush(stderr); + NSURL *logfile = [[[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] objectAtIndex:0] URLByAppendingPathComponent:@"log.txt"]; + + [report appendString:@"==========\nConsole log:\n"]; + [report appendFormat:@"%@\n", [NSString stringWithContentsOfURL:logfile encoding:NSUTF8StringEncoding error:nil]]; + } + + if(report.length) { + MFMailComposeViewController *mfmc = [MFMailComposeViewController canSendMail] ? [[MFMailComposeViewController alloc] init] : nil; + if(mfmc) { + mfmc.mailComposeDelegate = (UIViewController *)delegate; + [mfmc setToRecipients:@[@"team@irccloud.com"]]; + [mfmc setSubject:@"IRCCloud for iOS"]; + [mfmc setMessageBody:report isHTML:NO]; + if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && ![[UIDevice currentDevice] isBigPhone]) + mfmc.modalPresentationStyle = UIModalPresentationFormSheet; + else + mfmc.modalPresentationStyle = UIModalPresentationCurrentContext; + [delegate presentViewController:mfmc animated:YES completion:nil]; + } else { + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Email Unavailable" message:@"Email is not configured on this device. Please copy the report to the clipboard and send it to team@irccloud.com." preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleCancel handler:nil]]; + [alert addAction:[UIAlertAction actionWithTitle:@"Copy to Clipboard" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + UIPasteboard *pb = [UIPasteboard generalPasteboard]; + [pb setValue:report forPasteboardType:(NSString *)kUTTypeUTF8PlainText]; + }]]; + [delegate presentViewController:alert animated:YES completion:nil]; + } + } + +} @end