From 48121e5eaca3447819f8c19bd94b890df411e7b9 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 5 Sep 2017 12:45:21 -0400 Subject: [PATCH 1/2] Don't "scroll to bottom" when messages are sent from desktop. // FREEBIE --- .../ConversationViewController.m | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 61d690744..8fca94639 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1704,6 +1704,13 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { } } +- (void)finishSendingMessageAnimated:(BOOL)animated +{ + [super finishSendingMessageAnimated:animated]; + + [self scrollToBottomAnimated:animated]; +} + - (void)toggleDefaultKeyboard { // Primary language is nil for the emoji keyboard & we want to stay on it after sending @@ -3584,17 +3591,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { 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:^{ for (YapDatabaseViewRowChange *rowChange in messageRowChanges) { switch (rowChange.type) { @@ -3611,12 +3607,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { } case YapDatabaseViewChangeInsert: { [self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]]; - - TSInteraction *interaction = [self interactionAtIndexPath:rowChange.newIndexPath]; - if ([interaction isKindOfClass:[TSOutgoingMessage class]]) { - scrollToBottom = YES; - shouldAnimateScrollToBottom = NO; - } break; } case YapDatabaseViewChangeMove: { @@ -3642,10 +3632,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { } [self updateLastVisibleTimestamp]; - - if (scrollToBottom) { - [self scrollToBottomAnimated:shouldAnimateScrollToBottom]; - } }]; } From 05b18188749abb47bdbb93850036f0c78fc4fa6a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 6 Sep 2017 10:22:25 -0400 Subject: [PATCH 2/2] Don't "scroll to bottom" when messages are sent from desktop. // FREEBIE --- .../ConversationViewController.m | 31 ++++++++++++++----- .../Messages/Interactions/TSOutgoingMessage.h | 4 +++ .../Messages/Interactions/TSOutgoingMessage.m | 13 ++++++++ .../src/Messages/OWSMessageSender.m | 2 +- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 8fca94639..8b2e39716 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1704,13 +1704,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { } } -- (void)finishSendingMessageAnimated:(BOOL)animated -{ - [super finishSendingMessageAnimated:animated]; - - [self scrollToBottomAnimated:animated]; -} - - (void)toggleDefaultKeyboard { // 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; } + 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:^{ for (YapDatabaseViewRowChange *rowChange in messageRowChanges) { switch (rowChange.type) { @@ -3607,6 +3611,15 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { } case YapDatabaseViewChangeInsert: { [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; } case YapDatabaseViewChangeMove: { @@ -3632,6 +3645,10 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { } [self updateLastVisibleTimestamp]; + + if (scrollToBottom) { + [self scrollToBottomAnimated:shouldAnimateScrollToBottom]; + } }]; } diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h index ee1c870ed..ce38af07e 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h @@ -101,6 +101,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) { @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. */ @@ -168,6 +171,7 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) { - (void)updateWithWasDeliveredWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)updateWithWasDelivered; - (void)updateWithWasSentAndDelivered; +- (void)updateWithWasSentAndDeliveredFromLinkedDevice; - (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient transaction:(YapDatabaseReadWriteTransaction *)transaction; diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m index 9149e9ede..61a1a8139 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m @@ -28,6 +28,7 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec @property (atomic) NSString *mostRecentFailureText; @property (atomic) BOOL wasDelivered; @property (atomic) NSString *singleGroupRecipient; +@property (atomic) BOOL isFromLinkedDevice; // For outgoing, non-legacy group messages sent from this client, this // 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 transaction:(YapDatabaseReadWriteTransaction *)transaction { diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index b5f3a9f32..f0547cf03 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -1084,7 +1084,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; - (void)handleMessageSentRemotely:(TSOutgoingMessage *)message sentAt:(uint64_t)sentAt { - [message updateWithWasSentAndDelivered]; + [message updateWithWasSentAndDeliveredFromLinkedDevice]; [self becomeConsistentWithDisappearingConfigurationForMessage:message]; [OWSDisappearingMessagesJob setExpirationForMessage:message expirationStartedAt:sentAt]; }