From 4ab4eb8ef2334d19f448735398873b2cc95603e8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 3 Mar 2025 13:36:14 +0400 Subject: [PATCH] Pause voice in pay-to-send chats. --- Telegram/SourceFiles/history/history_widget.cpp | 12 ++++++++---- .../view/controls/history_view_compose_controls.cpp | 3 +++ .../view/controls/history_view_voice_record_bar.cpp | 9 +++++++++ .../view/controls/history_view_voice_record_bar.h | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index c7c55f463..459b3951c 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -5169,12 +5169,13 @@ void HistoryWidget::updateSendButtonType() { : 0; }(); const auto perMessage = _peer ? _peer->starsPerMessageChecked() : 0; - const auto stars = perMessage - ? perMessage * ComputeSendingMessagesCount(_history, { + const auto messages = _voiceRecordBar->isListenState() + ? 1 + : ComputeSendingMessagesCount(_history, { .forward = &_forwardPanel->items(), .text = &_field->getTextWithTags(), - }) - : 0; + }); + const auto stars = perMessage ? (perMessage * messages) : 0; _send->setState({ .type = (delay > 0) ? Type::Slowmode : type, .slowmodeDelay = delay, @@ -5775,6 +5776,9 @@ void HistoryWidget::fieldFocused() { } void HistoryWidget::updateFieldPlaceholder() { + _voiceRecordBar->setPauseInsteadSend(_history + && _history->peer->starsPerMessageChecked() > 0); + if (!_editMsgId && _inlineBot && !_inlineLookingUpBot) { _field->setPlaceholder( rpl::single(_inlineBot->botInfo->inlinePlaceholder.mid(1)), diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 1fee75916..0d277b016 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1714,6 +1714,9 @@ void ComposeControls::initFieldAutocomplete() { } void ComposeControls::updateFieldPlaceholder() { + _voiceRecordBar->setPauseInsteadSend(_history + && _history->peer->starsPerMessageChecked() > 0); + if (!isEditingMessage() && _isInlineBot) { _field->setPlaceholder( rpl::single(_inlineBot->botInfo->inlinePlaceholder.mid(1)), 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 696a480b1..bcf5cf292 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 @@ -1768,6 +1768,10 @@ void VoiceRecordBar::setTTLFilter(FilterCallback &&callback) { _hasTTLFilter = std::move(callback); } +void VoiceRecordBar::setPauseInsteadSend(bool pauseInsteadSend) { + _pauseInsteadSend = pauseInsteadSend; +} + void VoiceRecordBar::initLockGeometry() { const auto parent = static_cast(parentWidget()); rpl::merge( @@ -1918,6 +1922,11 @@ void VoiceRecordBar::recordUpdated(quint16 level, int samples) { void VoiceRecordBar::stop(bool send) { if (isHidden() && !send) { return; + } else if (send && _pauseInsteadSend) { + _fullRecord = true; + stopRecording(StopType::Listen); + _lockShowing = false; + return; } const auto ttlBeforeHide = peekTTLState(); auto disappearanceCallback = [=] { 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 027366a59..c1a9ff4a7 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 @@ -100,6 +100,7 @@ public: void setStartRecordingFilter(FilterCallback &&callback); void setTTLFilter(FilterCallback &&callback); + void setPauseInsteadSend(bool pauseInsteadSend); [[nodiscard]] bool isRecording() const; [[nodiscard]] bool isRecordingLocked() const; @@ -193,6 +194,7 @@ private: FilterCallback _hasTTLFilter; bool _warningShown = false; + bool _pauseInsteadSend = false; rpl::variable _recording = false; rpl::variable _inField = false;