diff options
author | Vitaly Takmazov | 2019-03-25 16:07:22 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-03-25 16:07:22 +0300 |
commit | 72fbd1b82041082dfb25cfdf0f28db65fd1c878a (patch) | |
tree | da00ae2f01af038da435342ee7282fe8575c7e4d | |
parent | 163a79e2aa4df23638686ca0608cdbaf6e6dad6f (diff) |
Scroll to reply from notification
-rw-r--r-- | Juick/AppDelegate.h | 1 | ||||
-rw-r--r-- | Juick/AppDelegate.m | 3 | ||||
-rw-r--r-- | Juick/ViewControllers/DiscoverViewController.m | 4 | ||||
-rw-r--r-- | Juick/ViewControllers/DiscussionsController.m | 4 | ||||
-rw-r--r-- | Juick/ViewControllers/FeedViewController.m | 4 | ||||
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.h | 6 | ||||
-rw-r--r-- | Juick/ViewControllers/MessagesViewController.m | 17 | ||||
-rw-r--r-- | Juick/ViewControllers/NewPostViewController.m | 4 | ||||
-rw-r--r-- | Juick/ViewControllers/ThreadViewController.m | 2 |
9 files changed, 27 insertions, 18 deletions
diff --git a/Juick/AppDelegate.h b/Juick/AppDelegate.h index 7b287e2..54d627e 100644 --- a/Juick/AppDelegate.h +++ b/Juick/AppDelegate.h @@ -24,5 +24,6 @@ extern NSString * const UserUpdatedNotificationName; @property (strong, nonatomic) NSNumber *pushedThread; @property (strong, nonatomic) NSString *pushedUname; +@property (strong, nonatomic) NSNumber *pushedReplyId; @end diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index 65220ff..b483a68 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -98,7 +98,7 @@ NSString * const UserUpdatedNotificationName = @"UserUpdated"; UINavigationController *discover = (UINavigationController *)[main.viewControllers objectAtIndex:0]; [discover popToRootViewControllerAnimated:NO]; MessagesViewController *msgVC = (MessagesViewController *)[discover.viewControllers objectAtIndex:0]; - [msgVC viewThreadForMessage:nil mid:self.pushedThread]; + [msgVC viewThreadForMessage:nil mid:self.pushedThread scrollTo:self.pushedReplyId]; } else { [main setSelectedIndex:2]; UINavigationController *dialogs = (UINavigationController *)[main.viewControllers objectAtIndex:2]; @@ -135,6 +135,7 @@ NSString * const UserUpdatedNotificationName = @"UserUpdated"; -(void) parseNotificationPayload:(NSDictionary *)userInfo { self.pushedThread = userInfo[@"mid"]; self.pushedUname = userInfo[@"uname"]; + self.pushedReplyId = userInfo[@"rid"]; } +(AppDelegate *) shared { diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m index f75e7d5..7bf9f74 100644 --- a/Juick/ViewControllers/DiscoverViewController.m +++ b/Juick/ViewControllers/DiscoverViewController.m @@ -18,7 +18,7 @@ self.messagesDelegate = self; self.title = @"Discover"; self.path = [APIClient messagesUrl]; - [self setShouldScrollToBottomOnRefresh:NO]; + [self setShouldScrollToUnreadOnRefresh:NO]; [super viewDidLoad]; } @@ -27,7 +27,7 @@ if (lastMsg != nil) { NSNumber *lastMid = lastMsg.mid; self.params = [@{@"before_mid":lastMid} mutableCopy]; - [self setShouldScrollToBottomOnRefresh:NO]; + [self setShouldScrollToUnreadOnRefresh:NO]; [self refreshData]; } } diff --git a/Juick/ViewControllers/DiscussionsController.m b/Juick/ViewControllers/DiscussionsController.m index 1a759a1..607ac26 100644 --- a/Juick/ViewControllers/DiscussionsController.m +++ b/Juick/ViewControllers/DiscussionsController.m @@ -19,7 +19,7 @@ self.messagesDelegate = self; self.title = @"Discussions"; self.path = [APIClient discussionsUrl]; - [self setShouldScrollToBottomOnRefresh:NO]; + [self setShouldScrollToUnreadOnRefresh:NO]; [super viewDidLoad]; } @@ -28,7 +28,7 @@ if (lastMsg != nil) { NSDate *msgDate = [[APIClient sharedClient].dateFormatter dateFromString:lastMsg.timestamp]; self.params = [@{@"to" : [NSString stringWithFormat:@"%.0f", [msgDate timeIntervalSince1970] * 1000]} mutableCopy]; - [self setShouldScrollToBottomOnRefresh:NO]; + [self setShouldScrollToUnreadOnRefresh:NO]; [self refreshData]; } } diff --git a/Juick/ViewControllers/FeedViewController.m b/Juick/ViewControllers/FeedViewController.m index fc8c387..523ea52 100644 --- a/Juick/ViewControllers/FeedViewController.m +++ b/Juick/ViewControllers/FeedViewController.m @@ -25,7 +25,7 @@ self.messagesDelegate = self; self.title = @"Today"; [self refreshPath]; - [self setShouldScrollToBottomOnRefresh:NO]; + [self setShouldScrollToUnreadOnRefresh:NO]; [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidSignedIn:) name:UserSignedInNotificationName object:nil]; } @@ -40,7 +40,7 @@ if (lastMsg != nil) { NSNumber *lastMid = lastMsg.mid; self.params = [@{@"before_mid":lastMid} mutableCopy]; - [self setShouldScrollToBottomOnRefresh:NO]; + [self setShouldScrollToUnreadOnRefresh:NO]; [self refreshData]; } } diff --git a/Juick/ViewControllers/MessagesViewController.h b/Juick/ViewControllers/MessagesViewController.h index c8eb4cf..7025e8b 100644 --- a/Juick/ViewControllers/MessagesViewController.h +++ b/Juick/ViewControllers/MessagesViewController.h @@ -18,11 +18,11 @@ extern NSString* const messageCellIdentifier; @interface MessagesViewController : UITableViewController @property(nonatomic, strong) NSString *path; @property(nonatomic, strong) NSDictionary *params; -@property(nonatomic, assign) BOOL shouldScrollToBottomOnRefresh; - +@property(nonatomic, assign) BOOL shouldScrollToUnreadOnRefresh; +@property(nonatomic) NSNumber * firstUnread; -(void) refreshData; --(void) viewThreadForMessage:(Message *)msg mid:(NSNumber *)mid; +-(void) viewThreadForMessage:(Message *)msg mid:(NSNumber *)mid scrollTo:(NSNumber *)rid; @property(nonatomic, strong) NSMutableArray *messages; @property(nonatomic, assign) Boolean dataLoading; 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]; } diff --git a/Juick/ViewControllers/NewPostViewController.m b/Juick/ViewControllers/NewPostViewController.m index 44338bf..65172f1 100644 --- a/Juick/ViewControllers/NewPostViewController.m +++ b/Juick/ViewControllers/NewPostViewController.m @@ -45,13 +45,13 @@ [[APIClient sharedClient] postMessage:self.textView.text result:^(Message *msg, NSError *err) { self.navigationController.navigationItem.rightBarButtonItem.enabled = YES; [self.navigationController popViewControllerAnimated:YES]; - [(MessagesViewController *)self.navigationController.visibleViewController setShouldScrollToBottomOnRefresh:YES]; + [(MessagesViewController *)self.navigationController.visibleViewController setShouldScrollToUnreadOnRefresh:YES]; }]; } else { [[APIClient sharedClient] postReplyToThread:_replyTo.mid inReplyTo:_replyTo.rid text:self.textView.text result:^(Message *msg, NSError *err) { self.navigationController.navigationItem.rightBarButtonItem.enabled = YES; [self.navigationController popViewControllerAnimated:YES]; - [(MessagesViewController *)self.navigationController.visibleViewController setShouldScrollToBottomOnRefresh:YES]; + [(MessagesViewController *)self.navigationController.visibleViewController setShouldScrollToUnreadOnRefresh:YES]; [(MessagesViewController *)self.navigationController.visibleViewController refreshData]; }]; } diff --git a/Juick/ViewControllers/ThreadViewController.m b/Juick/ViewControllers/ThreadViewController.m index 48999b4..1bc820a 100644 --- a/Juick/ViewControllers/ThreadViewController.m +++ b/Juick/ViewControllers/ThreadViewController.m @@ -36,7 +36,7 @@ -(void) loadMore { Message *lastMsg = [self.messages lastObject]; - [self setShouldScrollToBottomOnRefresh:lastMsg.rid > 0]; + [self setShouldScrollToUnreadOnRefresh:lastMsg.rid > 0]; [self refreshData]; } |