Handle notifications for open conversations.

pull/2/head
Matthew Chen 6 years ago
parent 4e8e41c327
commit f3d0cd99fc

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
#import <SignalMessaging/OWSViewController.h> #import <SignalMessaging/OWSViewController.h>
@ -25,6 +25,8 @@ typedef NS_ENUM(NSUInteger, ConversationViewAction) {
- (void)popKeyBoard; - (void)popKeyBoard;
- (void)scrollToFirstUnreadMessage:(BOOL)isAnimated;
#pragma mark 3D Touch Methods #pragma mark 3D Touch Methods
- (void)peekSetup; - (void)peekSetup;

@ -752,7 +752,7 @@ typedef enum : NSUInteger {
// We want to set the initial scroll state the first time we enter the view. // We want to set the initial scroll state the first time we enter the view.
if (!self.viewHasEverAppeared) { if (!self.viewHasEverAppeared) {
[self scrollToDefaultPosition]; [self scrollToDefaultPosition:NO];
} else if (self.menuActionsViewController != nil) { } else if (self.menuActionsViewController != nil) {
[self scrollToMenuActionInteraction:NO]; [self scrollToMenuActionInteraction:NO];
} }
@ -807,7 +807,7 @@ typedef enum : NSUInteger {
return [NSIndexPath indexPathForRow:row inSection:0]; return [NSIndexPath indexPathForRow:row inSection:0];
} }
- (void)scrollToDefaultPosition - (void)scrollToDefaultPosition:(BOOL)isAnimated
{ {
if (self.isUserScrolling) { if (self.isUserScrolling) {
return; return;
@ -824,14 +824,14 @@ typedef enum : NSUInteger {
if (indexPath) { if (indexPath) {
if (indexPath.section == 0 && indexPath.row == 0) { if (indexPath.section == 0 && indexPath.row == 0) {
[self.collectionView setContentOffset:CGPointZero animated:NO]; [self.collectionView setContentOffset:CGPointZero animated:isAnimated];
} else { } else {
[self.collectionView scrollToItemAtIndexPath:indexPath [self.collectionView scrollToItemAtIndexPath:indexPath
atScrollPosition:UICollectionViewScrollPositionTop atScrollPosition:UICollectionViewScrollPositionTop
animated:NO]; animated:isAnimated];
} }
} else { } 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. // Adjust content offset to prevent the presented keyboard from obscuring content.
if (!self.viewHasEverAppeared) { if (!self.viewHasEverAppeared) {
[self scrollToDefaultPosition]; [self scrollToDefaultPosition:NO];
} else if (wasScrolledToBottom) { } else if (wasScrolledToBottom) {
// If we were scrolled to the bottom, don't do any fancy math. Just stay at the bottom. // If we were scrolled to the bottom, don't do any fancy math. Just stay at the bottom.
[self scrollToBottomAnimated:NO]; [self scrollToBottomAnimated:NO];
@ -4026,6 +4026,11 @@ typedef enum : NSUInteger {
[self didScrollToBottom]; [self didScrollToBottom];
} }
- (void)scrollToFirstUnreadMessage:(BOOL)isAnimated
{
[self scrollToDefaultPosition:isAnimated];
}
#pragma mark - UIScrollViewDelegate #pragma mark - UIScrollViewDelegate
- (void)updateLastKnownDistanceFromBottom - (void)updateLastKnownDistanceFromBottom

@ -46,6 +46,8 @@ NS_ASSUME_NONNULL_BEGIN
focusMessageId:(nullable NSString *)focusMessageId focusMessageId:(nullable NSString *)focusMessageId
animated:(BOOL)isAnimated; animated:(BOOL)isAnimated;
- (void)presentConversationForThreadAndShowFirstUnreadMessage:(TSThread *)thread animated:(BOOL)isAnimated;
#pragma mark - Methods #pragma mark - Methods
+ (void)resetAppData; + (void)resetAppData;

@ -122,6 +122,35 @@ NS_ASSUME_NONNULL_BEGIN
}); });
} }
- (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 - (void)didChangeCallLoggingPreference:(NSNotification *)notitication
{ {
[AppEnvironment.shared.callService createCallUIAdapter]; [AppEnvironment.shared.callService createCallUIAdapter];

Loading…
Cancel
Save