diff options
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.h | 2 | ||||
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.m | 21 |
2 files changed, 16 insertions, 7 deletions
diff --git a/Juick/ViewControllers/MessagesViewController.h b/Juick/ViewControllers/MessagesViewController.h index 9478a17..48a9f6b 100644 --- a/Juick/ViewControllers/MessagesViewController.h +++ b/Juick/ViewControllers/MessagesViewController.h @@ -9,6 +9,8 @@ #import <UIKit/UIKit.h> #import "MessageCell.h" +extern NSString* const messageCellIdentifier; + @protocol MessagesDelegate -(void) loadMore; @end diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index 8b4bfae..554f9b1 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -21,6 +21,8 @@ #import "NSURL+PathParameters.h" +NSString* const messageCellIdentifier = @"messageCell"; + @implementation MessagesViewController -(void) refreshData { @@ -36,8 +38,10 @@ } NSArray *newMsgs = next; if ([self isAtTop:self.params]) { - [self.messages removeAllObjects]; - [self.tableView reloadData]; + if (![self.path isEqualToString:[APIClient threadUrl]]) { + [self.messages removeAllObjects]; + [self.tableView reloadData]; + } } NSUInteger oldCount = [self.messages count]; if ([self.path isEqualToString:[APIClient threadUrl]]) { @@ -47,6 +51,7 @@ if (lastRid && lastRid < count) { newMsgs = [next subarrayWithRange:NSMakeRange(lastRid, count - lastRid)]; } else { + [self.refreshControl endRefreshing]; return; } } @@ -86,11 +91,13 @@ [super viewDidLoad]; self.dataLoading = YES; [self.view setBackgroundColor:[UIColor colorNamed:@"Background"]]; - [self.tableView registerNib:[UINib nibWithNibName:@"MessageCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"messageCell"]; + [self.tableView registerNib:[UINib nibWithNibName:@"MessageCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:messageCellIdentifier]; [self.tableView registerNib:[UINib nibWithNibName:@"ContentLoadingCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"contentLoadingCell"]; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 500.0f; - self.messages = [NSMutableArray array]; + if (![self.path isEqualToString:[APIClient threadUrl]]) { + self.messages = [NSMutableArray array]; + } self.refreshControl = [UIRefreshControl new]; [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; [self refreshData]; @@ -115,8 +122,7 @@ return [tableView dequeueReusableCellWithIdentifier:@"contentLoadingCell"]; } else { Message *msg = [self.messages objectAtIndex:indexPath.row]; - NSString * cellIdentifier = @"messageCell"; - MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; + MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:messageCellIdentifier forIndexPath:indexPath]; [cell configureWithMessage:msg]; return cell; } @@ -135,6 +141,7 @@ -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqual: @"threadViewSegue"]) { NSNumber *mid; + Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; BOOL scrollToEnd = NO; if ([AppDelegate shared].pushedThread != nil) { mid = [[AppDelegate shared].pushedThread copy]; @@ -142,11 +149,11 @@ [AppDelegate shared].pushedUname = nil; scrollToEnd = YES; } else { - Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; mid = msg.mid; } if ([mid integerValue] > 0) { ThreadViewController *threadVC = (ThreadViewController *)segue.destinationViewController; + [threadVC setMessages:[@[msg] mutableCopy]]; [threadVC setPath:[APIClient threadUrl]]; [threadVC setParams:@{@"mid": mid }]; [threadVC setShouldScrollToBottomOnRefresh:scrollToEnd]; |