// // ThreadViewController.m // Juick // // Created by Vitaly Takmazov on 24/09/2017. // Copyright © 2017 com.juick. All rights reserved. // #import "ThreadViewController.h" #import "NewPostViewController.h" #import "MessageCell.h" #import "APIClient.h" @implementation ThreadViewController -(void) viewDidLoad { [self setTitle:@"Thread"]; [self setPath:[APIClient threadUrl]]; [super viewDidLoad]; self.messagesDelegate = self; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(replyPosted:) name:ReplyPostedNotificationName object:nil]; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:messageCellIdentifier forIndexPath:indexPath]; [self performSegueWithIdentifier:@"replySegue" sender:cell]; } -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqual: @"replySegue"]) { Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; NewPostViewController *postVC = (NewPostViewController *)[((UINavigationController *)segue.destinationViewController) .viewControllers firstObject]; [postVC setReplyTo:msg]; } } -(void) loadMore { Message *lastMsg = [self.messages lastObject]; [self setShouldScrollToUnreadOnRefresh:lastMsg.rid > 0]; [self refreshData]; } - (void)replyPosted:(NSNotification *) notification { [self setShouldScrollToUnreadOnRefresh:YES]; [self refreshData]; } @end