Added delay for start recording voice message.

This commit is contained in:
23rd 2020-10-12 19:52:41 +03:00 committed by John Preston
parent 367b487a6c
commit 041d8571c2
4 changed files with 46 additions and 25 deletions

View File

@ -732,19 +732,18 @@ void HistoryWidget::initVoiceRecordBar() {
_voiceRecordBar->setSendButtonGeometryValue(_send->geometryValue()); _voiceRecordBar->setSendButtonGeometryValue(_send->geometryValue());
_voiceRecordBar->startRecordingRequests( _voiceRecordBar->setStartRecordingFilter([=] {
) | rpl::start_with_next([=] {
const auto error = _peer const auto error = _peer
? Data::RestrictionError(_peer, ChatRestriction::f_send_media) ? Data::RestrictionError(_peer, ChatRestriction::f_send_media)
: std::nullopt; : std::nullopt;
if (error) { if (error) {
Ui::show(Box<InformBox>(*error)); Ui::show(Box<InformBox>(*error));
return; return true;
} else if (showSlowmodeError()) { } else if (showSlowmodeError()) {
return; return true;
} }
_voiceRecordBar->startRecording(); return false;
}, lifetime()); });
_voiceRecordBar->sendActionUpdates( _voiceRecordBar->sendActionUpdates(
) | rpl::start_with_next([=](const auto &data) { ) | rpl::start_with_next([=](const auto &data) {

View File

@ -915,8 +915,7 @@ void ComposeControls::initVoiceRecordBar() {
_field->setVisible(!active); _field->setVisible(!active);
}, _wrap->lifetime()); }, _wrap->lifetime());
_voiceRecordBar->startRecordingRequests( _voiceRecordBar->setStartRecordingFilter([=] {
) | rpl::start_with_next([=] {
const auto error = _history const auto error = _history
? Data::RestrictionError( ? Data::RestrictionError(
_history->peer, _history->peer,
@ -924,12 +923,12 @@ void ComposeControls::initVoiceRecordBar() {
: std::nullopt; : std::nullopt;
if (error) { if (error) {
Ui::show(Box<InformBox>(*error)); Ui::show(Box<InformBox>(*error));
return; return true;
} else if (_showSlowmodeError && _showSlowmodeError()) { } else if (_showSlowmodeError && _showSlowmodeError()) {
return; return true;
} }
_voiceRecordBar->startRecording(); return false;
}, _wrap->lifetime()); });
{ {
auto geometry = rpl::merge( auto geometry = rpl::merge(

View File

@ -429,6 +429,7 @@ VoiceRecordBar::VoiceRecordBar(
, _level(std::make_unique<RecordLevel>( , _level(std::make_unique<RecordLevel>(
sectionWidget, sectionWidget,
_controller->widget()->leaveEvents())) _controller->widget()->leaveEvents()))
, _startTimer([=] { startRecording(); })
, _cancelFont(st::historyRecordFont) { , _cancelFont(st::historyRecordFont) {
resize(QSize(parent->width(), recorderHeight)); resize(QSize(parent->width(), recorderHeight));
init(); init();
@ -589,6 +590,25 @@ void VoiceRecordBar::init() {
updateMessageGeometry(); updateMessageGeometry();
update(_messageRect); update(_messageRect);
}, lifetime()); }, lifetime());
_send->events(
) | rpl::filter([=](not_null<QEvent*> e) {
return isTypeRecord()
&& !isRecording()
&& !_showAnimation.animating()
&& !_lock->isLocked()
&& (e->type() == QEvent::MouseButtonPress
|| e->type() == QEvent::MouseButtonRelease);
}) | rpl::start_with_next([=](not_null<QEvent*> e) {
if (e->type() == QEvent::MouseButtonPress) {
if (_startRecordingFilter && _startRecordingFilter()) {
return;
}
_startTimer.callOnce(st::historyRecordVoiceShowDuration);
} else if (e->type() == QEvent::MouseButtonRelease) {
_startTimer.cancel();
}
}, lifetime());
} }
void VoiceRecordBar::activeAnimate(bool active) { void VoiceRecordBar::activeAnimate(bool active) {
@ -626,6 +646,10 @@ void VoiceRecordBar::setEscFilter(Fn<bool()> &&callback) {
_escFilter = std::move(callback); _escFilter = std::move(callback);
} }
void VoiceRecordBar::setStartRecordingFilter(Fn<bool()> &&callback) {
_startRecordingFilter = std::move(callback);
}
void VoiceRecordBar::setLockBottom(rpl::producer<int> &&bottom) { void VoiceRecordBar::setLockBottom(rpl::producer<int> &&bottom) {
std::move( std::move(
bottom bottom
@ -645,8 +669,13 @@ void VoiceRecordBar::setSendButtonGeometryValue(
} }
void VoiceRecordBar::startRecording() { void VoiceRecordBar::startRecording() {
if (isRecording()) {
return;
}
auto appearanceCallback = [=] { auto appearanceCallback = [=] {
Expects(!_showAnimation.animating()); if(_showAnimation.animating()) {
return;
}
using namespace ::Media::Capture; using namespace ::Media::Capture;
if (!instance()->available()) { if (!instance()->available()) {
@ -717,7 +746,7 @@ void VoiceRecordBar::recordUpdated(quint16 level, int samples) {
void VoiceRecordBar::stop(bool send) { void VoiceRecordBar::stop(bool send) {
auto disappearanceCallback = [=] { auto disappearanceCallback = [=] {
Expects(!_showAnimation.animating()); _showAnimation.stop();
hide(); hide();
_recording = false; _recording = false;
@ -833,16 +862,6 @@ bool VoiceRecordBar::isLockPresent() const {
return _lockShowing.current(); return _lockShowing.current();
} }
rpl::producer<> VoiceRecordBar::startRecordingRequests() const {
return _send->events(
) | rpl::filter([=](not_null<QEvent*> e) {
return isTypeRecord()
&& !_showAnimation.animating()
&& !_lock->isLocked()
&& (e->type() == QEvent::MouseButtonPress);
}) | rpl::to_empty;
}
bool VoiceRecordBar::isTypeRecord() const { bool VoiceRecordBar::isTypeRecord() const {
return (_send->type() == Ui::SendButton::Type::Record); return (_send->type() == Ui::SendButton::Type::Record);
} }

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once #pragma once
#include "api/api_common.h" #include "api/api_common.h"
#include "base/timer.h"
#include "history/view/controls/compose_controls_common.h" #include "history/view/controls/compose_controls_common.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
@ -51,12 +52,12 @@ public:
[[nodiscard]] rpl::producer<SendActionUpdate> sendActionUpdates() const; [[nodiscard]] rpl::producer<SendActionUpdate> sendActionUpdates() const;
[[nodiscard]] rpl::producer<VoiceToSend> sendVoiceRequests() const; [[nodiscard]] rpl::producer<VoiceToSend> sendVoiceRequests() const;
[[nodiscard]] rpl::producer<bool> recordingStateChanges() const; [[nodiscard]] rpl::producer<bool> recordingStateChanges() const;
[[nodiscard]] rpl::producer<> startRecordingRequests() const;
[[nodiscard]] rpl::producer<bool> lockShowStarts() const; [[nodiscard]] rpl::producer<bool> lockShowStarts() const;
void setLockBottom(rpl::producer<int> &&bottom); void setLockBottom(rpl::producer<int> &&bottom);
void setSendButtonGeometryValue(rpl::producer<QRect> &&geometry); void setSendButtonGeometryValue(rpl::producer<QRect> &&geometry);
void setEscFilter(Fn<bool()> &&callback); void setEscFilter(Fn<bool()> &&callback);
void setStartRecordingFilter(Fn<bool()> &&callback);
[[nodiscard]] bool isRecording() const; [[nodiscard]] bool isRecording() const;
[[nodiscard]] bool isLockPresent() const; [[nodiscard]] bool isLockPresent() const;
@ -102,6 +103,8 @@ private:
const std::unique_ptr<RecordLock> _lock; const std::unique_ptr<RecordLock> _lock;
const std::unique_ptr<RecordLevel> _level; const std::unique_ptr<RecordLevel> _level;
base::Timer _startTimer;
rpl::event_stream<SendActionUpdate> _sendActionUpdates; rpl::event_stream<SendActionUpdate> _sendActionUpdates;
rpl::event_stream<VoiceToSend> _sendVoiceRequests; rpl::event_stream<VoiceToSend> _sendVoiceRequests;
@ -113,6 +116,7 @@ private:
Ui::Text::String _message; Ui::Text::String _message;
Fn<bool()> _escFilter; Fn<bool()> _escFilter;
Fn<bool()> _startRecordingFilter;
rpl::variable<bool> _recording = false; rpl::variable<bool> _recording = false;
rpl::variable<bool> _inField = false; rpl::variable<bool> _inField = false;