Respond to CR.

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

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

@ -121,13 +121,6 @@ extern NSString *const TSIncomingMessageWasReadOnThisDeviceNotification;
@property (nonatomic, readonly) NSString *authorId;
@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).

@ -135,18 +135,6 @@ NSString *const TSIncomingMessageWasReadOnThisDeviceNotification = @"TSIncomingM
[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
+ (NSString *)tag

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

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

@ -31,7 +31,7 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
@property (nonatomic, readonly) BOOL isExpiringMessage;
@property (nonatomic, readonly) BOOL shouldStartExpireTimer;
// _DO NOT_ access this property directly. You almost certainly
// want to use bestReceivedAtDate instead.
// want to use receiptDateForSorting instead.
@property (nonatomic, readonly) NSDate *receivedAtDate;
- (instancetype)initWithTimestamp:(uint64_t)timestamp;
@ -64,11 +64,6 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
- (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
NS_ASSUME_NONNULL_END

@ -132,10 +132,13 @@ static const NSUInteger OWSMessageSchemaVersion = 3;
_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
// set the receivedAt time for old messages in the data store.
_schemaVersion = OWSMessageSchemaVersion;
return self;
}
@ -220,9 +223,22 @@ static const NSUInteger OWSMessageSchemaVersion = 3;
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

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

Loading…
Cancel
Save