summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-03-22 00:33:30 +0300
committerGravatar Vitaly Takmazov2019-03-22 00:33:30 +0300
commit5f4a09ec689cb04ce71b4eb7425936f04a70f6f4 (patch)
tree9653dc543bd8f47dbfa853cd36ace63206efc983 /Juick/ViewControllers
parent6e49fc5c4273e7597925c133c3a6985b6ad85ecc (diff)
Fix sign in
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r--Juick/ViewControllers/DialogsViewController.m17
-rw-r--r--Juick/ViewControllers/FeedViewController.m64
-rw-r--r--Juick/ViewControllers/MessagesViewController.h1
-rw-r--r--Juick/ViewControllers/MessagesViewController.m6
4 files changed, 45 insertions, 43 deletions
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;