diff --git a/Telegram/SourceFiles/boxes/send_credits_box.cpp b/Telegram/SourceFiles/boxes/send_credits_box.cpp index 445bc9029d..595434d99c 100644 --- a/Telegram/SourceFiles/boxes/send_credits_box.cpp +++ b/Telegram/SourceFiles/boxes/send_credits_box.cpp @@ -11,8 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "core/ui_integration.h" // Core::MarkedTextContext. #include "data/data_credits.h" -#include "data/data_file_origin.h" -#include "data/data_photo_media.h" #include "data/data_session.h" #include "data/data_user.h" #include "data/stickers/data_custom_emoji.h" @@ -94,47 +92,9 @@ void SendCreditsBox( const auto bot = session->data().user(form->botId); if (form->photo) { - struct State { - std::shared_ptr view; - Image *image = nullptr; - rpl::lifetime downloadLifetime; - }; - const auto state = content->lifetime().make_state(); - const auto widget = box->addRow( - object_ptr>( - content, - object_ptr(content)))->entity(); - state->view = form->photo->createMediaView(); - form->photo->load(Data::PhotoSize::Thumbnail, {}); - - widget->resize(Size(photoSize)); - - rpl::single(rpl::empty_value()) | rpl::then( - session->downloaderTaskFinished() - ) | rpl::start_with_next([=] { - using Size = Data::PhotoSize; - if (const auto large = state->view->image(Size::Large)) { - state->image = large; - } else if (const auto small = state->view->image(Size::Small)) { - state->image = small; - } else if (const auto t = state->view->image(Size::Thumbnail)) { - state->image = t; - } - widget->update(); - if (state->view->loaded()) { - state->downloadLifetime.destroy(); - } - }, state->downloadLifetime); - - widget->paintRequest( - ) | rpl::start_with_next([=] { - auto p = QPainter(widget); - if (state->image) { - p.drawPixmap(0, 0, state->image->pix(widget->width(), { - .options = Images::Option::RoundCircle, - })); - } - }, widget->lifetime()); + box->addRow(object_ptr>( + content, + Settings::HistoryEntryPhoto(content, form->photo, photoSize))); } else { const auto widget = box->addRow( object_ptr>( diff --git a/Telegram/SourceFiles/settings/settings_credits.cpp b/Telegram/SourceFiles/settings/settings_credits.cpp index c028600451..e9a01aa0a3 100644 --- a/Telegram/SourceFiles/settings/settings_credits.cpp +++ b/Telegram/SourceFiles/settings/settings_credits.cpp @@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_credits.h" #include "boxes/gift_premium_box.h" #include "core/click_handler_types.h" +#include "data/data_file_origin.h" +#include "data/data_photo_media.h" #include "data/data_session.h" #include "data/data_user.h" #include "info/settings/info_settings_widget.h" // SectionCustomTopBarData. @@ -856,4 +858,51 @@ void ReceiptCreditsBox( }, button->lifetime()); } +object_ptr HistoryEntryPhoto( + not_null parent, + not_null photo, + int photoSize) { + struct State { + std::shared_ptr view; + Image *image = nullptr; + rpl::lifetime downloadLifetime; + }; + const auto state = parent->lifetime().make_state(); + auto owned = object_ptr(parent); + const auto widget = owned.data(); + state->view = photo->createMediaView(); + photo->load(Data::PhotoSize::Thumbnail, {}); + + widget->resize(Size(photoSize)); + + rpl::single(rpl::empty_value()) | rpl::then( + photo->owner().session().downloaderTaskFinished() + ) | rpl::start_with_next([=] { + using Size = Data::PhotoSize; + if (const auto large = state->view->image(Size::Large)) { + state->image = large; + } else if (const auto small = state->view->image(Size::Small)) { + state->image = small; + } else if (const auto t = state->view->image(Size::Thumbnail)) { + state->image = t; + } + widget->update(); + if (state->view->loaded()) { + state->downloadLifetime.destroy(); + } + }, state->downloadLifetime); + + widget->paintRequest( + ) | rpl::start_with_next([=] { + auto p = QPainter(widget); + if (state->image) { + p.drawPixmap(0, 0, state->image->pix(widget->width(), { + .options = Images::Option::RoundCircle, + })); + } + }, widget->lifetime()); + + return owned; +} + } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_credits.h b/Telegram/SourceFiles/settings/settings_credits.h index 9f0d97ee04..32eba05db7 100644 --- a/Telegram/SourceFiles/settings/settings_credits.h +++ b/Telegram/SourceFiles/settings/settings_credits.h @@ -9,6 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_type.h" +template +class object_ptr; + class PeerData; namespace Data { @@ -39,5 +42,10 @@ void ReceiptCreditsBox( PeerData *premiumBot, const Data::CreditsHistoryEntry &e); +[[nodiscard]] object_ptr HistoryEntryPhoto( + not_null parent, + not_null photo, + int photoSize); + } // namespace Settings