From eeff3d77890efbf486521c8f63ed46a9e33b9bcd Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 29 Apr 2021 10:25:11 -0300 Subject: [PATCH] Respond to CR. --- .../ConversationView/InteractionReactionState.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/InteractionReactionState.swift b/Signal/src/ViewControllers/ConversationView/InteractionReactionState.swift index 3bb64257b8..0b344c5207 100644 --- a/Signal/src/ViewControllers/ConversationView/InteractionReactionState.swift +++ b/Signal/src/ViewControllers/ConversationView/InteractionReactionState.swift @@ -12,7 +12,7 @@ public class InteractionReactionState: NSObject { struct EmojiCount { let emoji: String let count: Int - let firstReceivedAtTimestamp: UInt64 + let lastReceivedAtTimestamp: UInt64 } let reactionsByEmoji: [Emoji: [OWSReaction]] @@ -61,19 +61,19 @@ public class InteractionReactionState: NSObject { emojiToRender = mostRecentEmoji } - let firstReceivedAtTimestamp = (reactions.map { $0.receivedAtTimestamp }.min() + let lastReceivedAtTimestamp = (reactions.map { $0.receivedAtTimestamp }.max() ?? mostRecentReaction.receivedAtTimestamp) return EmojiCount(emoji: emojiToRender, count: reactions.count, - firstReceivedAtTimestamp: firstReceivedAtTimestamp) + lastReceivedAtTimestamp: lastReceivedAtTimestamp) }.sorted { (left: EmojiCount, right: EmojiCount) in if left.count != right.count { // Sort more common reactions (higher counter) first. return left.count > right.count - } else if left.firstReceivedAtTimestamp != right.firstReceivedAtTimestamp { - // Sort reactions received first (lower first receivedAtTimestamp) first. - return left.firstReceivedAtTimestamp < right.firstReceivedAtTimestamp + } else if left.lastReceivedAtTimestamp != right.lastReceivedAtTimestamp { + // Sort reactions received in descending order of when we received them. + return left.lastReceivedAtTimestamp > right.lastReceivedAtTimestamp } else { // Ensure stability of sort by comparing emoji. return left.emoji > right.emoji