From 6272b79f70c6b5e660f06a65c1d52b39167f83d9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 24 Jun 2025 13:39:24 +0400 Subject: [PATCH] Allow suggesting with TON. --- Telegram/Resources/langs/lang.strings | 8 +- Telegram/SourceFiles/api/api_common.cpp | 3 +- Telegram/SourceFiles/api/api_updates.cpp | 5 - .../SourceFiles/data/components/credits.cpp | 14 +- .../SourceFiles/data/components/credits.h | 1 + .../view/history_view_suggest_options.cpp | 290 +++++++++++++++--- .../channel_statistics/earn/earn_icons.cpp | 12 +- .../info/channel_statistics/earn/earn_icons.h | 1 + Telegram/SourceFiles/ui/chat/chat.style | 18 ++ .../SourceFiles/ui/controls/ton_common.cpp | 240 +++++++++++++++ Telegram/SourceFiles/ui/controls/ton_common.h | 46 +++ Telegram/cmake/td_ui.cmake | 2 + 12 files changed, 584 insertions(+), 56 deletions(-) create mode 100644 Telegram/SourceFiles/ui/controls/ton_common.cpp create mode 100644 Telegram/SourceFiles/ui/controls/ton_common.h diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index da2e1a761f..cc0603dd6e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4422,8 +4422,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_suggest_bar_dated" = "Publish on {date}"; "lng_suggest_options_title" = "Suggest a Message"; "lng_suggest_options_change" = "Suggest Changes"; -"lng_suggest_options_price" = "Enter Price in Stars"; -"lng_suggest_options_price_about" = "Choose how many Stars to pay to publish this message."; +"lng_suggest_options_stars_offer" = "Offer Stars"; +"lng_suggest_options_stars_price" = "Enter Price in Stars"; +"lng_suggest_options_stars_price_about" = "Choose how many Stars to pay to publish this message."; +"lng_suggest_options_ton_offer" = "Offer TON"; +"lng_suggest_options_ton_price" = "Enter Price in TON"; +"lng_suggest_options_ton_price_about" = "Choose how many TON to pay to publish this message."; "lng_suggest_options_date" = "Time"; "lng_suggest_options_date_any" = "Anytime"; "lng_suggest_options_date_about" = "Select the date and time you want the message to be published."; diff --git a/Telegram/SourceFiles/api/api_common.cpp b/Telegram/SourceFiles/api/api_common.cpp index 65ec607c04..55017ade84 100644 --- a/Telegram/SourceFiles/api/api_common.cpp +++ b/Telegram/SourceFiles/api/api_common.cpp @@ -18,7 +18,8 @@ MTPSuggestedPost SuggestToMTP(SuggestPostOptions suggest) { using Flag = MTPDsuggestedPost::Flag; return suggest.exists ? MTP_suggestedPost( - MTP_flags(suggest.date ? Flag::f_schedule_date : Flag()), + MTP_flags((suggest.date ? Flag::f_schedule_date : Flag()) + | (suggest.price().empty() ? Flag() : Flag::f_price)), StarsAmountToTL(suggest.price()), MTP_int(suggest.date)) : MTPSuggestedPost(); diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 7b0c538850..d2a19a7420 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -2756,11 +2756,6 @@ void Updates::feedUpdate(const MTPUpdate &update) { _session->credits().apply(data); } break; - case mtpc_updateStarsTonBalance: { - const auto &data = update.c_updateStarsBalance(); - _session->credits().apply(data); - } break; - case mtpc_updatePaidReactionPrivacy: { const auto &data = update.c_updatePaidReactionPrivacy(); _session->api().globalPrivacy().updatePaidReactionShownPeer( diff --git a/Telegram/SourceFiles/data/components/credits.cpp b/Telegram/SourceFiles/data/components/credits.cpp index 5f93ba303c..5323305331 100644 --- a/Telegram/SourceFiles/data/components/credits.cpp +++ b/Telegram/SourceFiles/data/components/credits.cpp @@ -132,12 +132,16 @@ void Credits::invalidate() { } void Credits::apply(CreditsAmount balance) { - _balance = balance; - updateNonLockedValue(); + if (balance.ton()) { + _balanceTon = balance; + } else { + _balance = balance; + updateNonLockedValue(); - const auto was = std::exchange(_lastLoaded, crl::now()); - if (!was) { - _loadedChanges.fire({}); + const auto was = std::exchange(_lastLoaded, crl::now()); + if (!was) { + _loadedChanges.fire({}); + } } } diff --git a/Telegram/SourceFiles/data/components/credits.h b/Telegram/SourceFiles/data/components/credits.h index 000df652e3..a26715f473 100644 --- a/Telegram/SourceFiles/data/components/credits.h +++ b/Telegram/SourceFiles/data/components/credits.h @@ -56,6 +56,7 @@ private: base::flat_map _cachedPeerCurrencyBalances; CreditsAmount _balance; + CreditsAmount _balanceTon; CreditsAmount _locked; rpl::variable _nonLockedBalance; rpl::event_stream<> _loadedChanges; diff --git a/Telegram/SourceFiles/history/view/history_view_suggest_options.cpp b/Telegram/SourceFiles/history/view/history_view_suggest_options.cpp index b5c8f84097..be36d9e24d 100644 --- a/Telegram/SourceFiles/history/view/history_view_suggest_options.cpp +++ b/Telegram/SourceFiles/history/view/history_view_suggest_options.cpp @@ -8,9 +8,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_suggest_options.h" #include "base/unixtime.h" +#include "core/ui_integration.h" +#include "data/stickers/data_custom_emoji.h" #include "data/data_channel.h" #include "data/data_media_types.h" +#include "data/data_session.h" #include "history/history_item.h" +#include "info/channel_statistics/earn/earn_icons.h" #include "lang/lang_keys.h" #include "main/main_app_config.h" #include "main/main_session.h" @@ -18,12 +22,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/layers/generic_box.h" #include "ui/text/text_utilities.h" #include "ui/boxes/choose_date_time.h" +#include "ui/controls/ton_common.h" #include "ui/widgets/fields/number_input.h" +#include "ui/widgets/fields/input_field.h" #include "ui/widgets/buttons.h" +#include "ui/wrap/slide_wrap.h" +#include "ui/painter.h" #include "ui/vertical_list.h" #include "window/window_session_controller.h" +#include "styles/style_channel_earn.h" #include "styles/style_chat.h" #include "styles/style_chat_helpers.h" +#include "styles/style_credits.h" +#include "styles/style_layers.h" #include "styles/style_settings.h" namespace HistoryView { @@ -37,6 +48,7 @@ void ChooseSuggestTimeBox( const auto value = args.value ? std::clamp(args.value, now + min, now + max) : (now + 86400); + const auto done = args.done; Ui::ChooseDateTimeBox(box, { .title = ((args.mode == SuggestMode::New) ? tr::lng_suggest_options_date() @@ -44,21 +56,34 @@ void ChooseSuggestTimeBox( .submit = ((args.mode == SuggestMode::New) ? tr::lng_settings_save() : tr::lng_suggest_options_update()), - .done = std::move(args.done), + .done = done, .min = [=] { return now + min; }, .time = value, .max = [=] { return now + max; }, }); + + box->addLeftButton(tr::lng_suggest_options_date_any(), [=] { + done(TimeId()); + }); } void ChooseSuggestPriceBox( not_null box, SuggestPriceBoxArgs &&args) { + struct Button { + QRect geometry; + Ui::Text::String text; + bool active = false; + }; struct State { + std::vector