From 6ecc446a8a1939ee2811c38c9806fb47dac4afc8 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 10 Nov 2020 23:32:13 +0300 Subject: [PATCH] Added ability to schedule and send without sound recorded voice data. --- .../SourceFiles/history/history_widget.cpp | 6 ++ .../view/controls/compose_controls_common.h | 1 + .../history_view_voice_record_bar.cpp | 66 ++++++------------- .../controls/history_view_voice_record_bar.h | 3 + 4 files changed, 31 insertions(+), 45 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 23cf33d08c..8db4b16a6c 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -791,6 +791,7 @@ void HistoryWidget::initVoiceRecordBar() { auto action = Api::SendAction(_history); action.replyTo = replyToId(); + action.options = data.options; session().api().sendVoiceMessage( data.bytes, data.waveform, @@ -3064,6 +3065,11 @@ void HistoryWidget::send(Api::SendOptions options) { return; } + if (_voiceRecordBar && _voiceRecordBar->isListenState()) { + _voiceRecordBar->requestToSendWithOptions(options); + return; + } + const auto webPageId = _previewCancelled ? CancelledWebPageId : ((_previewData && _previewData->pendingTill >= 0) diff --git a/Telegram/SourceFiles/history/view/controls/compose_controls_common.h b/Telegram/SourceFiles/history/view/controls/compose_controls_common.h index d34621c1e5..3550707494 100644 --- a/Telegram/SourceFiles/history/view/controls/compose_controls_common.h +++ b/Telegram/SourceFiles/history/view/controls/compose_controls_common.h @@ -25,6 +25,7 @@ struct VoiceToSend { QByteArray bytes; VoiceWaveform waveform; int duration = 0; + Api::SendOptions options; }; struct SendActionUpdate { Api::SendProgressType type = Api::SendProgressType(); 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 5a51b66d59..7bd43d9d7e 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 @@ -958,7 +958,7 @@ void VoiceRecordBar::init() { }) | rpl::start_with_next([=] { _listen->stopRequests( ) | rpl::take(1) | rpl::start_with_next([=] { - visibilityAnimate(false, [=] { hide(); }); + hideAnimated(); }, _listen->lifetime()); _listen->lifetime().add([=] { _listenChanges.fire({}); }); @@ -1218,6 +1218,18 @@ void VoiceRecordBar::drawMessage(Painter &p, float64 recordActive) { style::al_center); } +void VoiceRecordBar::requestToSendWithOptions(Api::SendOptions options) { + if (isListenState()) { + const auto data = _listen->data(); + _sendVoiceRequests.fire({ + data->bytes, + data->waveform, + Duration(data->samples), + options }); + hideAnimated(); + } +} + rpl::producer VoiceRecordBar::sendActionUpdates() const { return _sendActionUpdates.events(); } @@ -1230,6 +1242,10 @@ bool VoiceRecordBar::isRecording() const { return _recording.current(); } +void VoiceRecordBar::hideAnimated() { + visibilityAnimate(false, [=] { hide(); }); +} + void VoiceRecordBar::finishAnimating() { _showAnimation.stop(); } @@ -1360,50 +1376,10 @@ void VoiceRecordBar::installClickOutsideFilter() { } void VoiceRecordBar::installListenStateFilter() { - const auto close = [=](bool send) { - auto callback = [=] { - if (send) { - const auto data = _listen->data(); - _sendVoiceRequests.fire({ - data->bytes, - data->waveform, - Duration(data->samples) }); - } - hide(); - }; - visibilityAnimate(false, std::move(callback)); - }; - - const auto isSend = [=] { - return _send->type() == Ui::SendButton::Type::Send - || _send->type() == Ui::SendButton::Type::Schedule; - }; - - auto mouseFilterCallback = [=](not_null e) { - using Result = base::EventFilterResult; - if (!isSend()) { - return Result::Continue; - } - switch(e->type()) { - case QEvent::MouseButtonRelease: { - close(true); - _send->clearState(); - return Result::Cancel; - } - default: return Result::Continue; - } - }; - - auto sendFilter = base::install_event_filter( - _send.get(), - std::move(mouseFilterCallback)); - - _listen->lifetime().make_state>( - std::move(sendFilter)); - auto keyFilterCallback = [=](not_null e) { using Result = base::EventFilterResult; - if (!isSend()) { + if (!(_send->type() == Ui::SendButton::Type::Send + || _send->type() == Ui::SendButton::Type::Schedule)) { return Result::Continue; } switch(e->type()) { @@ -1413,14 +1389,14 @@ void VoiceRecordBar::installListenStateFilter() { const auto isEnter = (key == Qt::Key_Enter || key == Qt::Key_Return); if (isEnter) { - close(true); + requestToSendWithOptions({}); return Result::Cancel; } if (isEsc) { if (_escFilter && _escFilter()) { return Result::Continue; } else { - close(false); + hideAnimated(); return Result::Cancel; } } 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 0968e6e520..59f2d891fe 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 @@ -59,6 +59,8 @@ public: [[nodiscard]] rpl::producer lockShowStarts() const; [[nodiscard]] rpl::producer<> updateSendButtonTypeRequests() const; + void requestToSendWithOptions(Api::SendOptions options); + void setLockBottom(rpl::producer &&bottom); void setSendButtonGeometryValue(rpl::producer &&geometry); void setEscFilter(Fn &&callback); @@ -100,6 +102,7 @@ private: bool isTypeRecord() const; bool hasDuration() const; + void hideAnimated(); void finish(); void activeAnimate(bool active);