From 243245d68056b34205ff312087f72e5241bd6539 Mon Sep 17 00:00:00 2001 From: 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 Date: Wed, 28 Jun 2023 00:00:03 +0300 Subject: [PATCH] feat: send GIF|voice confirmation by settings toggles --- Telegram/CMakeLists.txt | 2 + Telegram/SourceFiles/ayu/ayu_settings.cpp | 5 + Telegram/SourceFiles/ayu/ayu_settings.h | 4 + .../ayu/boxes/voice_confirmation_box.cpp | 103 ++++++++++++++++++ .../ayu/boxes/voice_confirmation_box.h | 21 ++++ .../SourceFiles/ayu/settings/settings_ayu.cpp | 28 +++++ .../chat_helpers/gifs_list_widget.cpp | 28 ++++- .../history_view_voice_record_bar.cpp | 47 +++++++- Telegram/SourceFiles/tray.cpp | 42 +++---- 9 files changed, 248 insertions(+), 32 deletions(-) create mode 100644 Telegram/SourceFiles/ayu/boxes/voice_confirmation_box.cpp create mode 100644 Telegram/SourceFiles/ayu/boxes/voice_confirmation_box.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 450f7aeb4..081475f79 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -102,6 +102,8 @@ PRIVATE ayu/ayu_settings.h ayu/ayu_lang.cpp ayu/ayu_lang.h + ayu/boxes/voice_confirmation_box.cpp + ayu/boxes/voice_confirmation_box.h ayu/boxes/confirmation_box.cpp ayu/boxes/confirmation_box.h ayu/boxes/edit_deleted_mark.cpp diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index 0c81ad23b..dc859f6da 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -153,6 +153,10 @@ namespace AyuSettings { GIFConfirmation = val; } + void AyuGramSettings::set_voiceConfirmation(bool val) { + voiceConfirmation = val; + } + bool AyuGramSettings::getGhostModeValue() { return (!sendReadPackets && !sendOnlinePackets @@ -161,6 +165,7 @@ namespace AyuSettings { } + rpl::producer get_deletedMarkReactive() { return deletedMarkReactive.value(); } diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index 62a7a9507..74c9a5de9 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -39,6 +39,7 @@ namespace AyuSettings { // ~ Beta functionality stickerConfirmation = false; GIFConfirmation = false; + voiceConfirmation = false; /* * showPeerId = 0 means no ID shown @@ -86,6 +87,8 @@ namespace AyuSettings { QS_FIELD(bool, GIFConfirmation) + QS_FIELD(bool, voiceConfirmation) + public: void set_sendReadPackets(bool val); void set_sendOnlinePackets(bool val); @@ -110,6 +113,7 @@ namespace AyuSettings { void set_stickerConfirmation(bool val); void set_GIFConfirmation(bool val); + void set_voiceConfirmation(bool val); bool getGhostModeValue(); }; diff --git a/Telegram/SourceFiles/ayu/boxes/voice_confirmation_box.cpp b/Telegram/SourceFiles/ayu/boxes/voice_confirmation_box.cpp new file mode 100644 index 000000000..47acc98ce --- /dev/null +++ b/Telegram/SourceFiles/ayu/boxes/voice_confirmation_box.cpp @@ -0,0 +1,103 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "ui/boxes/confirm_box.h" + +#include "lang/lang_keys.h" +#include "ui/widgets/buttons.h" +#include "styles/style_layers.h" +#include "voice_confirmation_box.h" + +namespace AyuUi { + + void VoiceConfirmBox(not_null box, Ui::ConfirmBoxArgs &&args) { + const auto weak = Ui::MakeWeak(box); + const auto lifetime = box->lifetime().make_state(); + + v::match(args.text, [](v::null_t) { + }, [&](auto &&) { + const auto label = box->addRow( + object_ptr( + box.get(), + v::text::take_marked(std::move(args.text)), + args.labelStyle ? *args.labelStyle : st::boxLabel), + st::boxPadding); + if (args.labelFilter) { + label->setClickHandlerFilter(std::move(args.labelFilter)); + } + }); + + const auto prepareCallback = [&](Ui::ConfirmBoxArgs::Callback &callback) { + return [=, confirmed = std::move(callback)]() { + if (const auto callbackPtr = std::get_if<1>(&confirmed)) { + if (auto callback = (*callbackPtr)) { + callback(); + } + } else if (const auto callbackPtr = std::get_if<2>(&confirmed)) { + if (auto callback = (*callbackPtr)) { + callback(crl::guard(weak, [=] { weak->closeBox(); })); + } + } else if (weak) { + weak->closeBox(); + } + }; + }; + + const auto &defaultButtonStyle = box->getDelegate()->style().button; + + const auto confirmButton = box->addButton( + v::text::take_plain(std::move(args.confirmText), tr::lng_box_ok()), + [=, c = prepareCallback(args.confirmed)]() { + lifetime->destroy(); + c(); + + weak->closeBox(); + }, + args.confirmStyle ? *args.confirmStyle : defaultButtonStyle); + box->events( + ) | rpl::start_with_next([=](not_null e) { + if ((e->type() != QEvent::KeyPress) || !confirmButton) { + return; + } + const auto k = static_cast(e.get()); + if (k->key() == Qt::Key_Enter || k->key() == Qt::Key_Return) { + confirmButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton); + } + }, box->lifetime()); + + if (!args.inform) { + const auto cancelButton = box->addButton( + v::text::take_plain(std::move(args.cancelText), tr::lng_cancel()), + crl::guard(weak, [=, c = prepareCallback(args.cancelled)]() { + lifetime->destroy(); + c(); + }), + args.cancelStyle ? *args.cancelStyle : defaultButtonStyle); + + box->boxClosing( + ) | rpl::start_with_next(crl::guard(cancelButton, [=] { + cancelButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton); + }), *lifetime); + } + + if (args.strictCancel) { + lifetime->destroy(); + } + } + + object_ptr MakeConfirmBox(Ui::ConfirmBoxArgs &&args) { + return Box(VoiceConfirmBox, std::move(args)); + } + + object_ptr MakeInformBox(v::text::data text) { + return MakeConfirmBox({ + .text = std::move(text), + .inform = true, + }); + } + +} // namespace AyuUi diff --git a/Telegram/SourceFiles/ayu/boxes/voice_confirmation_box.h b/Telegram/SourceFiles/ayu/boxes/voice_confirmation_box.h new file mode 100644 index 000000000..b3aa6c721 --- /dev/null +++ b/Telegram/SourceFiles/ayu/boxes/voice_confirmation_box.h @@ -0,0 +1,21 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "ui/layers/generic_box.h" +#include "ui/text/text_variant.h" +#include "ui/boxes/confirm_box.h" + +namespace AyuUi { + void VoiceConfirmBox(not_null box, Ui::ConfirmBoxArgs &&args); + + [[nodiscard]] object_ptr MakeConfirmBox( + Ui::ConfirmBoxArgs &&args); + [[nodiscard]] object_ptr MakeInformBox(v::text::data text); + +} // namespace Ui diff --git a/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp index 7607a575e..ebceb2b66 100644 --- a/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp @@ -336,6 +336,34 @@ namespace Settings { settings->set_stickerConfirmation(enabled); AyuSettings::save(); }, container->lifetime()); + + AddButton( + container, + rpl::single(QString("Send GIF confirmation")), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->GIFConfirmation) + )->toggledValue( + ) | rpl::filter([=] (bool enabled) { + return (enabled != settings->GIFConfirmation); + }) | rpl::start_with_next([=] (bool enabled) { + settings->set_GIFConfirmation(enabled); + AyuSettings::save(); + }, container->lifetime()); + + AddButton( + container, + rpl::single(QString("Send voice confirmation")), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->voiceConfirmation) + )->toggledValue( + ) | rpl::filter([=] (bool enabled) { + return (enabled != settings->voiceConfirmation); + }) | rpl::start_with_next([=] (bool enabled) { + settings->set_voiceConfirmation(enabled); + AyuSettings::save(); + }, container->lifetime()); } void Ayu::SetupAyuGramSettings(not_null container, not_null controller) { diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index d8ba04cf5..9ad5aa516 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -43,6 +43,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_menu_icons.h" #include +#include +#include namespace ChatHelpers { namespace { @@ -470,9 +472,11 @@ void GifsListWidget::selectInlineResult( if (forceSend || (media && media->image(PhotoSize::Thumbnail)) || (media && media->image(PhotoSize::Large))) { + // why photo type in GIF sender? _photoChosen.fire({ .photo = photo, .options = options }); + } else if (!photo->loading(PhotoSize::Thumbnail)) { photo->load(PhotoSize::Thumbnail, Data::FileOrigin()); } @@ -480,11 +484,25 @@ void GifsListWidget::selectInlineResult( const auto media = document->activeMediaView(); const auto preview = Data::VideoPreviewState(media.get()); if (forceSend || (media && preview.loaded())) { - _fileChosen.fire({ - .document = document, - .options = options, - .messageSendingFrom = messageSendingFrom(), - }); + auto settings = &AyuSettings::getInstance(); + auto sendGIFCallback = [=, this] { + _fileChosen.fire({ + .document = document, + .options = options, + .messageSendingFrom = messageSendingFrom(), + }); + }; + + if (settings->GIFConfirmation) { + Ui::show(Ui::MakeConfirmBox({ + .text = rpl::single(QString("Do you want to send this GIF?")), + .confirmed = sendGIFCallback, + .confirmText = rpl::single(QString("Send")), + })); + } + else { + sendGIFCallback(); + } } else if (!preview.usingThumbnail()) { if (preview.loading()) { document->cancel(); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index b80310d3b..9ea643408 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -5,6 +5,8 @@ the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ +#include +#include #include "history/view/controls/history_view_voice_record_bar.h" #include "api/api_send_progress.h" @@ -35,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/ripple_animation.h" #include "ui/text/format_values.h" #include "ui/painter.h" +#include "boxes/abstract_box.h" namespace HistoryView::Controls { @@ -1426,8 +1429,24 @@ void VoiceRecordBar::stopRecording(StopType type) { window()->raise(); window()->activateWindow(); const auto duration = Duration(data.samples); + auto settings = &AyuSettings::getInstance(); + if (type == StopType::Send) { - _sendVoiceRequests.fire({ data.bytes, data.waveform, duration }); + auto sendVoiceCallback = [=, this] { + _sendVoiceRequests.fire({ data.bytes, data.waveform, duration }); + }; + + if (settings->voiceConfirmation) { + Ui::show(AyuUi::MakeConfirmBox({ + .text = rpl::single(QString("Do you want to send voice message?")), + .confirmed = sendVoiceCallback, + .confirmText = rpl::single(QString("Send")) + })); + } + else { + sendVoiceCallback(); + } + } else if (type == StopType::Listen) { _listen = std::make_unique( this, @@ -1500,11 +1519,27 @@ void VoiceRecordBar::drawMessage(Painter &p, float64 recordActive) { void VoiceRecordBar::requestToSendWithOptions(Api::SendOptions options) { if (isListenState()) { const auto data = _listen->data(); - _sendVoiceRequests.fire({ - data->bytes, - data->waveform, - Duration(data->samples), - options }); + auto settings = &AyuSettings::getInstance(); + + auto sendVoiceCallback = [=, this] { + _sendVoiceRequests.fire({ + data->bytes, + data->waveform, + Duration(data->samples), + options + }); + }; + + if (settings->voiceConfirmation) { + Ui::show(AyuUi::MakeConfirmBox({ + .text = rpl::single(QString("Do you want to send voice message?")), + .confirmed = sendVoiceCallback, + .confirmText = rpl::single(QString("Send")) + })); + } + else { + sendVoiceCallback(); + } } } diff --git a/Telegram/SourceFiles/tray.cpp b/Telegram/SourceFiles/tray.cpp index 5f758071e..9e9890af5 100644 --- a/Telegram/SourceFiles/tray.cpp +++ b/Telegram/SourceFiles/tray.cpp @@ -90,28 +90,28 @@ void Tray::rebuildMenu() { [=] { toggleSoundNotifications(); }); } - auto turnGhostModeText = _textUpdates.events( - ) | rpl::map([=] { - auto settings = AyuSettings::AyuGramSettings(); - bool ghostModeEnabled = settings.getGhostModeValue(); +// auto turnGhostModeText = _textUpdates.events( +// ) | rpl::map([=] { +// auto settings = AyuSettings::AyuGramSettings(); +// bool ghostModeEnabled = settings.getGhostModeValue(); +// +// return ghostModeEnabled +// ? tr::ayu_DisableGhostMode(tr::now) +// : tr::ayu_EnableGhostMode(tr::now); +// }); - return ghostModeEnabled - ? tr::ayu_DisableGhostMode(tr::now) - : tr::ayu_EnableGhostMode(tr::now); - }); - - _tray.addAction(rpl::single(QString("Toggle ghost mode")), [=] { - auto settings = &AyuSettings::getInstance(); - bool ghostMode = (bool) AyuSettings::get_ghostModeEnabled(); - - settings->set_sendReadPackets(!ghostMode); - settings->set_sendOnlinePackets(!ghostMode); - settings->set_sendUploadProgress(!ghostMode); - - settings->set_sendOfflinePacketAfterOnline(ghostMode); - - AyuSettings::save(); - }); +// _tray.addAction(rpl::single(QString("Toggle ghost mode")), [=] { +// auto settings = &AyuSettings::getInstance(); +// bool ghostMode = (bool) AyuSettings::get_ghostModeEnabled(); +// +// settings->set_sendReadPackets(!ghostMode); +// settings->set_sendOnlinePackets(!ghostMode); +// settings->set_sendUploadProgress(!ghostMode); +// +// settings->set_sendOfflinePacketAfterOnline(ghostMode); +// +// AyuSettings::save(); +// }); auto quitText = _textUpdates.events( ) | rpl::map([=] {