Fix sending single-time voice messages.

This commit is contained in:
John Preston 2024-01-16 10:53:26 +04:00
parent 104cf504ab
commit b31bb6dd33
2 changed files with 12 additions and 5 deletions

View file

@ -1638,10 +1638,12 @@ void VoiceRecordBar::stop(bool send) {
if (isHidden() && !send) {
return;
}
const auto ttlBeforeHide = peekTTLState();
auto disappearanceCallback = [=] {
hide();
stopRecording(send ? StopType::Send : StopType::Cancel);
const auto type = send ? StopType::Send : StopType::Cancel;
stopRecording(type, ttlBeforeHide);
};
_lockShowing = false;
visibilityAnimate(false, std::move(disappearanceCallback));
@ -1671,7 +1673,7 @@ void VoiceRecordBar::hideFast() {
[[maybe_unused]] const auto s = takeTTLState();
}
void VoiceRecordBar::stopRecording(StopType type) {
void VoiceRecordBar::stopRecording(StopType type, bool ttlBeforeHide) {
using namespace ::Media::Capture;
if (type == StopType::Cancel) {
instance()->stop(crl::guard(this, [=](Result &&data) {
@ -1691,9 +1693,9 @@ void VoiceRecordBar::stopRecording(StopType type) {
const auto duration = Duration(data.samples);
if (type == StopType::Send) {
const auto options = Api::SendOptions{
.ttlSeconds = takeTTLState()
.ttlSeconds = (ttlBeforeHide
? std::numeric_limits<int>::max()
: 0
: 0),
};
_sendVoiceRequests.fire({
data.bytes,
@ -1901,6 +1903,10 @@ void VoiceRecordBar::computeAndSetLockProgress(QPoint globalPos) {
_lock->requestPaintProgress(Progress(localPos.y(), higher - lower));
}
bool VoiceRecordBar::peekTTLState() const {
return !_ttlButton->isDisabled();
}
bool VoiceRecordBar::takeTTLState() const {
const auto hasTtl = !_ttlButton->isDisabled();
_ttlButton->clearState();

View file

@ -126,7 +126,7 @@ private:
[[nodiscard]] bool recordingAnimationCallback(crl::time now);
void stop(bool send);
void stopRecording(StopType type);
void stopRecording(StopType type, bool ttlBeforeHide = false);
void visibilityAnimate(bool show, Fn<void()> &&callback);
[[nodiscard]] bool showRecordButton() const;
@ -149,6 +149,7 @@ private:
void computeAndSetLockProgress(QPoint globalPos);
[[nodiscard]] bool peekTTLState() const;
[[nodiscard]] bool takeTTLState() const;
const style::RecordBar &_st;