Skip to content

Commit

Permalink
Add a send feedback button to the login/signup failure dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed Dec 11, 2020
1 parent f780e73 commit 0f45dc1
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 58 deletions.
3 changes: 2 additions & 1 deletion IRCCloud/Classes/LoginSplashViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@


#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>

@interface LoginSplashViewController : UIViewController<UITextFieldDelegate, UIGestureRecognizerDelegate> {
@interface LoginSplashViewController : UIViewController<UITextFieldDelegate, UIGestureRecognizerDelegate, MFMailComposeViewControllerDelegate> {
IBOutlet UIImageView *logo;
IBOutlet UILabel *IRC;
IBOutlet UILabel *Cloud;
Expand Down
14 changes: 14 additions & 0 deletions IRCCloud/Classes/LoginSplashViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -851,13 +858,17 @@ -(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;
[UIView commitAnimations];
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];
}
}];
Expand Down Expand Up @@ -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
58 changes: 1 addition & 57 deletions IRCCloud/Classes/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:@[@"[email protected]"]];
[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 [email protected]." 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)
Expand Down
1 change: 1 addition & 0 deletions IRCCloud/Classes/NetworkConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
67 changes: 67 additions & 0 deletions IRCCloud/Classes/NetworkConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
// limitations under the License.

#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <MobileCoreServices/UTCoreTypes.h>
#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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<MFMailComposeViewControllerDelegate> *)delegate;
[mfmc setToRecipients:@[@"[email protected]"]];
[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 [email protected]." 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

0 comments on commit 0f45dc1

Please sign in to comment.