Added ability to schedule and send without sound recorded voice data.

This commit is contained in:
23rd 2020-11-10 23:32:13 +03:00 committed by John Preston
parent 2668619758
commit 6ecc446a8a
4 changed files with 31 additions and 45 deletions

View file

@ -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)

View file

@ -25,6 +25,7 @@ struct VoiceToSend {
QByteArray bytes;
VoiceWaveform waveform;
int duration = 0;
Api::SendOptions options;
};
struct SendActionUpdate {
Api::SendProgressType type = Api::SendProgressType();

View file

@ -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<SendActionUpdate> 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<QEvent*> 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<base::unique_qptr<QObject>>(
std::move(sendFilter));
auto keyFilterCallback = [=](not_null<QEvent*> 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;
}
}

View file

@ -59,6 +59,8 @@ public:
[[nodiscard]] rpl::producer<bool> lockShowStarts() const;
[[nodiscard]] rpl::producer<> updateSendButtonTypeRequests() const;
void requestToSendWithOptions(Api::SendOptions options);
void setLockBottom(rpl::producer<int> &&bottom);
void setSendButtonGeometryValue(rpl::producer<QRect> &&geometry);
void setEscFilter(Fn<bool()> &&callback);
@ -100,6 +102,7 @@ private:
bool isTypeRecord() const;
bool hasDuration() const;
void hideAnimated();
void finish();
void activeAnimate(bool active);