Skip to content

Commit

Permalink
Don't show recent apps in popular apps.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Aug 1, 2024
1 parent 7f3dc27 commit 11c91c1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
62 changes: 47 additions & 15 deletions Telegram/SourceFiles/dialogs/ui/dialogs_suggestions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,15 @@ class RecentAppsController final

void load();

[[nodiscard]] rpl::producer<> refreshed() const;
[[nodiscard]] bool shown(not_null<PeerData*> peer) const;

private:
void appendRow(not_null<UserData*> bot);
void fill();

std::vector<not_null<UserData*>> _bots;
rpl::event_stream<> _refreshed;
rpl::lifetime _lifetime;

};
Expand All @@ -442,7 +446,9 @@ class PopularAppsController final
: public Suggestions::ObjectListController {
public:
explicit PopularAppsController(
not_null<Window::SessionController*> window);
not_null<Window::SessionController*> window,
Fn<bool(not_null<PeerData*>)> filterOut,
rpl::producer<> filterOutRefreshes);

void prepare() override;

Expand All @@ -452,6 +458,8 @@ class PopularAppsController final
void fill();
void appendRow(not_null<UserData*> bot);

Fn<bool(not_null<PeerData*>)> _filterOut;
rpl::producer<> _filterOutRefreshes;
History *_activeHistory = nullptr;
bool _requested = false;
rpl::lifetime _lifetime;
Expand Down Expand Up @@ -1068,6 +1076,14 @@ void RecentAppsController::load() {
session().topBotApps().reload();
}

rpl::producer<> RecentAppsController::refreshed() const {
return _refreshed.events();
}

bool RecentAppsController::shown(not_null<PeerData*> peer) const {
return delegate()->peerListFindRow(peer->id.value) != nullptr;
}

void RecentAppsController::fill() {
const auto count = countCurrent();
const auto limit = expandedCurrent()
Expand All @@ -1087,6 +1103,8 @@ void RecentAppsController::fill() {
}
}
delegate()->peerListRefreshRows();

_refreshed.fire({});
}

void RecentAppsController::appendRow(not_null<UserData*> bot) {
Expand All @@ -1099,13 +1117,21 @@ void RecentAppsController::appendRow(not_null<UserData*> bot) {
}

PopularAppsController::PopularAppsController(
not_null<Window::SessionController*> window)
: ObjectListController(window) {
not_null<Window::SessionController*> window,
Fn<bool(not_null<PeerData*>)> filterOut,
rpl::producer<> filterOutRefreshes)
: ObjectListController(window)
, _filterOut(std::move(filterOut))
, _filterOutRefreshes(std::move(filterOutRefreshes)) {
}

void PopularAppsController::prepare() {
setupPlainDivider(tr::lng_bot_apps_popular());
fill();
rpl::single() | rpl::then(
std::move(_filterOutRefreshes)
) | rpl::start_with_next([=] {
fill();
}, _lifetime);
}

void PopularAppsController::load() {
Expand All @@ -1122,24 +1148,24 @@ void PopularAppsController::load() {
}

void PopularAppsController::fill() {
const auto attachWebView = &session().attachWebView();
const auto &list = attachWebView->popularAppBots();
if (list.empty()) {
return;
while (delegate()->peerListFullRowsCount()) {
delegate()->peerListRemoveRow(delegate()->peerListRowAt(0));
}
for (const auto &bot : list) {
appendRow(bot);
for (const auto &bot : session().attachWebView().popularAppBots()) {
if (!_filterOut || !_filterOut(bot)) {
appendRow(bot);
}
}
delegate()->peerListRefreshRows();
setCount(delegate()->peerListFullRowsCount());
}

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 (const auto count = bot->botInfo->activeUsers) {
// row->setCustomStatus(
// tr::lng_bot_status_users(tr::now, lt_count_decimal, count));
//}
delegate()->peerListAppendRow(std::move(row));
}

Expand Down Expand Up @@ -1896,6 +1922,10 @@ auto Suggestions::setupRecommendations() -> std::unique_ptr<ObjectList> {
auto Suggestions::setupRecentApps() -> std::unique_ptr<ObjectList> {
const auto controller = lifetime().make_state<RecentAppsController>(
_controller);
_recentAppsShows = [=](not_null<PeerData*> peer) {
return controller->shown(peer);
};
_recentAppsRefreshed = controller->refreshed();

auto result = setupObjectList(
_appsScroll.get(),
Expand Down Expand Up @@ -1952,7 +1982,9 @@ auto Suggestions::setupRecentApps() -> std::unique_ptr<ObjectList> {

auto Suggestions::setupPopularApps() -> std::unique_ptr<ObjectList> {
const auto controller = lifetime().make_state<PopularAppsController>(
_controller);
_controller,
_recentAppsShows,
rpl::duplicate(_recentAppsRefreshed));

const auto addToScroll = [=] {
const auto wrap = _recentApps->wrap;
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/dialogs/ui/dialogs_suggestions.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class Suggestions final : public Ui::RpWidget {
const std::unique_ptr<Ui::ElasticScroll> _appsScroll;
const not_null<Ui::VerticalLayout*> _appsContent;

rpl::producer<> _recentAppsRefreshed;
Fn<bool(not_null<PeerData*>)> _recentAppsShows;
const std::unique_ptr<ObjectList> _recentApps;
const std::unique_ptr<ObjectList> _popularApps;

Expand Down

0 comments on commit 11c91c1

Please sign in to comment.