Show internal list of apps as Stars Examples.

This commit is contained in:
John Preston 2024-09-05 13:14:07 +04:00
parent 216865a20d
commit c18e59218e
6 changed files with 68 additions and 9 deletions

View File

@ -2410,7 +2410,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_credits_box_history_entry_gift_out_about" = "With Stars, **{user}** will be able to unlock content and services on Telegram.\n{link}";
"lng_credits_box_history_entry_gift_in_about" = "Use Stars to unlock content and services on Telegram. {link}";
"lng_credits_box_history_entry_gift_about_link" = "See Examples {emoji}";
"lng_credits_box_history_entry_gift_about_url" = "https://telegram.org/blog/telegram-stars";
"lng_credits_box_history_entry_gift_examples" = "Examples";
"lng_credits_box_history_entry_ads" = "Ads Platform";
"lng_credits_box_history_entry_premium_bot" = "Stars Top-Up";
"lng_credits_box_history_entry_via_premium_bot" = "Premium Bot";

View File

@ -98,7 +98,7 @@ void GiftCreditsBox(
) | rpl::map([](TextWithEntities text) {
return Ui::Text::Link(
std::move(text),
tr::lng_credits_box_history_entry_gift_about_url(tr::now));
u"internal:stars_examples"_q);
});
content->add(
object_ptr<Ui::CenterWrap<>>(

View File

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/update_checker.h"
#include "core/application.h"
#include "core/click_handler_types.h"
#include "dialogs/ui/dialogs_suggestions.h"
#include "boxes/background_preview_box.h"
#include "ui/boxes/confirm_box.h"
#include "ui/boxes/edit_birthday_box.h"
@ -923,6 +924,17 @@ bool ShowCollectibleUsername(
return true;
}
bool ShowStarsExamples(
Window::SessionController *controller,
const Match &match,
const QVariant &context) {
if (!controller) {
return false;
}
controller->show(Dialogs::StarsExamplesBox(controller));
return true;
}
void ExportTestChatTheme(
not_null<Window::SessionController*> controller,
not_null<const Data::CloudTheme*> theme) {
@ -1380,6 +1392,10 @@ const std::vector<LocalUrlHandler> &InternalUrlHandlers() {
u"^collectible_username/([a-zA-Z0-9\\-\\_\\.]+)@([0-9]+)$"_q,
ShowCollectibleUsername,
},
{
u"^stars_examples$"_q,
ShowStarsExamples,
},
};
return Result;
}

View File

@ -446,7 +446,7 @@ private:
class PopularAppsController final
: public Suggestions::ObjectListController {
public:
explicit PopularAppsController(
PopularAppsController(
not_null<Window::SessionController*> window,
Fn<bool(not_null<PeerData*>)> filterOut,
rpl::producer<> filterOutRefreshes);
@ -1127,7 +1127,9 @@ PopularAppsController::PopularAppsController(
}
void PopularAppsController::prepare() {
setupPlainDivider(tr::lng_bot_apps_popular());
if (_filterOut) {
setupPlainDivider(tr::lng_bot_apps_popular());
}
rpl::single() | rpl::then(
std::move(_filterOutRefreshes)
) | rpl::start_with_next([=] {
@ -1163,10 +1165,11 @@ void PopularAppsController::fill() {
void PopularAppsController::appendRow(not_null<UserData*> bot) {
auto row = std::make_unique<PeerListRow>(bot);
//if (const auto count = bot->botInfo->activeUsers) {
// row->setCustomStatus(
// tr::lng_bot_status_users(tr::now, lt_count_decimal, count));
//}
if (bot->isBot()) {
if (!bot->botInfo->activeUsers && !bot->username().isEmpty()) {
row->setCustomStatus('@' + bot->username());
}
}
delegate()->peerListAppendRow(std::move(row));
}
@ -2283,4 +2286,40 @@ RecentPeersList RecentPeersContent(not_null<Main::Session*> session) {
return RecentPeersList{ session->recentPeers().list() };
}
object_ptr<Ui::BoxContent> StarsExamplesBox(
not_null<Window::SessionController*> window) {
auto controller = std::make_unique<PopularAppsController>(
window,
nullptr,
nullptr);
const auto raw = controller.get();
auto initBox = [=](not_null<PeerListBox*> box) {
box->setTitle(tr::lng_credits_box_history_entry_gift_examples());
box->addButton(tr::lng_close(), [=] {
box->closeBox();
});
raw->load();
raw->chosen() | rpl::start_with_next([=](not_null<PeerData*> peer) {
if (const auto user = peer->asUser()) {
if (const auto info = user->botInfo.get()) {
if (info->hasMainApp) {
window->session().attachWebView().open({
.bot = user,
.context = {
.controller = window,
.maySkipConfirmation = true,
},
.source = InlineBots::WebViewSourceBotProfile(),
});
return;
}
}
}
window->showPeerInfo(peer);
}, box->lifetime());
};
return Box<PeerListBox>(std::move(controller), std::move(initBox));
}
} // namespace Dialogs

View File

@ -23,6 +23,7 @@ class Session;
} // namespace Main
namespace Ui {
class BoxContent;
class ElasticScroll;
class SettingsSlider;
class VerticalLayout;
@ -215,4 +216,7 @@ private:
[[nodiscard]] RecentPeersList RecentPeersContent(
not_null<Main::Session*> session);
[[nodiscard]] object_ptr<Ui::BoxContent> StarsExamplesBox(
not_null<Window::SessionController*> window);
} // namespace Dialogs

View File

@ -759,7 +759,7 @@ void ReceiptCreditsBox(
) | rpl::map([](TextWithEntities text) {
return Ui::Text::Link(
std::move(text),
tr::lng_credits_box_history_entry_gift_about_url(tr::now));
u"internal:stars_examples"_q);
});
box->addRow(object_ptr<Ui::CenterWrap<>>(
box,