diff options
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r-- | Juick/ViewControllers/DiscoverViewController.h | 2 | ||||
-rw-r--r-- | Juick/ViewControllers/DiscoverViewController.m | 23 | ||||
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.h | 7 | ||||
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.m | 9 |
4 files changed, 32 insertions, 9 deletions
diff --git a/Juick/ViewControllers/DiscoverViewController.h b/Juick/ViewControllers/DiscoverViewController.h index 6bec23d..9f96b98 100644 --- a/Juick/ViewControllers/DiscoverViewController.h +++ b/Juick/ViewControllers/DiscoverViewController.h @@ -9,6 +9,6 @@ #import <UIKit/UIKit.h> #import "MessagesViewController.h" -@interface DiscoverViewController : MessagesViewController +@interface DiscoverViewController : MessagesViewController<MessagesDelegate> @end diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m index c027ea7..1b1a0a1 100644 --- a/Juick/ViewControllers/DiscoverViewController.m +++ b/Juick/ViewControllers/DiscoverViewController.m @@ -22,6 +22,7 @@ AppDelegate *appDelegate; -(void) viewDidLoad { [super viewDidLoad]; + self.messagesDelegate = self; if ([User isAuthenticated]) { [User checkIsValid:^(BOOL success) { if (success) { @@ -91,7 +92,29 @@ AppDelegate *appDelegate; [self.tableView reloadData]; [self refreshData:NO]; }]]; + [filterAlert addAction:[UIAlertAction actionWithTitle:@"Discussions" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + [self setTitle:@"Discussions"]; + self.path = [APIClient discussionsUrl]; + self.params = nil; + [self.messages removeAllObjects]; + [self.tableView reloadData]; + [self refreshData:NO]; + }]]; [self presentViewController:filterAlert animated:YES completion:nil]; } +-(void) loadMore { + Message *lastMsg = [self.messages lastObject]; + if (lastMsg != nil) { + if ([self.path isEqualToString:[APIClient discussionsUrl]]) { + NSDate *msgDate = [[APIClient sharedClient].dateFormatter dateFromString:lastMsg.timestamp]; + self.params = [@{@"to" : [NSString stringWithFormat:@"%.0f", [msgDate timeIntervalSince1970] * 1000]} mutableCopy]; + } else if (![self.path isEqualToString:[APIClient threadUrl]]) { + NSNumber *lastMid = lastMsg.mid; + self.params = [@{@"before_mid":lastMid} mutableCopy]; + } + [self refreshData:NO]; + } +} + @end diff --git a/Juick/ViewControllers/MessagesViewController.h b/Juick/ViewControllers/MessagesViewController.h index 9f47b57..2259b91 100644 --- a/Juick/ViewControllers/MessagesViewController.h +++ b/Juick/ViewControllers/MessagesViewController.h @@ -8,6 +8,10 @@ #import <UIKit/UIKit.h> +@protocol MessagesDelegate +-(void) loadMore; +@end + @interface MessagesViewController : UITableViewController @property(nonatomic, strong) NSString *path; @property(nonatomic, strong) NSDictionary *params; @@ -16,4 +20,7 @@ @property(nonatomic, strong) NSMutableArray *messages; @property(nonatomic, assign) Boolean dataLoading; +@property(nonatomic, weak) id<MessagesDelegate> messagesDelegate; @end + + diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index de79164..c718336 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -103,14 +103,7 @@ CGFloat actualPosition = scrollView_.contentOffset.y; CGFloat contentHeight = scrollView_.contentSize.height - scrollView_.contentSize.height / 2; if (actualPosition >= contentHeight && !self.dataLoading && ![self.tableView isTracking]) { - Message *lastMsg = [self.messages lastObject]; - if (lastMsg != nil) { - NSNumber *lastMid = lastMsg.mid; - if (![self.path isEqualToString:[APIClient threadUrl]]) { - self.params = [@{@"before_mid":lastMid} mutableCopy]; - } - [self refreshData:NO]; - } + [_messagesDelegate loadMore]; } } |