diff options
Diffstat (limited to 'Juick/ViewControllers/MessagesViewController.m')
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.m | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index 57087d7..09e84ec 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -69,9 +69,11 @@ NSString* const messageCellIdentifier = @"messageCell"; [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:NO]; [self.tableView endUpdates]; [self.refreshControl endRefreshing]; - if (self.shouldScrollToBottomOnRefresh) { - NSIndexPath *lastRow = [NSIndexPath indexPathForRow:self.messages.count - 1 inSection:0]; + if (self.shouldScrollToUnreadOnRefresh) { + NSInteger itemToScroll = [self.firstUnread integerValue] || self.messages.count - 1; + NSIndexPath *lastRow = [NSIndexPath indexPathForRow:itemToScroll inSection:0]; [self.tableView scrollToRowAtIndexPath:lastRow atScrollPosition:UITableViewScrollPositionBottom animated:NO]; + self.firstUnread = nil; } }]; } @@ -132,7 +134,7 @@ NSString* const messageCellIdentifier = @"messageCell"; -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Message *msg = [self.messages objectAtIndex:indexPath.row]; - [self viewThreadForMessage:msg mid:msg.mid]; + [self viewThreadForMessage:msg mid:msg.mid scrollTo:0]; } -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { @@ -154,13 +156,18 @@ NSString* const messageCellIdentifier = @"messageCell"; } } --(void) viewThreadForMessage:(Message *)msg mid:(NSNumber *)mid { +-(void) viewThreadForMessage:(Message *)msg mid:(NSNumber *)mid scrollTo:(NSNumber *)rid { ThreadViewController *threadVC = [AppDelegate threadViewController]; if (msg) { [threadVC setMessages:[@[msg] mutableCopy]]; } [threadVC setParams:@{@"mid": mid }]; - [threadVC setShouldScrollToBottomOnRefresh:NO]; + if (rid) { + [threadVC setFirstUnread:rid]; + [threadVC setShouldScrollToUnreadOnRefresh:YES]; + } else { + [threadVC setShouldScrollToUnreadOnRefresh:NO]; + } [self.navigationController pushViewController:threadVC animated:YES]; } |