mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Added ability to schedule and send without sound recorded voice data.
This commit is contained in:
parent
2668619758
commit
6ecc446a8a
4 changed files with 31 additions and 45 deletions
|
@ -791,6 +791,7 @@ void HistoryWidget::initVoiceRecordBar() {
|
||||||
|
|
||||||
auto action = Api::SendAction(_history);
|
auto action = Api::SendAction(_history);
|
||||||
action.replyTo = replyToId();
|
action.replyTo = replyToId();
|
||||||
|
action.options = data.options;
|
||||||
session().api().sendVoiceMessage(
|
session().api().sendVoiceMessage(
|
||||||
data.bytes,
|
data.bytes,
|
||||||
data.waveform,
|
data.waveform,
|
||||||
|
@ -3064,6 +3065,11 @@ void HistoryWidget::send(Api::SendOptions options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_voiceRecordBar && _voiceRecordBar->isListenState()) {
|
||||||
|
_voiceRecordBar->requestToSendWithOptions(options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto webPageId = _previewCancelled
|
const auto webPageId = _previewCancelled
|
||||||
? CancelledWebPageId
|
? CancelledWebPageId
|
||||||
: ((_previewData && _previewData->pendingTill >= 0)
|
: ((_previewData && _previewData->pendingTill >= 0)
|
||||||
|
|
|
@ -25,6 +25,7 @@ struct VoiceToSend {
|
||||||
QByteArray bytes;
|
QByteArray bytes;
|
||||||
VoiceWaveform waveform;
|
VoiceWaveform waveform;
|
||||||
int duration = 0;
|
int duration = 0;
|
||||||
|
Api::SendOptions options;
|
||||||
};
|
};
|
||||||
struct SendActionUpdate {
|
struct SendActionUpdate {
|
||||||
Api::SendProgressType type = Api::SendProgressType();
|
Api::SendProgressType type = Api::SendProgressType();
|
||||||
|
|
|
@ -958,7 +958,7 @@ void VoiceRecordBar::init() {
|
||||||
}) | rpl::start_with_next([=] {
|
}) | rpl::start_with_next([=] {
|
||||||
_listen->stopRequests(
|
_listen->stopRequests(
|
||||||
) | rpl::take(1) | rpl::start_with_next([=] {
|
) | rpl::take(1) | rpl::start_with_next([=] {
|
||||||
visibilityAnimate(false, [=] { hide(); });
|
hideAnimated();
|
||||||
}, _listen->lifetime());
|
}, _listen->lifetime());
|
||||||
|
|
||||||
_listen->lifetime().add([=] { _listenChanges.fire({}); });
|
_listen->lifetime().add([=] { _listenChanges.fire({}); });
|
||||||
|
@ -1218,6 +1218,18 @@ void VoiceRecordBar::drawMessage(Painter &p, float64 recordActive) {
|
||||||
style::al_center);
|
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 {
|
rpl::producer<SendActionUpdate> VoiceRecordBar::sendActionUpdates() const {
|
||||||
return _sendActionUpdates.events();
|
return _sendActionUpdates.events();
|
||||||
}
|
}
|
||||||
|
@ -1230,6 +1242,10 @@ bool VoiceRecordBar::isRecording() const {
|
||||||
return _recording.current();
|
return _recording.current();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VoiceRecordBar::hideAnimated() {
|
||||||
|
visibilityAnimate(false, [=] { hide(); });
|
||||||
|
}
|
||||||
|
|
||||||
void VoiceRecordBar::finishAnimating() {
|
void VoiceRecordBar::finishAnimating() {
|
||||||
_showAnimation.stop();
|
_showAnimation.stop();
|
||||||
}
|
}
|
||||||
|
@ -1360,50 +1376,10 @@ void VoiceRecordBar::installClickOutsideFilter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoiceRecordBar::installListenStateFilter() {
|
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) {
|
auto keyFilterCallback = [=](not_null<QEvent*> e) {
|
||||||
using Result = base::EventFilterResult;
|
using Result = base::EventFilterResult;
|
||||||
if (!isSend()) {
|
if (!(_send->type() == Ui::SendButton::Type::Send
|
||||||
|
|| _send->type() == Ui::SendButton::Type::Schedule)) {
|
||||||
return Result::Continue;
|
return Result::Continue;
|
||||||
}
|
}
|
||||||
switch(e->type()) {
|
switch(e->type()) {
|
||||||
|
@ -1413,14 +1389,14 @@ void VoiceRecordBar::installListenStateFilter() {
|
||||||
const auto isEnter = (key == Qt::Key_Enter
|
const auto isEnter = (key == Qt::Key_Enter
|
||||||
|| key == Qt::Key_Return);
|
|| key == Qt::Key_Return);
|
||||||
if (isEnter) {
|
if (isEnter) {
|
||||||
close(true);
|
requestToSendWithOptions({});
|
||||||
return Result::Cancel;
|
return Result::Cancel;
|
||||||
}
|
}
|
||||||
if (isEsc) {
|
if (isEsc) {
|
||||||
if (_escFilter && _escFilter()) {
|
if (_escFilter && _escFilter()) {
|
||||||
return Result::Continue;
|
return Result::Continue;
|
||||||
} else {
|
} else {
|
||||||
close(false);
|
hideAnimated();
|
||||||
return Result::Cancel;
|
return Result::Cancel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,8 @@ public:
|
||||||
[[nodiscard]] rpl::producer<bool> lockShowStarts() const;
|
[[nodiscard]] rpl::producer<bool> lockShowStarts() const;
|
||||||
[[nodiscard]] rpl::producer<> updateSendButtonTypeRequests() const;
|
[[nodiscard]] rpl::producer<> updateSendButtonTypeRequests() const;
|
||||||
|
|
||||||
|
void requestToSendWithOptions(Api::SendOptions options);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -100,6 +102,7 @@ private:
|
||||||
bool isTypeRecord() const;
|
bool isTypeRecord() const;
|
||||||
bool hasDuration() const;
|
bool hasDuration() const;
|
||||||
|
|
||||||
|
void hideAnimated();
|
||||||
void finish();
|
void finish();
|
||||||
|
|
||||||
void activeAnimate(bool active);
|
void activeAnimate(bool active);
|
||||||
|
|
Loading…
Add table
Reference in a new issue