From 5fb5c433bcd9c6b96f91f3ff25e3cec296906eed Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 13 Sep 2021 18:55:59 +0300 Subject: [PATCH] Animated emoji animations fixes --- .../Sources/State/PeerInputActivity.swift | 2 +- .../Sources/ChatHistoryListNode.swift | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/submodules/TelegramCore/Sources/State/PeerInputActivity.swift b/submodules/TelegramCore/Sources/State/PeerInputActivity.swift index 45ca3aee04..f90ffa483d 100644 --- a/submodules/TelegramCore/Sources/State/PeerInputActivity.swift +++ b/submodules/TelegramCore/Sources/State/PeerInputActivity.swift @@ -33,7 +33,7 @@ public struct EmojiInteraction: Equatable { for animationDict in animationsArray { if let animationDict = animationDict as? [String: Any] { if let index = animationDict["i"] as? Int, let timeOffset = animationDict["t"] as? Double { - animations.append(EmojiInteraction.Animation(index: index, timeOffset: timeOffset)) + animations.append(EmojiInteraction.Animation(index: index, timeOffset: Float(timeOffset))) } } } diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index 54443cec7b..309b05363d 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -796,8 +796,21 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { case let .result(_, items, _): for case let item as StickerPackItem in items { let indexKeys = item.getStringRepresentationsOfIndexKeys() - if indexKeys.count > 1, let emoji = indexKeys.first, let indexEmoji = indexKeys.last?.first { - if let strIndex = sequence.firstIndex(of: indexEmoji) { + if indexKeys.count > 1, let first = indexKeys.first, let last = indexKeys.last { + let emoji: String? + let indexEmoji: String? + if sequence.contains(first) { + emoji = last + indexEmoji = first + } else if sequence.contains(last) { + emoji = first + indexEmoji = last + } else { + emoji = nil + indexEmoji = nil + } + + if let emoji = emoji, let indexEmoji = indexEmoji?.first, let strIndex = sequence.firstIndex(of: indexEmoji) { let emoji = emoji.strippedEmoji let index = sequence.distance(from: sequence.startIndex, to: strIndex) if animatedEmojiStickers[emoji] != nil {