diff options
author | Vitaly Takmazov | 2019-03-22 00:33:30 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-03-22 00:33:30 +0300 |
commit | 5f4a09ec689cb04ce71b4eb7425936f04a70f6f4 (patch) | |
tree | 9653dc543bd8f47dbfa853cd36ace63206efc983 /Juick | |
parent | 6e49fc5c4273e7597925c133c3a6985b6ad85ecc (diff) |
Fix sign in
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/APIClient.m | 5 | ||||
-rw-r--r-- | Juick/Main.storyboard | 6 | ||||
-rw-r--r-- | Juick/ViewControllers/DialogsViewController.m | 17 | ||||
-rw-r--r-- | Juick/ViewControllers/FeedViewController.m | 64 | ||||
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.h | 1 | ||||
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.m | 6 |
6 files changed, 52 insertions, 47 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m index 869e944..e2ef67d 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -67,7 +67,10 @@ } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"REST Error: %@", error); [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - callback(nil, error); + NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode; + if (statusCode == 401) { + callback(nil, [NSError errorWithDomain:@"JuickErrorDomain" code:401 userInfo:nil]); + } }]; }]; }]; diff --git a/Juick/Main.storyboard b/Juick/Main.storyboard index c2c1717..b65af91 100644 --- a/Juick/Main.storyboard +++ b/Juick/Main.storyboard @@ -89,7 +89,7 @@ <navigationItem key="navigationItem" id="M2f-nV-K0C"> <barButtonItem key="rightBarButtonItem" image="ei-pencil" id="ovc-xl-vHA"> <connections> - <segue destination="rr1-jx-MLx" kind="push" id="vj1-M0-h6U"/> + <segue destination="rr1-jx-MLx" kind="push" identifier="newPostSegue" id="vj1-M0-h6U"/> </connections> </barButtonItem> </navigationItem> @@ -286,7 +286,7 @@ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="XYj-Y4-lfM"> - <rect key="frame" x="4" y="16" width="367" height="647"/> + <rect key="frame" x="4" y="60" width="367" height="603"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> @@ -483,6 +483,6 @@ <image name="ei-search" width="32" height="32"/> </resources> <inferredMetricsTieBreakers> - <segue reference="gw8-QZ-Hrt"/> + <segue reference="vj1-M0-h6U"/> </inferredMetricsTieBreakers> </document> diff --git a/Juick/ViewControllers/DialogsViewController.m b/Juick/ViewControllers/DialogsViewController.m index cbf0024..c2296dd 100644 --- a/Juick/ViewControllers/DialogsViewController.m +++ b/Juick/ViewControllers/DialogsViewController.m @@ -36,6 +36,10 @@ [self.tableView beginUpdates]; [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES]; [self.tableView endUpdates]; + self.tableView.backgroundView = [UIView new]; + } else { + [self setEmptyMessageView:@"Sign in to view chats"]; + [self.tableView reloadData]; } [self.refreshControl endRefreshing]; }]; @@ -77,5 +81,18 @@ } } +- (void) setEmptyMessageView:(NSString *)message { + CGRect rect = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height); + UILabel *messageLabel = [[UILabel alloc] initWithFrame:rect]; + messageLabel.text = message; + messageLabel.numberOfLines = 0; + messageLabel.textAlignment = NSTextAlignmentCenter; + messageLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCallout]; + messageLabel.textColor = [UIColor colorNamed:@"Muted"]; + [messageLabel sizeToFit]; + self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; + [self.tableView setBackgroundView:messageLabel]; +} + @end diff --git a/Juick/ViewControllers/FeedViewController.m b/Juick/ViewControllers/FeedViewController.m index b6b578f..f6e36f4 100644 --- a/Juick/ViewControllers/FeedViewController.m +++ b/Juick/ViewControllers/FeedViewController.m @@ -23,7 +23,12 @@ -(void) viewDidLoad { self.messagesDelegate = self; self.title = @"Today"; - self.path = [APIClient feedUrl]; + if ([[APIClient sharedClient] isAuthenticated]) { + self.path = [APIClient feedUrl]; + } else { + self.path = [APIClient messagesUrl]; + self.params = @{@"popular": @1}; + } [self setShouldScrollToBottomOnRefresh:NO]; [super viewDidLoad]; } @@ -32,47 +37,6 @@ self.selectedUser = uname; [self performSegueWithIdentifier:@"profileSegue" sender:self]; } -/* -- (IBAction)filterAction:(id)sender { - if (![[APIClient sharedClient] isAuthenticated]) { - [self.navigationController performSegueWithIdentifier:@"loginSegue" sender:self.navigationController]; - return; - } - UIAlertController *filterAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; - [filterAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; - [filterAlert addAction:[UIAlertAction actionWithTitle:@"My feed" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { - self.path = [APIClient feedUrl]; - self.navigationController.visibleViewController.navigationItem.title = @"My feed"; - self.params = nil; - [self.messages removeAllObjects]; - [self.tableView reloadData]; - [self setShouldScrollToBottomOnRefresh:NO]; - }]]; - [filterAlert addAction:[UIAlertAction actionWithTitle:@"Discover" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { - self.path = [APIClient messagesUrl]; - self.navigationController.visibleViewController.navigationItem.title = @"Discover"; - self.params = nil; - [self.messages removeAllObjects]; - [self.tableView reloadData]; - [self setShouldScrollToBottomOnRefresh:NO]; - }]]; - [filterAlert addAction:[UIAlertAction actionWithTitle:@"Discussions" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { - self.path = [APIClient discussionsUrl]; - self.navigationController.visibleViewController.navigationItem.title = @"Discussions"; - self.params = nil; - [self.messages removeAllObjects]; - [self.tableView reloadData]; - [self setShouldScrollToBottomOnRefresh:NO]; - }]]; - [filterAlert.view setTintColor:[ColorScheme linkColor]]; - UIPopoverPresentationController *popover = [filterAlert popoverPresentationController]; - if (popover) { - popover.sourceView = self.view; - popover.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds), 0, 0); - popover.permittedArrowDirections = UIPopoverArrowDirectionUp; - } - [self presentViewController:filterAlert animated:YES completion:nil]; -}*/ -(void) loadMore { Message *lastMsg = [self.messages lastObject]; @@ -88,4 +52,20 @@ } } +- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender { + if ([identifier isEqualToString:@"newPostSegue"]) { + if ([[APIClient sharedClient] isAuthenticated]) { + return YES; + } else { + [self.navigationController performSegueWithIdentifier:@"loginSegue" sender:self]; + return NO; + } + } + return YES; +} + +- (void)didReceiveChallenge { + +} + @end diff --git a/Juick/ViewControllers/MessagesViewController.h b/Juick/ViewControllers/MessagesViewController.h index c8eb4cf..8f41af7 100644 --- a/Juick/ViewControllers/MessagesViewController.h +++ b/Juick/ViewControllers/MessagesViewController.h @@ -12,6 +12,7 @@ extern NSString* const messageCellIdentifier; @protocol MessagesDelegate +-(void) didReceiveChallenge; -(void) loadMore; @end diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index 7029beb..88bee93 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -33,7 +33,11 @@ NSString* const messageCellIdentifier = @"messageCell"; } [[APIClient sharedClient] pullNextFromPath:self.path params:self.params callback:^(NSArray *next, NSError *err) { if (err) { - [User throwUnableToLogin:self error:err]; + if ([err.domain isEqual: @"JuickErrorDomain"] && err.code == 401) { + [self.messagesDelegate didReceiveChallenge]; + } else { + [User throwUnableToLogin:self error:err]; + } return; } NSArray *newMsgs = next; |