Fixing UX issue with unsynchronized clocks.

TextSecure messages don’t get assigned a timestamp by the server. All
of it is done end-to-end between both clients. A client could have a
misconfigured clock or might want to forge a timestamp. Therefore, we
address this issue by introducing a new receivedAt timestamp for
incoming messages that will be used to sort the messages.
pull/1/head
Frederic Jacobs 10 years ago
parent 456d1c479a
commit 7aad5c5971

@ -42,9 +42,10 @@
inThread:(TSGroupThread*)thread
authorId:(NSString*)authorId
messageBody:(NSString*)body
attachments:(NSArray*)attachments;
attachments:(NSArray*)attachments;
@property (nonatomic, readonly) NSString *authorId;
@property (nonatomic, getter = wasRead) BOOL read;
@property (nonatomic, readonly) NSDate *receivedAt;
@end

@ -19,8 +19,9 @@
self = [super initWithTimestamp:timestamp inThread:thread messageBody:body attachments:attachments];
if (self) {
_authorId = authorId;
_read = NO;
_authorId = authorId;
_read = NO;
_receivedAt = [NSDate date];
}
return self;
@ -34,8 +35,9 @@
self = [super initWithTimestamp:timestamp inThread:thread messageBody:body attachments:attachments];
if (self) {
_authorId = nil;
_read = NO;
_authorId = nil;
_read = NO;
_receivedAt = [NSDate date];
}
return self;

@ -163,11 +163,42 @@ NSString *TSUnreadDatabaseViewExtensionName = @"TSUnreadDatabaseViewExtensionNa
TSInteraction *message1 = (TSInteraction*)object1;
TSInteraction *message2 = (TSInteraction*)object2;
return [message1.date compare:message2.date];
NSDate *date1 = [self localTimeReceiveDateForInteraction:message1];
NSDate *date2 = [self localTimeReceiveDateForInteraction:message2];
NSComparisonResult result = [date1 compare:date2];
// NSDates are only accurate to the second, we might want finer precision
if (result != NSOrderedSame) {
return result;
}
if (message1.timestamp > message2.timestamp) {
return NSOrderedDescending;
} else if (message1.timestamp < message2.timestamp){
return NSOrderedAscending;
} else{
return NSOrderedSame;
}
}
return NSOrderedSame;
}];
}
+ (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;
}
@end

Loading…
Cancel
Save