mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Load recommendations on demand.
This commit is contained in:
parent
a88770a8ec
commit
705bd9693d
2 changed files with 49 additions and 30 deletions
|
@ -177,12 +177,16 @@ public:
|
||||||
not_null<PeerListRow*> row) override;
|
not_null<PeerListRow*> row) override;
|
||||||
Main::Session &session() const override;
|
Main::Session &session() const override;
|
||||||
|
|
||||||
|
void load();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void fill();
|
||||||
void setupDivider();
|
void setupDivider();
|
||||||
void appendRow(not_null<ChannelData*> channel);
|
void appendRow(not_null<ChannelData*> channel);
|
||||||
|
|
||||||
const not_null<Window::SessionController*> _window;
|
const not_null<Window::SessionController*> _window;
|
||||||
rpl::variable<int> _count;
|
rpl::variable<int> _count;
|
||||||
|
bool _requested = false;
|
||||||
rpl::event_stream<not_null<PeerData*>> _chosen;
|
rpl::event_stream<not_null<PeerData*>> _chosen;
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
|
@ -730,28 +734,35 @@ RecommendationsController::RecommendationsController(
|
||||||
|
|
||||||
void RecommendationsController::prepare() {
|
void RecommendationsController::prepare() {
|
||||||
setupDivider();
|
setupDivider();
|
||||||
|
|
||||||
const auto participants = &session().api().chatParticipants();
|
|
||||||
const auto fill = [=] {
|
|
||||||
const auto &list = participants->recommendations().list;
|
|
||||||
if (list.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const auto &peer : list) {
|
|
||||||
if (const auto channel = peer->asBroadcast()) {
|
|
||||||
appendRow(channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delegate()->peerListRefreshRows();
|
|
||||||
_count = delegate()->peerListFullRowsCount();
|
|
||||||
};
|
|
||||||
|
|
||||||
fill();
|
fill();
|
||||||
if (!_count.current()) {
|
}
|
||||||
participants->loadRecommendations();
|
|
||||||
participants->recommendationsLoaded(
|
void RecommendationsController::load() {
|
||||||
) | rpl::take(1) | rpl::start_with_next(fill, _lifetime);
|
if (_requested || _count.current()) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
_requested = true;
|
||||||
|
const auto participants = &session().api().chatParticipants();
|
||||||
|
participants->loadRecommendations();
|
||||||
|
participants->recommendationsLoaded(
|
||||||
|
) | rpl::take(1) | rpl::start_with_next([=] {
|
||||||
|
fill();
|
||||||
|
}, _lifetime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RecommendationsController::fill() {
|
||||||
|
const auto participants = &session().api().chatParticipants();
|
||||||
|
const auto &list = participants->recommendations().list;
|
||||||
|
if (list.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const auto &peer : list) {
|
||||||
|
if (const auto channel = peer->asBroadcast()) {
|
||||||
|
appendRow(channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delegate()->peerListRefreshRows();
|
||||||
|
_count = delegate()->peerListFullRowsCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecommendationsController::appendRow(not_null<ChannelData*> channel) {
|
void RecommendationsController::appendRow(not_null<ChannelData*> channel) {
|
||||||
|
@ -852,7 +863,7 @@ void Suggestions::setupTabs() {
|
||||||
_tabs->setSections({
|
_tabs->setSections({
|
||||||
tr::lng_recent_chats(tr::now),
|
tr::lng_recent_chats(tr::now),
|
||||||
tr::lng_recent_channels(tr::now),
|
tr::lng_recent_channels(tr::now),
|
||||||
});
|
});
|
||||||
_tabs->sectionActivated(
|
_tabs->sectionActivated(
|
||||||
) | rpl::start_with_next([=](int section) {
|
) | rpl::start_with_next([=](int section) {
|
||||||
switchTab(section ? Tab::Channels : Tab::Chats);
|
switchTab(section ? Tab::Channels : Tab::Chats);
|
||||||
|
@ -904,7 +915,7 @@ void Suggestions::setupChats() {
|
||||||
});
|
});
|
||||||
}, _topPeers->lifetime());
|
}, _topPeers->lifetime());
|
||||||
|
|
||||||
_chatsScroll->setVisible(_tab == Tab::Chats);
|
_chatsScroll->setVisible(_tab.current() == Tab::Chats);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Suggestions::setupChannels() {
|
void Suggestions::setupChannels() {
|
||||||
|
@ -923,7 +934,7 @@ void Suggestions::setupChannels() {
|
||||||
rpl::mappers::_1 + rpl::mappers::_2 == 0),
|
rpl::mappers::_1 + rpl::mappers::_2 == 0),
|
||||||
anim::type::instant);
|
anim::type::instant);
|
||||||
|
|
||||||
_channelsScroll->setVisible(_tab == Tab::Channels);
|
_channelsScroll->setVisible(_tab.current() == Tab::Channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Suggestions::selectJump(Qt::Key direction, int pageSize) {
|
void Suggestions::selectJump(Qt::Key direction, int pageSize) {
|
||||||
|
@ -1003,7 +1014,7 @@ void Suggestions::hide(anim::type animated, Fn<void()> finish) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Suggestions::switchTab(Tab tab) {
|
void Suggestions::switchTab(Tab tab) {
|
||||||
if (_tab == tab) {
|
if (_tab.current() == tab) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_tab = tab;
|
_tab = tab;
|
||||||
|
@ -1021,8 +1032,9 @@ void Suggestions::startSlideAnimation() {
|
||||||
_chatsScroll->hide();
|
_chatsScroll->hide();
|
||||||
_channelsScroll->hide();
|
_channelsScroll->hide();
|
||||||
}
|
}
|
||||||
const auto from = (_tab == Tab::Channels) ? 0. : 1.;
|
const auto channels = (_tab.current() == Tab::Channels);
|
||||||
const auto to = (_tab == Tab::Channels) ? 1. : 0.;
|
const auto from = channels ? 0. : 1.;
|
||||||
|
const auto to = channels ? 1. : 0.;
|
||||||
_slideAnimation.start([=] {
|
_slideAnimation.start([=] {
|
||||||
update();
|
update();
|
||||||
if (!_slideAnimation.animating() && !_shownAnimation.animating()) {
|
if (!_slideAnimation.animating() && !_shownAnimation.animating()) {
|
||||||
|
@ -1067,8 +1079,9 @@ void Suggestions::finishShow() {
|
||||||
_cache = QPixmap();
|
_cache = QPixmap();
|
||||||
|
|
||||||
_tabs->show();
|
_tabs->show();
|
||||||
_chatsScroll->setVisible(_tab == Tab::Chats);
|
const auto channels = (_tab.current() == Tab::Channels);
|
||||||
_channelsScroll->setVisible(_tab == Tab::Channels);
|
_chatsScroll->setVisible(!channels);
|
||||||
|
_channelsScroll->setVisible(channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
float64 Suggestions::shownOpacity() const {
|
float64 Suggestions::shownOpacity() const {
|
||||||
|
@ -1088,7 +1101,7 @@ void Suggestions::paintEvent(QPaintEvent *e) {
|
||||||
p.drawPixmap(0, (opacity - 1.) * slide, _cache);
|
p.drawPixmap(0, (opacity - 1.) * slide, _cache);
|
||||||
} else if (!_slideLeft.isNull()) {
|
} else if (!_slideLeft.isNull()) {
|
||||||
const auto slide = st::topPeers.height + st::searchedBarHeight;
|
const auto slide = st::topPeers.height + st::searchedBarHeight;
|
||||||
const auto right = (_tab == Tab::Channels);
|
const auto right = (_tab.current() == Tab::Channels);
|
||||||
const auto progress = _slideAnimation.value(right ? 1. : 0.);
|
const auto progress = _slideAnimation.value(right ? 1. : 0.);
|
||||||
const auto shift = st::topPeers.height + st::searchedBarHeight;
|
const auto shift = st::topPeers.height + st::searchedBarHeight;
|
||||||
p.setOpacity(1. - progress);
|
p.setOpacity(1. - progress);
|
||||||
|
@ -1299,6 +1312,12 @@ object_ptr<Ui::SlideWrap<>> Suggestions::setupRecommendations() {
|
||||||
|
|
||||||
_recommendationsCount = controller->count();
|
_recommendationsCount = controller->count();
|
||||||
|
|
||||||
|
_tab.value() | rpl::filter(
|
||||||
|
rpl::mappers::_1 == Tab::Channels
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
controller->load();
|
||||||
|
}, lifetime);
|
||||||
|
|
||||||
controller->chosen(
|
controller->chosen(
|
||||||
) | rpl::start_with_next([=](not_null<PeerData*> peer) {
|
) | rpl::start_with_next([=](not_null<PeerData*> peer) {
|
||||||
_persist = true;
|
_persist = true;
|
||||||
|
|
|
@ -108,6 +108,7 @@ private:
|
||||||
const not_null<Window::SessionController*> _controller;
|
const not_null<Window::SessionController*> _controller;
|
||||||
|
|
||||||
const std::unique_ptr<Ui::SettingsSlider> _tabs;
|
const std::unique_ptr<Ui::SettingsSlider> _tabs;
|
||||||
|
rpl::variable<Tab> _tab = Tab::Chats;
|
||||||
|
|
||||||
const std::unique_ptr<Ui::ElasticScroll> _chatsScroll;
|
const std::unique_ptr<Ui::ElasticScroll> _chatsScroll;
|
||||||
const not_null<Ui::VerticalLayout*> _chatsContent;
|
const not_null<Ui::VerticalLayout*> _chatsContent;
|
||||||
|
@ -142,7 +143,6 @@ private:
|
||||||
|
|
||||||
Ui::Animations::Simple _shownAnimation;
|
Ui::Animations::Simple _shownAnimation;
|
||||||
Fn<void()> _showFinished;
|
Fn<void()> _showFinished;
|
||||||
Tab _tab = Tab::Chats;
|
|
||||||
bool _hidden = false;
|
bool _hidden = false;
|
||||||
bool _persist = false;
|
bool _persist = false;
|
||||||
QPixmap _cache;
|
QPixmap _cache;
|
||||||
|
|
Loading…
Add table
Reference in a new issue