From d9fb54b67fb3405d7675ad0bb285cae8587bd5dc Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 22 Oct 2022 16:11:32 +0300 Subject: [PATCH] Fix video transcription text update --- ...MessageInstantVideoBubbleContentNode.swift | 9 ++++++-- .../ChatMessageInteractiveFileNode.swift | 6 +++--- ...atMessageInteractiveInstantVideoNode.swift | 21 ++++++++++++++----- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/submodules/TelegramUI/Sources/ChatMessageInstantVideoBubbleContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageInstantVideoBubbleContentNode.swift index b833994607..fdaabade8b 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInstantVideoBubbleContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInstantVideoBubbleContentNode.swift @@ -60,15 +60,20 @@ class ChatMessageInstantVideoBubbleContentNode: ChatMessageBubbleContentNode { let _ = item.controllerInteraction.requestMessageUpdate(item.message.id) } } - self.interactiveVideoNode.updateTranscribeExpanded = { [weak self] state, text in + self.interactiveVideoNode.updateTranscriptionExpanded = { [weak self] state in if let strongSelf = self, let item = strongSelf.item { strongSelf.audioTranscriptionState = state strongSelf.interactiveFileNode.audioTranscriptionState = state + let _ = item.controllerInteraction.requestMessageUpdate(item.message.id) + } + } + self.interactiveVideoNode.updateTranscriptionText = { [weak self] text in + if let strongSelf = self, let item = strongSelf.item { strongSelf.interactiveFileNode.forcedAudioTranscriptionText = text let _ = item.controllerInteraction.requestMessageUpdate(item.message.id) } } - self.interactiveFileNode.updateTranscribeExpanded = { [weak self] state in + self.interactiveFileNode.updateTranscriptionExpanded = { [weak self] state in if let strongSelf = self, let item = strongSelf.item { strongSelf.audioTranscriptionState = state strongSelf.interactiveVideoNode.audioTranscriptionState = state diff --git a/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift b/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift index e006fdbcc6..5d3e366341 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift @@ -32,7 +32,7 @@ private struct FetchControls { let cancel: () -> Void } -enum TranscribedText { +enum TranscribedText: Equatable { case success(text: String, isPending: Bool) case error(AudioTranscriptionMessageAttribute.TranscriptionError) } @@ -199,7 +199,7 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode { var requestUpdateLayout: (Bool) -> Void = { _ in } var displayImportedTooltip: (ASDisplayNode) -> Void = { _ in } - var updateTranscribeExpanded: ((AudioTranscriptionButtonComponent.TranscriptionState) -> Void)? + var updateTranscriptionExpanded: ((AudioTranscriptionButtonComponent.TranscriptionState) -> Void)? private var context: AccountContext? private var message: Message? @@ -447,7 +447,7 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode { self.audioTranscriptionState = .collapsed self.isWaitingForCollapse = true self.requestUpdateLayout(true) - self.updateTranscribeExpanded?(self.audioTranscriptionState) + self.updateTranscriptionExpanded?(self.audioTranscriptionState) case .collapsed: self.audioTranscriptionState = .inProgress self.requestUpdateLayout(true) diff --git a/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift b/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift index 98a8ac1623..e52feba0ba 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift @@ -112,6 +112,9 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { var shouldOpen: () -> Bool = { return true } + var updateTranscriptionExpanded: ((AudioTranscriptionButtonComponent.TranscriptionState) -> Void)? + var updateTranscriptionText: ((TranscribedText?) -> Void)? + var audioTranscriptionState: AudioTranscriptionButtonComponent.TranscriptionState = .collapsed var audioTranscriptionText: TranscribedText? private var transcribeDisposable: Disposable? @@ -199,6 +202,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { let makeDateAndStatusLayout = self.dateAndStatusNode.asyncLayout() let audioTranscriptionState = self.audioTranscriptionState + let audioTranscriptionText = self.audioTranscriptionText return { item, width, displaySize, maximumDisplaySize, scaleProgress, statusDisplayType, automaticDownload in var secretVideoPlaceholderBackgroundImage: UIImage? @@ -399,6 +403,11 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { break } + var updatedTranscriptionText: TranscribedText? + if audioTranscriptionText != transcribedText { + updatedTranscriptionText = transcribedText + } + let effectiveAudioTranscriptionState = updatedAudioTranscriptionState ?? audioTranscriptionState return (result, { [weak self] layoutData, animation in @@ -410,10 +419,13 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { if let updatedAudioTranscriptionState = updatedAudioTranscriptionState { strongSelf.audioTranscriptionState = updatedAudioTranscriptionState - strongSelf.audioTranscriptionText = transcribedText - strongSelf.updateTranscribeExpanded?(updatedAudioTranscriptionState, transcribedText) + strongSelf.updateTranscriptionExpanded?(strongSelf.audioTranscriptionState) } - + if let updatedTranscriptionText = updatedTranscriptionText { + strongSelf.audioTranscriptionText = updatedTranscriptionText + strongSelf.updateTranscriptionText?(strongSelf.audioTranscriptionText) + } + if let updatedInfoBackgroundImage = updatedInfoBackgroundImage { strongSelf.infoBackgroundNode.image = updatedInfoBackgroundImage } @@ -1151,7 +1163,6 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { } } - var updateTranscribeExpanded: ((AudioTranscriptionButtonComponent.TranscriptionState, TranscribedText?) -> Void)? private func transcribe() { guard let context = self.item?.context, let message = self.item?.message, self.statusNode == nil else { return @@ -1205,7 +1216,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { } } - self.updateTranscribeExpanded?(self.audioTranscriptionState, self.audioTranscriptionText) + self.updateTranscriptionExpanded?(self.audioTranscriptionState) } func animateTo(_ node: ChatMessageInteractiveFileNode, animator: ControlledTransitionAnimator) {