From 3b7ee797b301fc56c40aa39b6752e9ea9db46631 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 17 Nov 2020 13:55:34 +0400 Subject: [PATCH] Fix animated emoji haptics --- .../ChatMessageAnimatedStickerItemNode.swift | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift index b4158193b8..e6c0accb84 100644 --- a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift @@ -1303,6 +1303,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { } let beatingHearts: [UInt32] = [0x2764, 0x1F90E, 0x1F9E1, 0x1F499, 0x1F49A, 0x1F49C, 0x1F49B, 0x1F5A4, 0x1F90D] + let heart = 0x2764 let peach = 0x1F351 let coffin = 0x26B0 @@ -1312,7 +1313,12 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { return view.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue } - if let text = self.item?.message.text, let firstScalar = text.unicodeScalars.first { + if let text = self.item?.message.text, var firstScalar = text.unicodeScalars.first { + var textEmoji = text.strippedEmoji + if beatingHearts.contains(firstScalar.value) { + textEmoji = "❤️" + firstScalar = UnicodeScalar(heart)! + } return .optionalAction({ if shouldPlay { let _ = (appConfiguration @@ -1322,7 +1328,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { } let emojiSounds = AnimatedEmojiSoundsConfiguration.with(appConfiguration: appConfiguration, account: item.context.account) for (emoji, file) in emojiSounds.sounds { - if emoji.strippedEmoji == text.strippedEmoji { + if emoji.strippedEmoji == textEmoji.strippedEmoji { let mediaManager = item.context.sharedContext.mediaManager let mediaPlayer = MediaPlayer(audioSessionManager: mediaManager.audioSession, postbox: item.context.account.postbox, resourceReference: .standalone(resource: file.resource), streamable: .none, video: false, preferSoftwareDecoding: false, enableSound: true, fetchAutomatically: true, ambient: true) mediaPlayer.togglePlayPause() @@ -1334,24 +1340,24 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { strongSelf.mediaStatusDisposable.set((mediaPlayer.status |> deliverOnMainQueue).start(next: { [weak self, weak animationNode] status in if let strongSelf = self { - if firstScalar.value == coffin || firstScalar.value == peach { - var haptic: EmojiHaptic - if let current = strongSelf.haptic { - haptic = current - } else { - if beatingHearts.contains(firstScalar.value) { - haptic = HeartbeatHaptic() - } else if firstScalar.value == coffin { - haptic = CoffinHaptic() - } else { - haptic = PeachHaptic() - } - haptic.enabled = true - strongSelf.haptic = haptic - } - if !haptic.active { - haptic.start(time: 0.0) + + var haptic: EmojiHaptic? + if let current = strongSelf.haptic { + haptic = current + } else { + if firstScalar.value == heart { + haptic = HeartbeatHaptic() + } else if firstScalar.value == coffin { + haptic = CoffinHaptic() + } else if firstScalar.value == peach { + haptic = PeachHaptic() } + haptic?.enabled = true + strongSelf.haptic = haptic + } + + if let haptic = haptic, !haptic.active { + haptic.start(time: 0.0) } switch status.status {