diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index d78bc4b41..3714bbf8f 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -1638,10 +1638,12 @@ void VoiceRecordBar::stop(bool send) { if (isHidden() && !send) { return; } + const auto ttlBeforeHide = peekTTLState(); auto disappearanceCallback = [=] { hide(); - stopRecording(send ? StopType::Send : StopType::Cancel); + const auto type = send ? StopType::Send : StopType::Cancel; + stopRecording(type, ttlBeforeHide); }; _lockShowing = false; visibilityAnimate(false, std::move(disappearanceCallback)); @@ -1671,7 +1673,7 @@ void VoiceRecordBar::hideFast() { [[maybe_unused]] const auto s = takeTTLState(); } -void VoiceRecordBar::stopRecording(StopType type) { +void VoiceRecordBar::stopRecording(StopType type, bool ttlBeforeHide) { using namespace ::Media::Capture; if (type == StopType::Cancel) { instance()->stop(crl::guard(this, [=](Result &&data) { @@ -1691,9 +1693,9 @@ void VoiceRecordBar::stopRecording(StopType type) { const auto duration = Duration(data.samples); if (type == StopType::Send) { const auto options = Api::SendOptions{ - .ttlSeconds = takeTTLState() + .ttlSeconds = (ttlBeforeHide ? std::numeric_limits::max() - : 0 + : 0), }; _sendVoiceRequests.fire({ data.bytes, @@ -1901,6 +1903,10 @@ void VoiceRecordBar::computeAndSetLockProgress(QPoint globalPos) { _lock->requestPaintProgress(Progress(localPos.y(), higher - lower)); } +bool VoiceRecordBar::peekTTLState() const { + return !_ttlButton->isDisabled(); +} + bool VoiceRecordBar::takeTTLState() const { const auto hasTtl = !_ttlButton->isDisabled(); _ttlButton->clearState(); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h index 8b59ad5ea..964614597 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h @@ -126,7 +126,7 @@ private: [[nodiscard]] bool recordingAnimationCallback(crl::time now); void stop(bool send); - void stopRecording(StopType type); + void stopRecording(StopType type, bool ttlBeforeHide = false); void visibilityAnimate(bool show, Fn &&callback); [[nodiscard]] bool showRecordButton() const; @@ -149,6 +149,7 @@ private: void computeAndSetLockProgress(QPoint globalPos); + [[nodiscard]] bool peekTTLState() const; [[nodiscard]] bool takeTTLState() const; const style::RecordBar &_st;