Added delay for start recording voice message.
This commit is contained in:
parent
367b487a6c
commit
041d8571c2
|
@ -732,19 +732,18 @@ void HistoryWidget::initVoiceRecordBar() {
|
|||
|
||||
_voiceRecordBar->setSendButtonGeometryValue(_send->geometryValue());
|
||||
|
||||
_voiceRecordBar->startRecordingRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
_voiceRecordBar->setStartRecordingFilter([=] {
|
||||
const auto error = _peer
|
||||
? Data::RestrictionError(_peer, ChatRestriction::f_send_media)
|
||||
: std::nullopt;
|
||||
if (error) {
|
||||
Ui::show(Box<InformBox>(*error));
|
||||
return;
|
||||
return true;
|
||||
} else if (showSlowmodeError()) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
_voiceRecordBar->startRecording();
|
||||
}, lifetime());
|
||||
return false;
|
||||
});
|
||||
|
||||
_voiceRecordBar->sendActionUpdates(
|
||||
) | rpl::start_with_next([=](const auto &data) {
|
||||
|
|
|
@ -915,8 +915,7 @@ void ComposeControls::initVoiceRecordBar() {
|
|||
_field->setVisible(!active);
|
||||
}, _wrap->lifetime());
|
||||
|
||||
_voiceRecordBar->startRecordingRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
_voiceRecordBar->setStartRecordingFilter([=] {
|
||||
const auto error = _history
|
||||
? Data::RestrictionError(
|
||||
_history->peer,
|
||||
|
@ -924,12 +923,12 @@ void ComposeControls::initVoiceRecordBar() {
|
|||
: std::nullopt;
|
||||
if (error) {
|
||||
Ui::show(Box<InformBox>(*error));
|
||||
return;
|
||||
return true;
|
||||
} else if (_showSlowmodeError && _showSlowmodeError()) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
_voiceRecordBar->startRecording();
|
||||
}, _wrap->lifetime());
|
||||
return false;
|
||||
});
|
||||
|
||||
{
|
||||
auto geometry = rpl::merge(
|
||||
|
|
|
@ -429,6 +429,7 @@ VoiceRecordBar::VoiceRecordBar(
|
|||
, _level(std::make_unique<RecordLevel>(
|
||||
sectionWidget,
|
||||
_controller->widget()->leaveEvents()))
|
||||
, _startTimer([=] { startRecording(); })
|
||||
, _cancelFont(st::historyRecordFont) {
|
||||
resize(QSize(parent->width(), recorderHeight));
|
||||
init();
|
||||
|
@ -589,6 +590,25 @@ void VoiceRecordBar::init() {
|
|||
updateMessageGeometry();
|
||||
update(_messageRect);
|
||||
}, 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) {
|
||||
|
@ -626,6 +646,10 @@ void VoiceRecordBar::setEscFilter(Fn<bool()> &&callback) {
|
|||
_escFilter = std::move(callback);
|
||||
}
|
||||
|
||||
void VoiceRecordBar::setStartRecordingFilter(Fn<bool()> &&callback) {
|
||||
_startRecordingFilter = std::move(callback);
|
||||
}
|
||||
|
||||
void VoiceRecordBar::setLockBottom(rpl::producer<int> &&bottom) {
|
||||
std::move(
|
||||
bottom
|
||||
|
@ -645,8 +669,13 @@ void VoiceRecordBar::setSendButtonGeometryValue(
|
|||
}
|
||||
|
||||
void VoiceRecordBar::startRecording() {
|
||||
if (isRecording()) {
|
||||
return;
|
||||
}
|
||||
auto appearanceCallback = [=] {
|
||||
Expects(!_showAnimation.animating());
|
||||
if(_showAnimation.animating()) {
|
||||
return;
|
||||
}
|
||||
|
||||
using namespace ::Media::Capture;
|
||||
if (!instance()->available()) {
|
||||
|
@ -717,7 +746,7 @@ void VoiceRecordBar::recordUpdated(quint16 level, int samples) {
|
|||
|
||||
void VoiceRecordBar::stop(bool send) {
|
||||
auto disappearanceCallback = [=] {
|
||||
Expects(!_showAnimation.animating());
|
||||
_showAnimation.stop();
|
||||
|
||||
hide();
|
||||
_recording = false;
|
||||
|
@ -833,16 +862,6 @@ bool VoiceRecordBar::isLockPresent() const {
|
|||
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 {
|
||||
return (_send->type() == Ui::SendButton::Type::Record);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#pragma once
|
||||
|
||||
#include "api/api_common.h"
|
||||
#include "base/timer.h"
|
||||
#include "history/view/controls/compose_controls_common.h"
|
||||
#include "ui/effects/animations.h"
|
||||
#include "ui/rp_widget.h"
|
||||
|
@ -51,12 +52,12 @@ public:
|
|||
[[nodiscard]] rpl::producer<SendActionUpdate> sendActionUpdates() const;
|
||||
[[nodiscard]] rpl::producer<VoiceToSend> sendVoiceRequests() const;
|
||||
[[nodiscard]] rpl::producer<bool> recordingStateChanges() const;
|
||||
[[nodiscard]] rpl::producer<> startRecordingRequests() const;
|
||||
[[nodiscard]] rpl::producer<bool> lockShowStarts() const;
|
||||
|
||||
void setLockBottom(rpl::producer<int> &&bottom);
|
||||
void setSendButtonGeometryValue(rpl::producer<QRect> &&geometry);
|
||||
void setEscFilter(Fn<bool()> &&callback);
|
||||
void setStartRecordingFilter(Fn<bool()> &&callback);
|
||||
|
||||
[[nodiscard]] bool isRecording() const;
|
||||
[[nodiscard]] bool isLockPresent() const;
|
||||
|
@ -102,6 +103,8 @@ private:
|
|||
const std::unique_ptr<RecordLock> _lock;
|
||||
const std::unique_ptr<RecordLevel> _level;
|
||||
|
||||
base::Timer _startTimer;
|
||||
|
||||
rpl::event_stream<SendActionUpdate> _sendActionUpdates;
|
||||
rpl::event_stream<VoiceToSend> _sendVoiceRequests;
|
||||
|
||||
|
@ -113,6 +116,7 @@ private:
|
|||
Ui::Text::String _message;
|
||||
|
||||
Fn<bool()> _escFilter;
|
||||
Fn<bool()> _startRecordingFilter;
|
||||
|
||||
rpl::variable<bool> _recording = false;
|
||||
rpl::variable<bool> _inField = false;
|
||||
|
|
Loading…
Reference in New Issue