Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent 7bd4d26532
commit 686fe679bd

@ -246,14 +246,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
- (void)updateWithLastMessage:(TSInteraction *)lastMessage transaction:(YapDatabaseReadWriteTransaction *)transaction { - (void)updateWithLastMessage:(TSInteraction *)lastMessage transaction:(YapDatabaseReadWriteTransaction *)transaction {
NSDate *lastMessageDate = lastMessage.date; NSDate *lastMessageDate = [lastMessage receiptDateForSorting];
if ([lastMessage isKindOfClass:[TSMessage class]]) {
TSMessage *message = (TSMessage *)lastMessage;
if ([message bestReceivedAtDate]) {
lastMessageDate = [message bestReceivedAtDate];
}
}
if (!_lastMessageDate || [lastMessageDate timeIntervalSinceDate:self.lastMessageDate] > 0) { if (!_lastMessageDate || [lastMessageDate timeIntervalSinceDate:self.lastMessageDate] > 0) {
_lastMessageDate = lastMessageDate; _lastMessageDate = lastMessageDate;

@ -121,13 +121,6 @@ extern NSString *const TSIncomingMessageWasReadOnThisDeviceNotification;
@property (nonatomic, readonly) NSString *authorId; @property (nonatomic, readonly) NSString *authorId;
@property (nonatomic, readonly, getter=wasRead) BOOL read; @property (nonatomic, readonly, getter=wasRead) BOOL read;
// _DO NOT_ access this property directly. You almost certainly
// want to use bestReceivedAtDate instead.
//
// This property has been superceded by TSMessage.receivedAtData.
// This property only exists for backwards compatability with messages
// received before TSMessage.receivedAtData was added.
@property (nonatomic, readonly) NSDate *receivedAt;
/* /*
* Marks a message as having been read on this device (as opposed to responding to a remote read receipt). * Marks a message as having been read on this device (as opposed to responding to a remote read receipt).

@ -135,18 +135,6 @@ NSString *const TSIncomingMessageWasReadOnThisDeviceNotification = @"TSIncomingM
[self touchThreadWithTransaction:transaction]; [self touchThreadWithTransaction:transaction];
} }
- (nullable NSDate *)bestReceivedAtDate
{
NSDate *result = [super bestReceivedAtDate];
if (!result) {
// For backward compatibility with messages received before
// TSMessage.receivedAtData was added, honor TSIncomingMessage.receivedAt
// if TSMessage.receivedAtData is not set.
result = self.receivedAt;
}
return result;
}
#pragma mark - Logging #pragma mark - Logging
+ (NSString *)tag + (NSString *)tag

@ -31,5 +31,6 @@
+ (instancetype)interactionForTimestamp:(uint64_t)timestamp + (instancetype)interactionForTimestamp:(uint64_t)timestamp
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
- (nullable NSDate *)receiptDateForSorting;
@end @end

@ -86,6 +86,11 @@
return [myNumber unsignedLongLongValue]; return [myNumber unsignedLongLongValue];
} }
- (nullable NSDate *)receiptDateForSorting
{
return self.date;
}
- (NSString *)description { - (NSString *)description {
return @"Interaction description"; return @"Interaction description";
} }

@ -31,7 +31,7 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
@property (nonatomic, readonly) BOOL isExpiringMessage; @property (nonatomic, readonly) BOOL isExpiringMessage;
@property (nonatomic, readonly) BOOL shouldStartExpireTimer; @property (nonatomic, readonly) BOOL shouldStartExpireTimer;
// _DO NOT_ access this property directly. You almost certainly // _DO NOT_ access this property directly. You almost certainly
// want to use bestReceivedAtDate instead. // want to use receiptDateForSorting instead.
@property (nonatomic, readonly) NSDate *receivedAtDate; @property (nonatomic, readonly) NSDate *receivedAtDate;
- (instancetype)initWithTimestamp:(uint64_t)timestamp; - (instancetype)initWithTimestamp:(uint64_t)timestamp;
@ -64,11 +64,6 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
- (BOOL)hasAttachments; - (BOOL)hasAttachments;
// This message should return TSMessage.receivedAtDate for most messages.
// For messages received before TSMessage.receivedAtDate was added, this
// will try to return TSIncomingMessage.receivedAt.
- (nullable NSDate *)bestReceivedAtDate;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -132,10 +132,13 @@ static const NSUInteger OWSMessageSchemaVersion = 3;
_attachmentIds = [NSMutableArray new]; _attachmentIds = [NSMutableArray new];
} }
_schemaVersion = OWSMessageSchemaVersion; if (!_receivedAtDate) {
// TSIncomingMessage.receivedAt has been superceded by TSMessage.receivedAtDate.
NSDate *receivedAt = [coder decodeObjectForKey:@"receivedAt"];
_receivedAtDate = receivedAt;
}
// We _DO NOT_ set _receivedAt_ in this constructor. We don't want to _schemaVersion = OWSMessageSchemaVersion;
// set the receivedAt time for old messages in the data store.
return self; return self;
} }
@ -220,9 +223,22 @@ static const NSUInteger OWSMessageSchemaVersion = 3;
return self.expiresInSeconds > 0; return self.expiresInSeconds > 0;
} }
- (nullable NSDate *)bestReceivedAtDate - (nullable NSDate *)receiptDateForSorting
{
// Prefer receivedAtDate if set, otherwise fallback to date.
return self.receivedAtDate ?: self.date;
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{ {
return self.receivedAtDate; return self.class.tag;
} }
@end @end

@ -264,16 +264,7 @@ NSString *TSSecondaryDevicesDatabaseViewExtensionName = @"TSSecondaryDevicesData
} }
+ (NSDate *)localTimeReceiveDateForInteraction:(TSInteraction *)interaction { + (NSDate *)localTimeReceiveDateForInteraction:(TSInteraction *)interaction {
NSDate *interactionDate = interaction.date; return [interaction receiptDateForSorting];
if ([interaction isKindOfClass:[TSMessage class]]) {
TSMessage *message = (TSMessage *)interaction;
if ([message bestReceivedAtDate]) {
interactionDate = [message bestReceivedAtDate];
}
}
return interactionDate;
} }
#pragma mark - Logging #pragma mark - Logging

Loading…
Cancel
Save