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

View file

@ -1752,37 +1752,27 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
showStickerSetBox(document);
} else {
auto settings = &AyuSettings::getInstance();
if (settings->stickerConfirmation)
{
// it is necessary to store it here, because section & index can be changed by cursor position (guess)
int currentSection = sticker->section;
int currentIndex = sticker->index;
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
auto from = messageSentAnimationInfo(
sticker->section,
sticker->index,
document);
auto sendStickerCallback = crl::guard(this, [=, this]
{
_chosen.fire({
.document = document,
.messageSendingFrom = messageSentAnimationInfo(
sticker->section,
sticker->index,
document),
});
.document = document,
.messageSendingFrom = from,
});
});
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)) {

View file

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