summaryrefslogtreecommitdiff
path: root/Juick/MessagesViewController.m
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2014-01-30 17:16:06 +0400
committerGravatar Vitaly Takmazov2014-01-30 17:16:17 +0400
commit63f9e9576991fa8e50ca728836c6ba6917bbbc26 (patch)
treefed956ca4f77869f37ddd561d7fc3e4129d66317 /Juick/MessagesViewController.m
parentc0a5f540950dcf34eb08dc990ec753df6ae98ede (diff)
LoginView
Diffstat (limited to 'Juick/MessagesViewController.m')
-rw-r--r--Juick/MessagesViewController.m26
1 files changed, 17 insertions, 9 deletions
diff --git a/Juick/MessagesViewController.m b/Juick/MessagesViewController.m
index b77901b..4518686 100644
--- a/Juick/MessagesViewController.m
+++ b/Juick/MessagesViewController.m
@@ -25,15 +25,17 @@ static NSString *CellIdentifier = @"MessageCell";
@property(nonatomic, strong) NSMutableArray *messages;
@property(nonatomic, assign) Boolean dataLoading;
-@property(nonatomic, strong) NSURL *url;
+@property(nonatomic, strong) NSString *path;
+@property(nonatomic, strong) NSMutableDictionary *params;
@end
@implementation MessagesViewController
-- (void)loadFromURL:(NSURL *)messagesURL withTitle:(NSString *)title
+- (void)loadFromPath:(NSString *)messagesPath withParams:(NSDictionary *)params withTitle:(NSString *)title
{
- [self setUrl:messagesURL];
+ [self setPath:messagesPath];
+ [self setParams:params];
self.title = title;
[self refreshData:nil];
}
@@ -41,7 +43,7 @@ static NSString *CellIdentifier = @"MessageCell";
- (void) refreshData:(UIRefreshControl *)refresh {
[self.messages removeAllObjects];
[self.tableView reloadData];
- [Message pullNextFromURL:self.url callback:^(NSArray *next) {
+ [Message pullNextFromPath:self.path params:self.params callback:^(NSArray *next) {
[self.messages addObjectsFromArray:next];
[self.tableView reloadData];
[refresh endRefreshing];
@@ -54,7 +56,7 @@ static NSString *CellIdentifier = @"MessageCell";
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- if ([self.url.absoluteString hasPrefix:[Message threadUrl]]) {
+ if ([self.path isEqualToString:[Message threadUrl]]) {
return;
}
CGPoint pos = scrollView.contentOffset;
@@ -62,9 +64,15 @@ static NSString *CellIdentifier = @"MessageCell";
if (pos.y >= contentHeight && !self.dataLoading) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
self.dataLoading = YES;
+ if (self.params == nil) {
+ self.params = [[NSMutableDictionary alloc] init];
+ }
+
Message * lastMessage = [self.messages lastObject];
- NSURL *beforeUrl = [self.url URLByAppendingParameters:[NSDictionary dictionaryWithObjectsAndKeys:lastMessage.MID, @"before_mid", nil]];
- [Message pullNextFromURL:beforeUrl callback:^(NSArray *next) {
+ if (lastMessage != nil) {
+ [self.params setValue:lastMessage.MID forKey:@"before_mid"];
+ }
+ [Message pullNextFromPath:self.path params:self.params callback:^(NSArray *next) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.messages addObjectsFromArray:next];
[self.tableView reloadData];
@@ -185,11 +193,11 @@ static NSString *CellIdentifier = @"MessageCell";
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if ([self.url.absoluteString hasPrefix:[Message threadUrl]])
+ if ([self.path isEqualToString:[Message threadUrl]])
return;
Message *msg = [_messages objectAtIndex:indexPath.row];
MessagesViewController *threadViewController = [[MessagesViewController alloc] init];
- [threadViewController loadFromURL:[[NSURL URLWithString:[Message threadUrl]] URLByAppendingParameters:[NSDictionary dictionaryWithObjectsAndKeys:msg.MID, @"mid", nil]] withTitle:@"Thread"];
+ [threadViewController loadFromPath:[Message threadUrl] withParams:[NSDictionary dictionaryWithObjectsAndKeys:msg.MID, @"mid", nil] withTitle:@"Thread"];
[self.navigationController pushViewController:threadViewController animated:NO];
}