|
|
|
@ -42,6 +42,7 @@
|
|
|
|
|
#import "TSIncomingMessage.h"
|
|
|
|
|
#import "TSInfoMessage.h"
|
|
|
|
|
#import "TSInvalidIdentityKeyErrorMessage.h"
|
|
|
|
|
#import "TSUnreadIndicatorInteraction.h"
|
|
|
|
|
#import "ThreadUtil.h"
|
|
|
|
|
#import "UIFont+OWS.h"
|
|
|
|
|
#import "UIUtil.h"
|
|
|
|
@ -98,6 +99,8 @@ typedef enum : NSUInteger {
|
|
|
|
|
|
|
|
|
|
- (void)didPasteAttachment:(SignalAttachment * _Nullable)attachment;
|
|
|
|
|
|
|
|
|
|
- (void)textViewDidChangeSize;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
@ -146,6 +149,30 @@ typedef enum : NSUInteger {
|
|
|
|
|
[super paste:sender];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setFrame:(CGRect)frame
|
|
|
|
|
{
|
|
|
|
|
BOOL isNonEmpty = (self.width > 0.f && self.height > 0.f);
|
|
|
|
|
BOOL didChangeSize = !CGSizeEqualToSize(frame.size, self.frame.size);
|
|
|
|
|
|
|
|
|
|
[super setFrame:frame];
|
|
|
|
|
|
|
|
|
|
if (didChangeSize && isNonEmpty) {
|
|
|
|
|
[self.textViewPasteDelegate textViewDidChangeSize];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setBounds:(CGRect)bounds
|
|
|
|
|
{
|
|
|
|
|
BOOL isNonEmpty = (self.width > 0.f && self.height > 0.f);
|
|
|
|
|
BOOL didChangeSize = !CGSizeEqualToSize(bounds.size, self.bounds.size);
|
|
|
|
|
|
|
|
|
|
[super setBounds:bounds];
|
|
|
|
|
|
|
|
|
|
if (didChangeSize && isNonEmpty) {
|
|
|
|
|
[self.textViewPasteDelegate textViewDidChangeSize];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
@ -611,6 +638,7 @@ typedef enum : NSUInteger {
|
|
|
|
|
@property (nonatomic) NSCache *messageAdapterCache;
|
|
|
|
|
@property (nonatomic) BOOL userHasScrolled;
|
|
|
|
|
@property (nonatomic) NSDate *lastMessageSentDate;
|
|
|
|
|
@property (nonatomic) NSTimer *scrollLaterTimer;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
@ -782,6 +810,7 @@ typedef enum : NSUInteger {
|
|
|
|
|
|
|
|
|
|
self.senderId = ME_MESSAGE_IDENTIFIER;
|
|
|
|
|
self.senderDisplayName = ME_MESSAGE_IDENTIFIER;
|
|
|
|
|
self.automaticallyScrollsToMostRecentMessage = NO;
|
|
|
|
|
|
|
|
|
|
[self initializeToolbars];
|
|
|
|
|
|
|
|
|
@ -935,14 +964,6 @@ typedef enum : NSUInteger {
|
|
|
|
|
[self setBarButtonItemsForDisappearingMessagesConfiguration:configuration];
|
|
|
|
|
[self setNavigationTitle];
|
|
|
|
|
|
|
|
|
|
NSInteger numberOfMessages = (NSInteger)[self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
|
|
|
|
|
if (numberOfMessages > 0) {
|
|
|
|
|
NSIndexPath *lastCellIndexPath = [NSIndexPath indexPathForRow:numberOfMessages - 1 inSection:0];
|
|
|
|
|
[self.collectionView scrollToItemAtIndexPath:lastCellIndexPath
|
|
|
|
|
atScrollPosition:UICollectionViewScrollPositionBottom
|
|
|
|
|
animated:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Other views might change these custom menu items, so we
|
|
|
|
|
// need to set them every time we enter this view.
|
|
|
|
|
SEL saveSelector = NSSelectorFromString(@"save:");
|
|
|
|
@ -961,6 +982,50 @@ typedef enum : NSUInteger {
|
|
|
|
|
[self resetContentAndLayout];
|
|
|
|
|
|
|
|
|
|
[((OWSMessagesToolbarContentView *)self.inputToolbar.contentView)ensureSubviews];
|
|
|
|
|
|
|
|
|
|
[self.collectionView.collectionViewLayout
|
|
|
|
|
invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]];
|
|
|
|
|
|
|
|
|
|
[self.scrollLaterTimer invalidate];
|
|
|
|
|
// We want to scroll to the bottom _after_ the layout has been updated.
|
|
|
|
|
self.scrollLaterTimer = [NSTimer weakScheduledTimerWithTimeInterval:0.001f
|
|
|
|
|
target:self
|
|
|
|
|
selector:@selector(scrollToDefaultPosition)
|
|
|
|
|
userInfo:nil
|
|
|
|
|
repeats:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)clearUnreadMessagesIndicator
|
|
|
|
|
{
|
|
|
|
|
[ThreadUtil clearUnreadMessagesIndicator:self.thread storageManager:self.storageManager];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSIndexPath *_Nullable)indexPathOfUnreadMessagesIndicator
|
|
|
|
|
{
|
|
|
|
|
int numberOfMessages = (int)[self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
|
|
|
|
|
for (int i = 0; i < numberOfMessages; i++) {
|
|
|
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
|
|
|
|
|
id<OWSMessageData> message = [self messageAtIndexPath:indexPath];
|
|
|
|
|
if (message.messageType == TSUnreadIndicatorAdapter) {
|
|
|
|
|
return indexPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)scrollToDefaultPosition
|
|
|
|
|
{
|
|
|
|
|
[self.scrollLaterTimer invalidate];
|
|
|
|
|
self.scrollLaterTimer = nil;
|
|
|
|
|
|
|
|
|
|
NSIndexPath *_Nullable indexPath = [self indexPathOfUnreadMessagesIndicator];
|
|
|
|
|
if (indexPath) {
|
|
|
|
|
[self.collectionView scrollToItemAtIndexPath:indexPath
|
|
|
|
|
atScrollPosition:UICollectionViewScrollPositionTop
|
|
|
|
|
animated:NO];
|
|
|
|
|
} else {
|
|
|
|
|
[self scrollToBottomAnimated:NO];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)resetContentAndLayout
|
|
|
|
@ -1556,6 +1621,8 @@ typedef enum : NSUInteger {
|
|
|
|
|
[ThreadUtil sendMessageWithText:text inThread:self.thread messageSender:self.messageSender];
|
|
|
|
|
}
|
|
|
|
|
self.lastMessageSentDate = [NSDate new];
|
|
|
|
|
[self clearUnreadMessagesIndicator];
|
|
|
|
|
|
|
|
|
|
if (updateKeyboardState)
|
|
|
|
|
{
|
|
|
|
|
[self toggleDefaultKeyboard];
|
|
|
|
@ -2314,6 +2381,8 @@ typedef enum : NSUInteger {
|
|
|
|
|
self.page++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self.scrollLaterTimer invalidate];
|
|
|
|
|
self.scrollLaterTimer = nil;
|
|
|
|
|
NSInteger item = (NSInteger)[self scrollToItem];
|
|
|
|
|
|
|
|
|
|
[self updateRangeOptionsForPage:self.page];
|
|
|
|
@ -2366,6 +2435,8 @@ typedef enum : NSUInteger {
|
|
|
|
|
invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]];
|
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
|
|
|
|
|
|
[self.scrollLaterTimer invalidate];
|
|
|
|
|
self.scrollLaterTimer = nil;
|
|
|
|
|
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:offset inSection:0]
|
|
|
|
|
atScrollPosition:UICollectionViewScrollPositionTop
|
|
|
|
|
animated:NO];
|
|
|
|
@ -2899,6 +2970,7 @@ typedef enum : NSUInteger {
|
|
|
|
|
[attachment mimeType]);
|
|
|
|
|
[ThreadUtil sendMessageWithAttachment:attachment inThread:self.thread messageSender:self.messageSender];
|
|
|
|
|
self.lastMessageSentDate = [NSDate new];
|
|
|
|
|
[self clearUnreadMessagesIndicator];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSURL *)videoTempFolder {
|
|
|
|
@ -3022,11 +3094,7 @@ typedef enum : NSUInteger {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CGFloat kIsAtBottomTolerancePts = 5;
|
|
|
|
|
BOOL wasAtBottom = (self.collectionView.contentOffset.y +
|
|
|
|
|
self.collectionView.bounds.size.height +
|
|
|
|
|
kIsAtBottomTolerancePts >=
|
|
|
|
|
self.collectionView.contentSize.height);
|
|
|
|
|
BOOL wasAtBottom = [self isScrolledToBottom];
|
|
|
|
|
// We want sending messages to feel snappy. So, if the only
|
|
|
|
|
// update is a new outgoing message AND we're already scrolled to
|
|
|
|
|
// the bottom of the conversation, skip the scroll animation.
|
|
|
|
@ -3052,11 +3120,11 @@ typedef enum : NSUInteger {
|
|
|
|
|
}
|
|
|
|
|
case YapDatabaseViewChangeInsert: {
|
|
|
|
|
[self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]];
|
|
|
|
|
scrollToBottom = YES;
|
|
|
|
|
|
|
|
|
|
TSInteraction *interaction = [self interactionAtIndexPath:rowChange.newIndexPath];
|
|
|
|
|
if (![interaction isKindOfClass:[TSOutgoingMessage class]]) {
|
|
|
|
|
shouldAnimateScrollToBottom = YES;
|
|
|
|
|
if ([interaction isKindOfClass:[TSOutgoingMessage class]]) {
|
|
|
|
|
scrollToBottom = YES;
|
|
|
|
|
shouldAnimateScrollToBottom = NO;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -3083,11 +3151,20 @@ typedef enum : NSUInteger {
|
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
|
}
|
|
|
|
|
if (scrollToBottom) {
|
|
|
|
|
[self.scrollLaterTimer invalidate];
|
|
|
|
|
self.scrollLaterTimer = nil;
|
|
|
|
|
[self scrollToBottomAnimated:shouldAnimateScrollToBottom];
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)isScrolledToBottom
|
|
|
|
|
{
|
|
|
|
|
const CGFloat kIsAtBottomTolerancePts = 5;
|
|
|
|
|
return (self.collectionView.contentOffset.y + self.collectionView.bounds.size.height + kIsAtBottomTolerancePts
|
|
|
|
|
>= self.collectionView.contentSize.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - UICollectionView DataSource
|
|
|
|
|
|
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
|
|
@ -3608,6 +3685,32 @@ typedef enum : NSUInteger {
|
|
|
|
|
completion:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)textViewDidChangeSize
|
|
|
|
|
{
|
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
|
|
BOOL wasAtBottom = [self isScrolledToBottom];
|
|
|
|
|
if (wasAtBottom) {
|
|
|
|
|
[self.scrollLaterTimer invalidate];
|
|
|
|
|
// We want to scroll to the bottom _after_ the layout has been updated.
|
|
|
|
|
self.scrollLaterTimer = [NSTimer weakScheduledTimerWithTimeInterval:0.001f
|
|
|
|
|
target:self
|
|
|
|
|
selector:@selector(scrollToBottomImmediately)
|
|
|
|
|
userInfo:nil
|
|
|
|
|
repeats:NO];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)scrollToBottomImmediately
|
|
|
|
|
{
|
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
|
|
[self.scrollLaterTimer invalidate];
|
|
|
|
|
self.scrollLaterTimer = nil;
|
|
|
|
|
|
|
|
|
|
[self scrollToBottomAnimated:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - OWSMessagesToolbarContentDelegate
|
|
|
|
|
|
|
|
|
|
- (void)voiceMemoGestureDidStart
|
|
|
|
|