Merge branch 'feature/messageSortingRevisited'

pull/1/head
Matthew Chen 8 years ago
commit 427f225df9

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

@ -121,7 +121,6 @@ extern NSString *const TSIncomingMessageWasReadOnThisDeviceNotification;
@property (nonatomic, readonly) NSString *authorId;
@property (nonatomic, readonly, getter=wasRead) BOOL read;
@property (nonatomic, readonly) NSDate *receivedAt;
/*
* Marks a message as having been read on this device (as opposed to responding to a remote read receipt).

@ -61,7 +61,8 @@ NSString *const TSIncomingMessageWasReadOnThisDeviceNotification = @"TSIncomingM
_authorId = authorId;
_read = NO;
_receivedAt = [NSDate date];
OWSAssert(self.receivedAtDate);
return self;
}

@ -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";
}

@ -1,5 +1,6 @@
// Created by Frederic Jacobs on 12/11/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSInteraction.h"
@ -29,6 +30,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
@property (nonatomic, readonly) uint64_t expiresAt;
@property (nonatomic, readonly) BOOL isExpiringMessage;
@property (nonatomic, readonly) BOOL shouldStartExpireTimer;
// _DO NOT_ access this property directly. You almost certainly
// want to use receiptDateForSorting instead.
@property (nonatomic, readonly) NSDate *receivedAtDate;
- (instancetype)initWithTimestamp:(uint64_t)timestamp;

@ -102,6 +102,7 @@ static const NSUInteger OWSMessageSchemaVersion = 3;
_expiresInSeconds = expiresInSeconds;
_expireStartedAt = expireStartedAt;
[self updateExpiresAt];
_receivedAtDate = [NSDate date];
return self;
}
@ -131,7 +132,14 @@ static const NSUInteger OWSMessageSchemaVersion = 3;
_attachmentIds = [NSMutableArray new];
}
if (!_receivedAtDate) {
// TSIncomingMessage.receivedAt has been superceded by TSMessage.receivedAtDate.
NSDate *receivedAt = [coder decodeObjectForKey:@"receivedAt"];
_receivedAtDate = receivedAt;
}
_schemaVersion = OWSMessageSchemaVersion;
return self;
}
@ -215,6 +223,24 @@ static const NSUInteger OWSMessageSchemaVersion = 3;
return self.expiresInSeconds > 0;
}
- (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.class.tag;
}
@end
NS_ASSUME_NONNULL_END

@ -1,5 +1,6 @@
// Created by Frederic Jacobs on 15/11/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSMessage.h"

@ -1,5 +1,6 @@
// Created by Frederic Jacobs on 15/11/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSOutgoingMessage.h"
#import "NSDate+millisecondTimeStamp.h"
@ -86,6 +87,8 @@ NS_ASSUME_NONNULL_BEGIN
self.groupMetaMessage = TSGroupMessageNone;
}
OWSAssert(self.receivedAtDate);
return self;
}

@ -9,6 +9,7 @@
#import "OWSDevice.h"
#import "OWSReadTracking.h"
#import "TSIncomingMessage.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager.h"
#import "TSThread.h"
@ -263,17 +264,7 @@ NSString *TSSecondaryDevicesDatabaseViewExtensionName = @"TSSecondaryDevicesData
}
+ (NSDate *)localTimeReceiveDateForInteraction:(TSInteraction *)interaction {
NSDate *interactionDate = interaction.date;
if ([interaction isKindOfClass:[TSIncomingMessage class]]) {
TSIncomingMessage *message = (TSIncomingMessage *)interaction;
if (message.receivedAt) {
interactionDate = message.receivedAt;
}
}
return interactionDate;
return [interaction receiptDateForSorting];
}
#pragma mark - Logging

Loading…
Cancel
Save