Don't "scroll to bottom" when messages are sent from desktop.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 48121e5eac
commit 05b1818874

@ -1704,13 +1704,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
} }
} }
- (void)finishSendingMessageAnimated:(BOOL)animated
{
[super finishSendingMessageAnimated:animated];
[self scrollToBottomAnimated:animated];
}
- (void)toggleDefaultKeyboard - (void)toggleDefaultKeyboard
{ {
// Primary language is nil for the emoji keyboard & we want to stay on it after sending // Primary language is nil for the emoji keyboard & we want to stay on it after sending
@ -3591,6 +3584,17 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
return; return;
} }
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.
__block BOOL shouldAnimateScrollToBottom = !wasAtBottom;
// We want to scroll to the bottom if the user:
//
// a) already was at the bottom of the conversation.
// b) is inserting new interactions.
__block BOOL scrollToBottom = wasAtBottom;
[self.collectionView performBatchUpdates:^{ [self.collectionView performBatchUpdates:^{
for (YapDatabaseViewRowChange *rowChange in messageRowChanges) { for (YapDatabaseViewRowChange *rowChange in messageRowChanges) {
switch (rowChange.type) { switch (rowChange.type) {
@ -3607,6 +3611,15 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
} }
case YapDatabaseViewChangeInsert: { case YapDatabaseViewChangeInsert: {
[self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]]; [self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]];
TSInteraction *interaction = [self interactionAtIndexPath:rowChange.newIndexPath];
if ([interaction isKindOfClass:[TSOutgoingMessage class]]) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)interaction;
if (!outgoingMessage.isFromLinkedDevice) {
scrollToBottom = YES;
shouldAnimateScrollToBottom = NO;
}
}
break; break;
} }
case YapDatabaseViewChangeMove: { case YapDatabaseViewChangeMove: {
@ -3632,6 +3645,10 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
} }
[self updateLastVisibleTimestamp]; [self updateLastVisibleTimestamp];
if (scrollToBottom) {
[self scrollToBottomAnimated:shouldAnimateScrollToBottom];
}
}]; }];
} }

@ -101,6 +101,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
@property (nonatomic, readonly) BOOL isVoiceMessage; @property (nonatomic, readonly) BOOL isVoiceMessage;
// This property won't be accurate for legacy messages.
@property (atomic, readonly) BOOL isFromLinkedDevice;
/** /**
* Signal Identifier (e.g. e164 number) or nil if in a group thread. * Signal Identifier (e.g. e164 number) or nil if in a group thread.
*/ */
@ -168,6 +171,7 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
- (void)updateWithWasDeliveredWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)updateWithWasDeliveredWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateWithWasDelivered; - (void)updateWithWasDelivered;
- (void)updateWithWasSentAndDelivered; - (void)updateWithWasSentAndDelivered;
- (void)updateWithWasSentAndDeliveredFromLinkedDevice;
- (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient - (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;

@ -28,6 +28,7 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
@property (atomic) NSString *mostRecentFailureText; @property (atomic) NSString *mostRecentFailureText;
@property (atomic) BOOL wasDelivered; @property (atomic) BOOL wasDelivered;
@property (atomic) NSString *singleGroupRecipient; @property (atomic) NSString *singleGroupRecipient;
@property (atomic) BOOL isFromLinkedDevice;
// For outgoing, non-legacy group messages sent from this client, this // For outgoing, non-legacy group messages sent from this client, this
// contains the list of recipients to whom the message has been sent. // contains the list of recipients to whom the message has been sent.
@ -333,6 +334,18 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
}]; }];
} }
- (void)updateWithWasSentAndDeliveredFromLinkedDevice
{
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self applyChangeToSelfAndLatestOutgoingMessage:transaction
changeBlock:^(TSOutgoingMessage *message) {
[message setMessageState:TSOutgoingMessageStateSentToService];
[message setWasDelivered:YES];
[message setIsFromLinkedDevice:YES];
}];
}];
}
- (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient - (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {

@ -1084,7 +1084,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
- (void)handleMessageSentRemotely:(TSOutgoingMessage *)message sentAt:(uint64_t)sentAt - (void)handleMessageSentRemotely:(TSOutgoingMessage *)message sentAt:(uint64_t)sentAt
{ {
[message updateWithWasSentAndDelivered]; [message updateWithWasSentAndDeliveredFromLinkedDevice];
[self becomeConsistentWithDisappearingConfigurationForMessage:message]; [self becomeConsistentWithDisappearingConfigurationForMessage:message];
[OWSDisappearingMessagesJob setExpirationForMessage:message expirationStartedAt:sentAt]; [OWSDisappearingMessagesJob setExpirationForMessage:message expirationStartedAt:sentAt];
} }

Loading…
Cancel
Save