diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.h b/Signal/src/ViewControllers/ConversationView/ConversationViewController.h index 31d7841c1..0529b940b 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import @@ -25,6 +25,8 @@ typedef NS_ENUM(NSUInteger, ConversationViewAction) { - (void)popKeyBoard; +- (void)scrollToFirstUnreadMessage:(BOOL)isAnimated; + #pragma mark 3D Touch Methods - (void)peekSetup; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 0002ac339..05924083e 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -752,7 +752,7 @@ typedef enum : NSUInteger { // We want to set the initial scroll state the first time we enter the view. if (!self.viewHasEverAppeared) { - [self scrollToDefaultPosition]; + [self scrollToDefaultPosition:NO]; } else if (self.menuActionsViewController != nil) { [self scrollToMenuActionInteraction:NO]; } @@ -807,7 +807,7 @@ typedef enum : NSUInteger { return [NSIndexPath indexPathForRow:row inSection:0]; } -- (void)scrollToDefaultPosition +- (void)scrollToDefaultPosition:(BOOL)isAnimated { if (self.isUserScrolling) { return; @@ -824,14 +824,14 @@ typedef enum : NSUInteger { if (indexPath) { if (indexPath.section == 0 && indexPath.row == 0) { - [self.collectionView setContentOffset:CGPointZero animated:NO]; + [self.collectionView setContentOffset:CGPointZero animated:isAnimated]; } else { [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop - animated:NO]; + animated:isAnimated]; } } else { - [self scrollToBottomAnimated:NO]; + [self scrollToBottomAnimated:isAnimated]; } } @@ -3899,7 +3899,7 @@ typedef enum : NSUInteger { // Adjust content offset to prevent the presented keyboard from obscuring content. if (!self.viewHasEverAppeared) { - [self scrollToDefaultPosition]; + [self scrollToDefaultPosition:NO]; } else if (wasScrolledToBottom) { // If we were scrolled to the bottom, don't do any fancy math. Just stay at the bottom. [self scrollToBottomAnimated:NO]; @@ -4026,6 +4026,11 @@ typedef enum : NSUInteger { [self didScrollToBottom]; } +- (void)scrollToFirstUnreadMessage:(BOOL)isAnimated +{ + [self scrollToDefaultPosition:isAnimated]; +} + #pragma mark - UIScrollViewDelegate - (void)updateLastKnownDistanceFromBottom diff --git a/Signal/src/environment/SignalApp.h b/Signal/src/environment/SignalApp.h index b3b5fb9dc..e89daec85 100644 --- a/Signal/src/environment/SignalApp.h +++ b/Signal/src/environment/SignalApp.h @@ -46,6 +46,8 @@ NS_ASSUME_NONNULL_BEGIN focusMessageId:(nullable NSString *)focusMessageId animated:(BOOL)isAnimated; +- (void)presentConversationForThreadAndShowFirstUnreadMessage:(TSThread *)thread animated:(BOOL)isAnimated; + #pragma mark - Methods + (void)resetAppData; diff --git a/Signal/src/environment/SignalApp.m b/Signal/src/environment/SignalApp.m index 0316ae5bd..b03834b31 100644 --- a/Signal/src/environment/SignalApp.m +++ b/Signal/src/environment/SignalApp.m @@ -109,7 +109,7 @@ NS_ASSUME_NONNULL_BEGIN DispatchMainThreadSafe(^{ UIViewController *frontmostVC = [[UIApplication sharedApplication] frontmostViewController]; - + if ([frontmostVC isKindOfClass:[ConversationViewController class]]) { ConversationViewController *conversationVC = (ConversationViewController *)frontmostVC; if ([conversationVC.thread.uniqueId isEqualToString:thread.uniqueId]) { @@ -117,11 +117,40 @@ NS_ASSUME_NONNULL_BEGIN return; } } - + [self.homeViewController presentThread:thread action:action focusMessageId:focusMessageId animated:isAnimated]; }); } +- (void)presentConversationForThreadAndShowFirstUnreadMessage:(TSThread *)thread animated:(BOOL)isAnimated +{ + OWSAssertIsOnMainThread(); + + OWSLogInfo(@""); + + if (!thread) { + OWSFailDebug(@"Can't present nil thread."); + return; + } + + DispatchMainThreadSafe(^{ + UIViewController *frontmostVC = [[UIApplication sharedApplication] frontmostViewController]; + + if ([frontmostVC isKindOfClass:[ConversationViewController class]]) { + ConversationViewController *conversationVC = (ConversationViewController *)frontmostVC; + if ([conversationVC.thread.uniqueId isEqualToString:thread.uniqueId]) { + [conversationVC scrollToFirstUnreadMessage:isAnimated]; + return; + } + } + + [self.homeViewController presentThread:thread + action:ConversationViewActionNone + focusMessageId:nil + animated:isAnimated]; + }); +} + - (void)didChangeCallLoggingPreference:(NSNotification *)notitication { [AppEnvironment.shared.callService createCallUIAdapter];