From d897952ce0941e46cac924224382967b385ee937 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 19 Apr 2021 11:36:05 +1000 Subject: [PATCH] use sent timestamp instead of received timestamp for sorting and UI --- .../Message Cells/VisibleMessageCell.swift | 2 +- .../MediaGalleryViewController.swift | 2 +- .../Messages/Signal/TSInteraction.h | 2 ++ .../Messages/Signal/TSInteraction.m | 15 ++++++++------- .../Messaging/ThreadViewModel.swift | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Session/Conversations/Message Cells/VisibleMessageCell.swift b/Session/Conversations/Message Cells/VisibleMessageCell.swift index e1b94861e..c60c0d191 100644 --- a/Session/Conversations/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations/Message Cells/VisibleMessageCell.swift @@ -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) diff --git a/Session/Media Viewing & Editing/MediaGalleryViewController.swift b/Session/Media Viewing & Editing/MediaGalleryViewController.swift index 973acfad6..093289508 100644 --- a/Session/Media Viewing & Editing/MediaGalleryViewController.swift +++ b/Session/Media Viewing & Editing/MediaGalleryViewController.swift @@ -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) diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.h b/SessionMessagingKit/Messages/Signal/TSInteraction.h index 1d67d12c0..7cdef9db1 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.h +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.h @@ -43,6 +43,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value); - (uint64_t)timestampForUI; +- (NSDate *)dateForUI; + - (NSDate *)receivedAtDate; - (OWSInteractionType)interactionType; diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.m b/SessionMessagingKit/Messages/Signal/TSInteraction.m index ad5648f98..a1bf68e0c 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.m +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.m @@ -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; } diff --git a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift index 16f8fa16a..a164f96fb 100644 --- a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift +++ b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift @@ -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()