From 7773e9a2809018766133a1d8f80b5a103b878787 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 31 Aug 2020 16:15:57 +1000 Subject: [PATCH] fix bugs for open group time handling --- .../ConversationView/Cells/OWSMessageFooterView.m | 2 +- .../ConversationView/ConversationViewController.m | 8 ++++---- .../ConversationView/ConversationViewModel.m | 4 ++-- .../src/Messages/Interactions/TSInteraction.h | 3 +++ .../src/Messages/Interactions/TSInteraction.m | 10 ++++------ 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m index d63a8baa8..09782265d 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m @@ -195,7 +195,7 @@ NS_ASSUME_NONNULL_BEGIN timestampLabelText = NSLocalizedString(@"MESSAGE_STATUS_SEND_FAILED", @"Label indicating that a message failed to send."); } else { - timestampLabelText = [DateUtil formatMessageTimestamp:viewItem.interaction.timestamp]; + timestampLabelText = [DateUtil formatMessageTimestamp:viewItem.interaction.timestampForUI]; } TSMessage *message = [viewItem.interaction as:TSMessage.class]; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 96f84c3ff..1d8a91499 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -4683,7 +4683,7 @@ typedef enum : NSUInteger { OWSAssertDebug(left <= mid); OWSAssertDebug(mid < right); id viewItem = self.viewItems[mid]; - if (viewItem.interaction.timestamp >= viewHorizonTimestamp) { + if (viewItem.interaction.timestampForUI >= viewHorizonTimestamp) { right = mid; } else { // This is an optimization; it also ensures that we converge. @@ -4692,7 +4692,7 @@ typedef enum : NSUInteger { } OWSAssertDebug(left == right); id viewItem = self.viewItems[left]; - if (viewItem.interaction.timestamp >= viewHorizonTimestamp) { + if (viewItem.interaction.timestampForUI >= viewHorizonTimestamp) { OWSLogInfo(@"firstIndexPathAtViewHorizonTimestamp: %zd / %zd", left, self.viewItems.count); return [NSIndexPath indexPathForRow:(NSInteger) left inSection:0]; } else { @@ -5402,7 +5402,7 @@ typedef enum : NSUInteger { __block TSInteraction *targetInteraction; [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.thread enumerateInteractionsWithTransaction:transaction usingBlock:^(TSInteraction *interaction, YapDatabaseReadTransaction *t) { - if (interaction.timestamp == timestamp.unsignedLongLongValue) { + if (interaction.timestampForUI == timestamp.unsignedLongLongValue) { targetInteraction = interaction; } }]; @@ -5426,7 +5426,7 @@ typedef enum : NSUInteger { { __block TSInteraction *targetInteraction; [self.thread enumerateInteractionsUsingBlock:^(TSInteraction *interaction) { - if (interaction.timestamp == timestamp.unsignedLongLongValue) { + if (interaction.timestampForUI == timestamp.unsignedLongLongValue) { targetInteraction = interaction; } }]; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m b/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m index 693392413..1b438a869 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m @@ -1350,7 +1350,7 @@ static const int kYapDatabaseRangeMaxLength = 25000; break; } - uint64_t viewItemTimestamp = viewItem.interaction.timestamp; + uint64_t viewItemTimestamp = viewItem.interaction.timestampForUI; OWSAssertDebug(viewItemTimestamp > 0); BOOL shouldShowDate = NO; @@ -1417,7 +1417,7 @@ static const int kYapDatabaseRangeMaxLength = 25000; NSAttributedString *_Nullable senderName = nil; OWSInteractionType interactionType = viewItem.interaction.interactionType; - NSString *timestampText = [DateUtil formatTimestampShort:viewItem.interaction.timestamp]; + NSString *timestampText = [DateUtil formatTimestampShort:viewItem.interaction.timestampForUI]; if (interactionType == OWSInteractionType_OutgoingMessage) { TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction; diff --git a/SignalServiceKit/src/Messages/Interactions/TSInteraction.h b/SignalServiceKit/src/Messages/Interactions/TSInteraction.h index b53c71b17..2d230db56 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSInteraction.h +++ b/SignalServiceKit/src/Messages/Interactions/TSInteraction.h @@ -39,11 +39,14 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value); @property (nonatomic, readonly) uint64_t timestamp; @property (nonatomic, readonly) uint64_t sortId; @property (nonatomic, readonly) uint64_t receivedAtTimestamp; +@property (nonatomic, readonly) BOOL shouldUseServerTime; /// Used for public chats where a message sent from a slave device is interpreted as having been sent from the master device. @property (nonatomic) NSString *actualSenderHexEncodedPublicKey; - (void)setServerTimestampToReceivedTimestamp:(uint64_t)receivedAtTimestamp; +- (uint64_t)timestampForUI; + - (NSDate *)receivedAtDate; - (OWSInteractionType)interactionType; diff --git a/SignalServiceKit/src/Messages/Interactions/TSInteraction.m b/SignalServiceKit/src/Messages/Interactions/TSInteraction.m index 502c55d35..2d818d150 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSInteraction.m +++ b/SignalServiceKit/src/Messages/Interactions/TSInteraction.m @@ -177,13 +177,10 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) #pragma mark Date operations -- (uint64_t)timestamp +- (uint64_t)timestampForUI { - if (self.thread.isGroupThread) { - TSGroupThread *thread = (TSGroupThread *)self.thread; - if (thread.isPublicChat) { - return _receivedAtTimestamp; - } + if (_shouldUseServerTime) { + return _receivedAtTimestamp; } return _timestamp; } @@ -195,6 +192,7 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (void)setServerTimestampToReceivedTimestamp:(uint64_t)receivedAtTimestamp { + _shouldUseServerTime = YES; _receivedAtTimestamp = receivedAtTimestamp; }