fix bugs for open group time handling

pull/258/head
Ryan ZHAO 5 years ago
parent 1b621fc56d
commit 7773e9a280

@ -195,7 +195,7 @@ NS_ASSUME_NONNULL_BEGIN
timestampLabelText timestampLabelText
= NSLocalizedString(@"MESSAGE_STATUS_SEND_FAILED", @"Label indicating that a message failed to send."); = NSLocalizedString(@"MESSAGE_STATUS_SEND_FAILED", @"Label indicating that a message failed to send.");
} else { } else {
timestampLabelText = [DateUtil formatMessageTimestamp:viewItem.interaction.timestamp]; timestampLabelText = [DateUtil formatMessageTimestamp:viewItem.interaction.timestampForUI];
} }
TSMessage *message = [viewItem.interaction as:TSMessage.class]; TSMessage *message = [viewItem.interaction as:TSMessage.class];

@ -4683,7 +4683,7 @@ typedef enum : NSUInteger {
OWSAssertDebug(left <= mid); OWSAssertDebug(left <= mid);
OWSAssertDebug(mid < right); OWSAssertDebug(mid < right);
id<ConversationViewItem> viewItem = self.viewItems[mid]; id<ConversationViewItem> viewItem = self.viewItems[mid];
if (viewItem.interaction.timestamp >= viewHorizonTimestamp) { if (viewItem.interaction.timestampForUI >= viewHorizonTimestamp) {
right = mid; right = mid;
} else { } else {
// This is an optimization; it also ensures that we converge. // This is an optimization; it also ensures that we converge.
@ -4692,7 +4692,7 @@ typedef enum : NSUInteger {
} }
OWSAssertDebug(left == right); OWSAssertDebug(left == right);
id<ConversationViewItem> viewItem = self.viewItems[left]; id<ConversationViewItem> viewItem = self.viewItems[left];
if (viewItem.interaction.timestamp >= viewHorizonTimestamp) { if (viewItem.interaction.timestampForUI >= viewHorizonTimestamp) {
OWSLogInfo(@"firstIndexPathAtViewHorizonTimestamp: %zd / %zd", left, self.viewItems.count); OWSLogInfo(@"firstIndexPathAtViewHorizonTimestamp: %zd / %zd", left, self.viewItems.count);
return [NSIndexPath indexPathForRow:(NSInteger) left inSection:0]; return [NSIndexPath indexPathForRow:(NSInteger) left inSection:0];
} else { } else {
@ -5402,7 +5402,7 @@ typedef enum : NSUInteger {
__block TSInteraction *targetInteraction; __block TSInteraction *targetInteraction;
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self.thread enumerateInteractionsWithTransaction:transaction usingBlock:^(TSInteraction *interaction, YapDatabaseReadTransaction *t) { [self.thread enumerateInteractionsWithTransaction:transaction usingBlock:^(TSInteraction *interaction, YapDatabaseReadTransaction *t) {
if (interaction.timestamp == timestamp.unsignedLongLongValue) { if (interaction.timestampForUI == timestamp.unsignedLongLongValue) {
targetInteraction = interaction; targetInteraction = interaction;
} }
}]; }];
@ -5426,7 +5426,7 @@ typedef enum : NSUInteger {
{ {
__block TSInteraction *targetInteraction; __block TSInteraction *targetInteraction;
[self.thread enumerateInteractionsUsingBlock:^(TSInteraction *interaction) { [self.thread enumerateInteractionsUsingBlock:^(TSInteraction *interaction) {
if (interaction.timestamp == timestamp.unsignedLongLongValue) { if (interaction.timestampForUI == timestamp.unsignedLongLongValue) {
targetInteraction = interaction; targetInteraction = interaction;
} }
}]; }];

@ -1350,7 +1350,7 @@ static const int kYapDatabaseRangeMaxLength = 25000;
break; break;
} }
uint64_t viewItemTimestamp = viewItem.interaction.timestamp; uint64_t viewItemTimestamp = viewItem.interaction.timestampForUI;
OWSAssertDebug(viewItemTimestamp > 0); OWSAssertDebug(viewItemTimestamp > 0);
BOOL shouldShowDate = NO; BOOL shouldShowDate = NO;
@ -1417,7 +1417,7 @@ static const int kYapDatabaseRangeMaxLength = 25000;
NSAttributedString *_Nullable senderName = nil; NSAttributedString *_Nullable senderName = nil;
OWSInteractionType interactionType = viewItem.interaction.interactionType; OWSInteractionType interactionType = viewItem.interaction.interactionType;
NSString *timestampText = [DateUtil formatTimestampShort:viewItem.interaction.timestamp]; NSString *timestampText = [DateUtil formatTimestampShort:viewItem.interaction.timestampForUI];
if (interactionType == OWSInteractionType_OutgoingMessage) { if (interactionType == OWSInteractionType_OutgoingMessage) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction; TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction;

@ -39,11 +39,14 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value);
@property (nonatomic, readonly) uint64_t timestamp; @property (nonatomic, readonly) uint64_t timestamp;
@property (nonatomic, readonly) uint64_t sortId; @property (nonatomic, readonly) uint64_t sortId;
@property (nonatomic, readonly) uint64_t receivedAtTimestamp; @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. /// 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; @property (nonatomic) NSString *actualSenderHexEncodedPublicKey;
- (void)setServerTimestampToReceivedTimestamp:(uint64_t)receivedAtTimestamp; - (void)setServerTimestampToReceivedTimestamp:(uint64_t)receivedAtTimestamp;
- (uint64_t)timestampForUI;
- (NSDate *)receivedAtDate; - (NSDate *)receivedAtDate;
- (OWSInteractionType)interactionType; - (OWSInteractionType)interactionType;

@ -177,13 +177,10 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
#pragma mark Date operations #pragma mark Date operations
- (uint64_t)timestamp - (uint64_t)timestampForUI
{ {
if (self.thread.isGroupThread) { if (_shouldUseServerTime) {
TSGroupThread *thread = (TSGroupThread *)self.thread; return _receivedAtTimestamp;
if (thread.isPublicChat) {
return _receivedAtTimestamp;
}
} }
return _timestamp; return _timestamp;
} }
@ -195,6 +192,7 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
- (void)setServerTimestampToReceivedTimestamp:(uint64_t)receivedAtTimestamp - (void)setServerTimestampToReceivedTimestamp:(uint64_t)receivedAtTimestamp
{ {
_shouldUseServerTime = YES;
_receivedAtTimestamp = receivedAtTimestamp; _receivedAtTimestamp = receivedAtTimestamp;
} }

Loading…
Cancel
Save