use sent timestamp instead of received timestamp for sorting and UI

pull/390/head
Ryan ZHAO 4 years ago
parent d360353c17
commit d897952ce0

@ -286,7 +286,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
dateBreakLabel.font = .boldSystemFont(ofSize: Values.verySmallFontSize) dateBreakLabel.font = .boldSystemFont(ofSize: Values.verySmallFontSize)
dateBreakLabel.textColor = Colors.text dateBreakLabel.textColor = Colors.text
dateBreakLabel.textAlignment = .center dateBreakLabel.textAlignment = .center
let date = viewItem.interaction.receivedAtDate() let date = viewItem.interaction.dateForUI()
let description = DateUtil.formatDate(forConversationDateBreaks: date) let description = DateUtil.formatDate(forConversationDateBreaks: date)
dateBreakLabel.text = description dateBreakLabel.text = description
headerView.addSubview(dateBreakLabel) headerView.addSubview(dateBreakLabel)

@ -120,7 +120,7 @@ public struct GalleryDate: Hashable, Comparable, Equatable {
let month: Int let month: Int
init(message: TSMessage) { init(message: TSMessage) {
let date = message.receivedAtDate() let date = message.dateForUI()
self.year = Calendar.current.component(.year, from: date) self.year = Calendar.current.component(.year, from: date)
self.month = Calendar.current.component(.month, from: date) self.month = Calendar.current.component(.month, from: date)

@ -43,6 +43,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value);
- (uint64_t)timestampForUI; - (uint64_t)timestampForUI;
- (NSDate *)dateForUI;
- (NSDate *)receivedAtDate; - (NSDate *)receivedAtDate;
- (OWSInteractionType)interactionType; - (OWSInteractionType)interactionType;

@ -180,8 +180,14 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
return self.timestamp; return self.timestamp;
} }
- (NSDate *)dateForUI
{
return [NSDate ows_dateWithMillisecondsSince1970:self.timestampForUI];
}
- (NSDate *)receivedAtDate - (NSDate *)receivedAtDate
{ {
// This is only used for sorting threads
return [NSDate ows_dateWithMillisecondsSince1970:self.receivedAtTimestamp]; return [NSDate ows_dateWithMillisecondsSince1970:self.receivedAtTimestamp];
} }
@ -222,13 +228,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
- (uint64_t)sortId - (uint64_t)sortId
{ {
if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) { if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage && ((TSIncomingMessage *) self).serverTimestamp != nil) {
if (((TSIncomingMessage *) self).serverTimestamp != nil) { return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue;
return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue;
}
// For messages that don't have a serverTimestamp, it is the same to sort by the receivedAtTimestamp,
// since in the open group poller we sort messages by their server timestamp.
return ((TSIncomingMessage *) self).receivedAtTimestamp;
} }
return self.timestamp; return self.timestamp;
} }

@ -32,7 +32,7 @@ public class ThreadViewModel: NSObject {
self.lastMessageText = thread.lastMessageText(transaction: transaction) self.lastMessageText = thread.lastMessageText(transaction: transaction)
let lastInteraction = thread.lastInteractionForInbox(transaction: transaction) let lastInteraction = thread.lastInteractionForInbox(transaction: transaction)
self.lastMessageForInbox = lastInteraction self.lastMessageForInbox = lastInteraction
self.lastMessageDate = lastInteraction?.receivedAtDate() ?? thread.creationDate self.lastMessageDate = lastInteraction?.dateForUI() ?? thread.creationDate
if let contactThread = thread as? TSContactThread { if let contactThread = thread as? TSContactThread {
self.contactIdentifier = contactThread.contactIdentifier() self.contactIdentifier = contactThread.contactIdentifier()

Loading…
Cancel
Save