use sent timestamp instead of received timestamp for sorting and UI

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

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

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

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

@ -180,8 +180,14 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
return self.timestamp;
}
- (NSDate *)dateForUI
{
return [NSDate ows_dateWithMillisecondsSince1970:self.timestampForUI];
}
- (NSDate *)receivedAtDate
{
// This is only used for sorting threads
return [NSDate ows_dateWithMillisecondsSince1970:self.receivedAtTimestamp];
}
@ -222,13 +228,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
- (uint64_t)sortId
{
if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) {
if (((TSIncomingMessage *) self).serverTimestamp != nil) {
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;
if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage && ((TSIncomingMessage *) self).serverTimestamp != nil) {
return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue;
}
return self.timestamp;
}

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

Loading…
Cancel
Save