From 0077a070f2e6a9cb831b6e017260edd0f29d91e8 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 28 May 2025 17:24:15 +0200 Subject: [PATCH] Various fixes --- .../Chat/ChatControllerMediaRecording.swift | 36 +++++++++++++++++-- .../ChatRecordingPreviewInputPanelNode.swift | 4 +-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/submodules/TelegramUI/Sources/Chat/ChatControllerMediaRecording.swift b/submodules/TelegramUI/Sources/Chat/ChatControllerMediaRecording.swift index cb16ef2a24..733ef38465 100644 --- a/submodules/TelegramUI/Sources/Chat/ChatControllerMediaRecording.swift +++ b/submodules/TelegramUI/Sources/Chat/ChatControllerMediaRecording.swift @@ -494,7 +494,7 @@ extension ChatControllerImpl { }) } else { let proceed = { - self.withAudioRecorder({ audioRecorder in + self.withAudioRecorder(resuming: true, { audioRecorder in audioRecorder.resume() self.updateChatPresentationInterfaceState(animated: true, interactive: true, { @@ -617,13 +617,43 @@ extension ChatControllerImpl { self.present(tooltipController, in: .window(.root)) } - private func withAudioRecorder(_ f: (ManagedAudioRecorder) -> Void) { + private func withAudioRecorder(resuming: Bool, _ f: (ManagedAudioRecorder) -> Void) { if let audioRecorder = self.audioRecorderValue { f(audioRecorder) } else if let recordedMediaPreview = self.presentationInterfaceState.interfaceState.mediaDraftState, case let .audio(audio) = recordedMediaPreview { self.requestAudioRecorder(beginWithTone: false, existingDraft: audio) if let audioRecorder = self.audioRecorderValue { f(audioRecorder) + + if !resuming { + self.recorderDataDisposable.set( + (audioRecorder.takenRecordedData() + |> deliverOnMainQueue).startStrict( + next: { [weak self] data in + if let strongSelf = self, let data = data { + let audioWaveform = audio.waveform + + strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { + $0.updatedInterfaceState { + $0.withUpdatedMediaDraftState(.audio( + ChatInterfaceMediaDraftState.Audio( + resource: audio.resource, + fileSize: Int32(data.compressedData.count), + duration: data.duration, + waveform: audioWaveform, + trimRange: data.trimRange, + resumeData: data.resumeData + ) + )) + }.updatedInputTextPanelState { panelState in + return panelState.withUpdatedMediaRecordingState(nil) + } + }) + strongSelf.updateDownButtonVisibility() + } + }) + ) + } } } } @@ -632,7 +662,7 @@ extension ChatControllerImpl { if let videoRecorder = self.videoRecorderValue { videoRecorder.updateTrimRange(start: start, end: end, updatedEnd: updatedEnd, apply: apply) } else { - self.withAudioRecorder({ audioRecorder in + self.withAudioRecorder(resuming: false, { audioRecorder in audioRecorder.updateTrimRange(start: start, end: end, updatedEnd: updatedEnd, apply: apply) }) } diff --git a/submodules/TelegramUI/Sources/ChatRecordingPreviewInputPanelNode.swift b/submodules/TelegramUI/Sources/ChatRecordingPreviewInputPanelNode.swift index 1374a6d3db..57fa738e09 100644 --- a/submodules/TelegramUI/Sources/ChatRecordingPreviewInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatRecordingPreviewInputPanelNode.swift @@ -119,7 +119,7 @@ final class PlayButtonNode: ASDisplayNode { transition.updateFrame(node: self.backgroundNode, frame: buttonSize.centered(in: CGRect(origin: .zero, size: size))) - self.playPauseIconNode.frame = CGRect(origin: CGPoint(x: 4.0, y: 1.0 - UIScreenPixel), size: CGSize(width: 21.0, height: 21.0)) + self.playPauseIconNode.frame = CGRect(origin: CGPoint(x: 3.0, y: 1.0 - UIScreenPixel), size: CGSize(width: 21.0, height: 21.0)) transition.updateFrame(node: self.durationLabel, frame: CGRect(origin: CGPoint(x: 18.0, y: 3.0), size: CGSize(width: 35.0, height: 20.0))) transition.updateAlpha(node: self.durationLabel, alpha: buttonSize.width > 27.0 ? 1.0 : 0.0) @@ -509,7 +509,7 @@ final class ChatRecordingPreviewInputPanelNode: ChatInputPanelNode { })) } - let minDuration = max(2.0, 56.0 * audio.duration / waveformBackgroundFrame.size.width) + let minDuration = max(1.0, 56.0 * audio.duration / waveformBackgroundFrame.size.width) let (leftHandleFrame, rightHandleFrame) = self.trimView.update( style: .voiceMessage, theme: interfaceState.theme,