fix: crashes in confirmations

This commit is contained in:
ZavaruKitsu 2023-11-01 00:17:47 +03:00
parent fe15857704
commit d0b0b02b62
3 changed files with 46 additions and 66 deletions

View file

@ -491,17 +491,17 @@ void GifsListWidget::selectInlineResult(
const auto preview = Data::VideoPreviewState(media.get()); const auto preview = Data::VideoPreviewState(media.get());
if (forceSend || (media && preview.loaded())) { if (forceSend || (media && preview.loaded())) {
auto settings = &AyuSettings::getInstance(); auto settings = &AyuSettings::getInstance();
auto from = messageSendingFrom();
auto sendGIFCallback = crl::guard(this, [=]
{
_fileChosen.fire({
.document = document,
.options = options,
.messageSendingFrom = from,
});
});
if (settings->gifConfirmation) { if (settings->gifConfirmation) {
auto sendGIFCallback = [=, this]
{
_fileChosen.fire({
.document = document,
.options = options,
.messageSendingFrom = messageSendingFrom(),
});
};
Ui::show(Ui::MakeConfirmBox({ Ui::show(Ui::MakeConfirmBox({
.text = tr::ayu_ConfirmationGIF(), .text = tr::ayu_ConfirmationGIF(),
.confirmed = sendGIFCallback, .confirmed = sendGIFCallback,
@ -509,11 +509,7 @@ void GifsListWidget::selectInlineResult(
})); }));
} }
else { else {
_fileChosen.fire({ sendGIFCallback();
.document = document,
.options = options,
.messageSendingFrom = messageSendingFrom(),
});
} }
} else if (!preview.usingThumbnail()) { } else if (!preview.usingThumbnail()) {
if (preview.loading()) { if (preview.loading()) {

View file

@ -1752,37 +1752,27 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
showStickerSetBox(document); showStickerSetBox(document);
} else { } else {
auto settings = &AyuSettings::getInstance(); auto settings = &AyuSettings::getInstance();
if (settings->stickerConfirmation) auto from = messageSentAnimationInfo(
{ sticker->section,
// it is necessary to store it here, because section & index can be changed by cursor position (guess) sticker->index,
int currentSection = sticker->section; document);
int currentIndex = sticker->index; auto sendStickerCallback = crl::guard(this, [=, this]
auto sendStickerCallback = [=, this]
{
_chosen.fire({
.document = document,
.messageSendingFrom = messageSentAnimationInfo(
currentSection,
currentIndex,
document),
});
};
Ui::show(Ui::MakeConfirmBox({
.text = tr::ayu_ConfirmationSticker(),
.confirmed = sendStickerCallback,
.confirmText = tr::lng_send_button()
}));
}
else
{ {
_chosen.fire({ _chosen.fire({
.document = document, .document = document,
.messageSendingFrom = messageSentAnimationInfo( .messageSendingFrom = from,
sticker->section, });
sticker->index, });
document),
}); if (settings->stickerConfirmation) {
Ui::show(Ui::MakeConfirmBox({
.text = tr::ayu_ConfirmationSticker(),
.confirmed = sendStickerCallback,
.confirmText = tr::lng_send_button()
}));
}
else {
sendStickerCallback();
} }
} }
} else if (auto set = std::get_if<OverSet>(&pressed)) { } else if (auto set = std::get_if<OverSet>(&pressed)) {

View file

@ -1498,14 +1498,14 @@ void VoiceRecordBar::stopRecording(StopType type) {
window()->activateWindow(); window()->activateWindow();
const auto duration = Duration(data.samples); const auto duration = Duration(data.samples);
auto settings = &AyuSettings::getInstance();
if (type == StopType::Send) { if (type == StopType::Send) {
if (settings->voiceConfirmation) { auto settings = &AyuSettings::getInstance();
auto sendVoiceCallback = [=, this] auto sendVoiceCallback = crl::guard(this, [=, this]
{ {
_sendVoiceRequests.fire({data.bytes, data.waveform, duration}); _sendVoiceRequests.fire({data.bytes, data.waveform, duration});
}; });
if (settings->voiceConfirmation) {
Ui::show(AyuUi::MakeConfirmBox({ Ui::show(AyuUi::MakeConfirmBox({
.text = tr::ayu_ConfirmationVoice(), .text = tr::ayu_ConfirmationVoice(),
.confirmed = sendVoiceCallback, .confirmed = sendVoiceCallback,
@ -1513,7 +1513,7 @@ void VoiceRecordBar::stopRecording(StopType type) {
})); }));
} }
else { else {
_sendVoiceRequests.fire({data.bytes, data.waveform, duration}); sendVoiceCallback();
} }
} else if (type == StopType::Listen) { } else if (type == StopType::Listen) {
_listen = std::make_unique<ListenWrap>( _listen = std::make_unique<ListenWrap>(
@ -1585,18 +1585,17 @@ void VoiceRecordBar::requestToSendWithOptions(Api::SendOptions options) {
if (isListenState()) { if (isListenState()) {
const auto data = _listen->data(); const auto data = _listen->data();
auto settings = &AyuSettings::getInstance(); auto settings = &AyuSettings::getInstance();
auto sendVoiceCallback = crl::guard(this, [=, this]
{
_sendVoiceRequests.fire({
data->bytes,
data->waveform,
Duration(data->samples),
options
});
});
if (settings->voiceConfirmation) { if (settings->voiceConfirmation) {
auto sendVoiceCallback = [=, this]
{
_sendVoiceRequests.fire({
data->bytes,
data->waveform,
Duration(data->samples),
options
});
};
Ui::show(AyuUi::MakeConfirmBox({ Ui::show(AyuUi::MakeConfirmBox({
.text = tr::ayu_ConfirmationVoice(), .text = tr::ayu_ConfirmationVoice(),
.confirmed = sendVoiceCallback, .confirmed = sendVoiceCallback,
@ -1604,12 +1603,7 @@ void VoiceRecordBar::requestToSendWithOptions(Api::SendOptions options) {
})); }));
} }
else { else {
_sendVoiceRequests.fire({ sendVoiceCallback();
data->bytes,
data->waveform,
Duration(data->samples),
options
});
} }
} }
} }