Fix video transcription text update

This commit is contained in:
Ilya Laktyushin 2022-10-22 16:11:32 +03:00
parent fc2a32678b
commit d9fb54b67f
3 changed files with 26 additions and 10 deletions

View File

@ -60,15 +60,20 @@ class ChatMessageInstantVideoBubbleContentNode: ChatMessageBubbleContentNode {
let _ = item.controllerInteraction.requestMessageUpdate(item.message.id) 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 { if let strongSelf = self, let item = strongSelf.item {
strongSelf.audioTranscriptionState = state strongSelf.audioTranscriptionState = state
strongSelf.interactiveFileNode.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 strongSelf.interactiveFileNode.forcedAudioTranscriptionText = text
let _ = item.controllerInteraction.requestMessageUpdate(item.message.id) 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 { if let strongSelf = self, let item = strongSelf.item {
strongSelf.audioTranscriptionState = state strongSelf.audioTranscriptionState = state
strongSelf.interactiveVideoNode.audioTranscriptionState = state strongSelf.interactiveVideoNode.audioTranscriptionState = state

View File

@ -32,7 +32,7 @@ private struct FetchControls {
let cancel: () -> Void let cancel: () -> Void
} }
enum TranscribedText { enum TranscribedText: Equatable {
case success(text: String, isPending: Bool) case success(text: String, isPending: Bool)
case error(AudioTranscriptionMessageAttribute.TranscriptionError) case error(AudioTranscriptionMessageAttribute.TranscriptionError)
} }
@ -199,7 +199,7 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode {
var requestUpdateLayout: (Bool) -> Void = { _ in } var requestUpdateLayout: (Bool) -> Void = { _ in }
var displayImportedTooltip: (ASDisplayNode) -> Void = { _ in } var displayImportedTooltip: (ASDisplayNode) -> Void = { _ in }
var updateTranscribeExpanded: ((AudioTranscriptionButtonComponent.TranscriptionState) -> Void)? var updateTranscriptionExpanded: ((AudioTranscriptionButtonComponent.TranscriptionState) -> Void)?
private var context: AccountContext? private var context: AccountContext?
private var message: Message? private var message: Message?
@ -447,7 +447,7 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode {
self.audioTranscriptionState = .collapsed self.audioTranscriptionState = .collapsed
self.isWaitingForCollapse = true self.isWaitingForCollapse = true
self.requestUpdateLayout(true) self.requestUpdateLayout(true)
self.updateTranscribeExpanded?(self.audioTranscriptionState) self.updateTranscriptionExpanded?(self.audioTranscriptionState)
case .collapsed: case .collapsed:
self.audioTranscriptionState = .inProgress self.audioTranscriptionState = .inProgress
self.requestUpdateLayout(true) self.requestUpdateLayout(true)

View File

@ -112,6 +112,9 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
var shouldOpen: () -> Bool = { return true } var shouldOpen: () -> Bool = { return true }
var updateTranscriptionExpanded: ((AudioTranscriptionButtonComponent.TranscriptionState) -> Void)?
var updateTranscriptionText: ((TranscribedText?) -> Void)?
var audioTranscriptionState: AudioTranscriptionButtonComponent.TranscriptionState = .collapsed var audioTranscriptionState: AudioTranscriptionButtonComponent.TranscriptionState = .collapsed
var audioTranscriptionText: TranscribedText? var audioTranscriptionText: TranscribedText?
private var transcribeDisposable: Disposable? private var transcribeDisposable: Disposable?
@ -199,6 +202,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
let makeDateAndStatusLayout = self.dateAndStatusNode.asyncLayout() let makeDateAndStatusLayout = self.dateAndStatusNode.asyncLayout()
let audioTranscriptionState = self.audioTranscriptionState let audioTranscriptionState = self.audioTranscriptionState
let audioTranscriptionText = self.audioTranscriptionText
return { item, width, displaySize, maximumDisplaySize, scaleProgress, statusDisplayType, automaticDownload in return { item, width, displaySize, maximumDisplaySize, scaleProgress, statusDisplayType, automaticDownload in
var secretVideoPlaceholderBackgroundImage: UIImage? var secretVideoPlaceholderBackgroundImage: UIImage?
@ -399,6 +403,11 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
break break
} }
var updatedTranscriptionText: TranscribedText?
if audioTranscriptionText != transcribedText {
updatedTranscriptionText = transcribedText
}
let effectiveAudioTranscriptionState = updatedAudioTranscriptionState ?? audioTranscriptionState let effectiveAudioTranscriptionState = updatedAudioTranscriptionState ?? audioTranscriptionState
return (result, { [weak self] layoutData, animation in return (result, { [weak self] layoutData, animation in
@ -410,8 +419,11 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
if let updatedAudioTranscriptionState = updatedAudioTranscriptionState { if let updatedAudioTranscriptionState = updatedAudioTranscriptionState {
strongSelf.audioTranscriptionState = updatedAudioTranscriptionState strongSelf.audioTranscriptionState = updatedAudioTranscriptionState
strongSelf.audioTranscriptionText = transcribedText strongSelf.updateTranscriptionExpanded?(strongSelf.audioTranscriptionState)
strongSelf.updateTranscribeExpanded?(updatedAudioTranscriptionState, transcribedText) }
if let updatedTranscriptionText = updatedTranscriptionText {
strongSelf.audioTranscriptionText = updatedTranscriptionText
strongSelf.updateTranscriptionText?(strongSelf.audioTranscriptionText)
} }
if let updatedInfoBackgroundImage = updatedInfoBackgroundImage { if let updatedInfoBackgroundImage = updatedInfoBackgroundImage {
@ -1151,7 +1163,6 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
} }
} }
var updateTranscribeExpanded: ((AudioTranscriptionButtonComponent.TranscriptionState, TranscribedText?) -> Void)?
private func transcribe() { private func transcribe() {
guard let context = self.item?.context, let message = self.item?.message, self.statusNode == nil else { guard let context = self.item?.context, let message = self.item?.message, self.statusNode == nil else {
return return
@ -1205,7 +1216,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
} }
} }
self.updateTranscribeExpanded?(self.audioTranscriptionState, self.audioTranscriptionText) self.updateTranscriptionExpanded?(self.audioTranscriptionState)
} }
func animateTo(_ node: ChatMessageInteractiveFileNode, animator: ControlledTransitionAnimator) { func animateTo(_ node: ChatMessageInteractiveFileNode, animator: ControlledTransitionAnimator) {