Play haptic feedback when receiving emoji interaction

This commit is contained in:
Ilya Laktyushin 2021-09-13 22:27:38 +03:00
parent 34590f0836
commit e3206fc855
2 changed files with 34 additions and 9 deletions

View File

@ -7435,15 +7435,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
strongSelf.chatDisplayNode.historyNode.forEachVisibleItemNode({ itemNode in
if !found, let itemNode = itemNode as? ChatMessageAnimatedStickerItemNode, let item = itemNode.item {
if item.message.id == messageId {
for animation in interaction.animations {
if animation.timeOffset > 0.0 {
Queue.mainQueue().after(Double(animation.timeOffset)) {
itemNode.playAdditionalAnimation(index: animation.index)
}
} else {
itemNode.playAdditionalAnimation(index: animation.index)
}
}
itemNode.playEmojiInteraction(interaction)
found = true
}
}

View File

@ -204,6 +204,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
private var forceStopAnimations = false
private var hapticFeedback: HapticFeedback?
private var haptic: EmojiHaptic?
private var mediaPlayer: MediaPlayer?
private let mediaStatusDisposable = MetaDisposable()
@ -1352,6 +1353,38 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
item.context.account.updateLocalInputActivity(peerId: PeerActivitySpace(peerId: item.message.id.peerId, category: .global), activity: .interactingWithEmoji(emoticon: textEmoji, messageId: item.message.id, interaction: EmojiInteraction(animations: animations)), isPresent: true)
}
func playEmojiInteraction(_ interaction: EmojiInteraction) {
var hapticFeedback: HapticFeedback
if let current = self.hapticFeedback {
hapticFeedback = current
} else {
hapticFeedback = HapticFeedback()
self.hapticFeedback = hapticFeedback
}
var playHaptic = true
if let existingHaptic = self.haptic, existingHaptic.active {
playHaptic = false
}
hapticFeedback.prepareTap()
for animation in interaction.animations {
if animation.timeOffset > 0.0 {
Queue.mainQueue().after(Double(animation.timeOffset)) {
self.playAdditionalAnimation(index: animation.index)
if playHaptic {
hapticFeedback.tap()
}
}
} else {
self.playAdditionalAnimation(index: animation.index)
if playHaptic {
hapticFeedback.tap()
}
}
}
}
func playAdditionalAnimation(index: Int) {
guard let item = self.item else {
return