diff options
author | Vitaly Takmazov | 2019-03-21 23:39:03 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-03-21 23:39:03 +0300 |
commit | 6e49fc5c4273e7597925c133c3a6985b6ad85ecc (patch) | |
tree | ca5c8bac8e6bbe73d28db597be38840a4e88deca /Juick/ViewControllers/MessagesViewController.m | |
parent | 31cee12a4f5c2733965e99e2fa9add28fee266c2 (diff) |
First RC
Diffstat (limited to 'Juick/ViewControllers/MessagesViewController.m')
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.m | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index 8a1d072..7029beb 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -95,14 +95,12 @@ NSString* const messageCellIdentifier = @"messageCell"; [self.tableView registerNib:[UINib nibWithNibName:@"ContentLoadingCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"contentLoadingCell"]; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 500.0f; - if (![self.path isEqualToString:[APIClient threadUrl]]) { + if (!self.messages) { self.messages = [NSMutableArray array]; } self.refreshControl = [UIRefreshControl new]; [self.refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged]; [self refreshData]; - [self addObserver:self forKeyPath:@"path" options:0 context:nil]; - [self addObserver:self forKeyPath:@"params" options:0 context:nil]; } - (void) composePressed { @@ -133,32 +131,30 @@ NSString* const messageCellIdentifier = @"messageCell"; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:messageCellIdentifier forIndexPath:indexPath]; - [self performSegueWithIdentifier:@"threadViewSegue" sender:cell]; + Message *msg = [self.messages objectAtIndex:indexPath.row]; + [self viewThreadForMessage:msg mid:msg.mid]; } -(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]; - [AppDelegate shared].pushedThread = nil; - [AppDelegate shared].pushedUname = nil; - scrollToEnd = YES; - } else { - 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]; - } - } /* + NSNumber *mid; + Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; + BOOL scrollToEnd = NO; + if ([AppDelegate shared].pushedThread != nil) { + mid = [[AppDelegate shared].pushedThread copy]; + [AppDelegate shared].pushedThread = nil; + [AppDelegate shared].pushedUname = nil; + scrollToEnd = YES; + } else { + 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]; + } if ([segue.identifier isEqual: @"profileSegue"]) { BlogViewController *blogVC = (BlogViewController *)segue.destinationViewController; [blogVC setUname:self.selectedUser]; @@ -176,8 +172,14 @@ NSString* const messageCellIdentifier = @"messageCell"; } } -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context { - [self refreshData]; +-(void) viewThreadForMessage:(Message *)msg mid:(NSNumber *)mid { + ThreadViewController *threadVC = [AppDelegate threadViewController]; + if (msg) { + [threadVC setMessages:[@[msg] mutableCopy]]; + } + [threadVC setParams:@{@"mid": mid }]; + [threadVC setShouldScrollToBottomOnRefresh:NO]; + [self.navigationController pushViewController:threadVC animated:YES]; } @end |